amazon-web-services - AWS Lambda,使用 python 在 s3 存储桶之间复制
问题描述
所以我写了一个 lambda 函数,女巫是由 S3 PUT 触发的,
import datetime
import boto3
import botocore
#boto3.set_stream_logger('botocore', level='DEBUG')
def lambda_handler(event, context):
src_bucket_name=event['Records'][0]['s3']['bucket']['name']
print src_bucket_name
file = event['Records'][0]['s3']['object']['key']
split_string = file.split('/')
file_string = split_string[-1].split('_')
fecha_str = event['Records'][0]['eventTime']
fecha_real=datetime.datetime.strptime(fecha_str, '%Y-%m-%dT%H:%M:%S.%fZ')+ datetime.timedelta(hours=-6)
new_path='PATH/'+file_string[0].lower()+'/'+str(fecha_real.year)+'/'+str(fecha_real.month)+'/'+split_string[-1]
s3 = boto3.resource('s3')
s3_client = boto3.client('s3')
copy_source = {
'Bucket': src_bucket_name,
'Key': file
}
s3.meta.client.copy(copy_source, DST_BUCKET_NAME, new_path)
当我运行代码时,我得到 ClientError:调用 HeadObject 操作时发生错误(404):未找到
该文件确实存在 source_bucket中的文件
你能告诉我我做错了什么吗?
编辑:
我授予了我正在使用的角色的管理员权限,但仍然有同样的错误。
更新关闭:
我删除了角色,创建了一个新角色,将复制部分的代码更改为:
copy_source = {
'Bucket': src_bucket_name,
'Key': file
}
r = s3_client.copy_object(
Bucket=[DST_BUCKET_NAME],
CopySource=copy_source,
Key=new_path
)
它奏效了!
解决方案
推荐阅读
- scala - 在 Apache Flink 中使用 Dropwizard 直方图度量时违反加载程序约束
- android - NavController 在设备旋转后没有当前导航节点
- javascript - 如果包含文本,jQuery 对多个 DIV 进行排序
- c# - 在 AX 2012 r2 中出现类似“Testing1”的错误不是 AxdEnum_XMLDocPurpose 的有效值
- loops - for循环中的变量范围
- python-3.x - 如何在单元格值为空时结束 iter_rows 循环?
- java - 正则表达式返回进程的 pid
- typescript - 预计不会出现在打字稿中
- java - TabLayout 中的上下文菜单
- python - JupyterLab 中未显示一些 Plotly 绘图