python - 尝试使用 AWS Lambda 将 CSV 文件从 S3 上传到 DynamoDB 时出错
问题描述
我正在尝试使用 AWS Lambda 将 CSV 文件从 S3 上传到 Amazon DynamoDB。我正在使用 Python 2.7。该文件只有 2 列:名称和 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
如果我尝试上传任何其他文件,我仍然会遇到同样的错误。谁能建议我应该怎么做?
解决方案
推荐阅读
- opengl - 如何运行两个opengl渲染并渲染到一个屏幕
- php - PHP/CodeIgniter 2 - 仅为特定对象调用对象的 __get() 方法
- mysql - 是否有允许我在 MySql 查询中使用星期数的功能?
- html - Kendo-Grid-Column 标题字体大小
- php - Codeigniter 文件没有在我的本地上传。因为它在实时服务器中工作正常
- excel - Excel VBA 代码在组中无法正常工作
- azure - Spark for kubernetes - Azure Blob 存储凭据问题
- oracle - 更改现有分区的范围
- laravel - Laravel 5.5.* Cookie::get 返回加密的 cookie 值
- python - 在终端关闭时运行两个单独的脚本?