我正在尝试使用AWS Lambda将CSV文件从S3上传到Amazon DynamoDB。我正在使用Python 2.7。该文件只有两列:名称和ID。代码如下:
import boto3
s3 = boto3.client('s3')
dynamodb = boto3.resource('dynamodb')
def csv_reader(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = event['Records'][0]['s3']['object']['key']
obj = s3.get_object(Bucket=bucket, Key=key)
rows = obj['Body'].read().split('\n')
table = dynamodb.Table('test_table')
with table.batch_writer() as batch:
for row in rows:
batch.put_item(Item={
'Name':row.split(',')[0],
'ID':row.split(',')[1]
})
我收到此错误:
An error occurred (ResourceNotFoundException) when calling the BatchWriteItem operation: Requested resource not found: ResourceNotFoundException
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 24, in csv_reader
'ID':row.split(',')[1]
File "/var/runtime/boto3/dynamodb/table.py", line 156, in __exit__
self._flush()
File "/var/runtime/boto3/dynamodb/table.py", line 137, in _flush
RequestItems={self._table_name: items_to_send})
File "/var/runtime/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
ResourceNotFoundException: An error occurred (ResourceNotFoundException) when calling the BatchWriteItem operation: Requested resource not found
如果我尝试上传任何其他文件,我仍然会遇到相同的错误。谁能建议我该怎么做?