python-2.7 - Python Lambda 用于复制大文件
问题描述
我在 python2.7 中组合了一个简单的 Lambda 函数,当文件放入存储桶时会触发。后来我发现预计要发送到我观看的存储桶的文件可能大于 5GB(找到的记录约为 490GB)。所以用不同的复制函数更新函数。但是,我现在所做的编辑会导致事件触发器出现问题。
使用其他复制功能时可能导致错误的原因是什么?有什么方法可以改善 <500GB 文件的情况吗?
具有 5GB 副本限制的原始脚本:
from __future__ import print_function
import json
import boto3
import time
import urllib
import re
print("Loading sftp file mover. Fuction= dev-sftp-move-lambda")
s3 = boto3.client('s3') #for s3 copy function
s3_resource = boto3.resource('s3') #for s3 delete function
.... checks for fileparts and other stuff...
def lambda_handler(event, context):
source_bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'])
target_bucket = 'dev-sftpinput'
copy_source = {'Bucket':source_bucket,'Key':key}
try:
s3.copy_object(Bucket=target_bucket, Key=key, CopySource=copy_source, ServerSideEncryption='AES256')
except Exception as e:
print(e)
print('Error in execution')
raise
为了允许更大的文件,我尝试简单地将复制行替换为:
s3_resource.meta.client.copy( Bucket=target_bucket, Key=key, CopySource=copy_source, ExtraArgs={'ServerSideEncryption':'AES256'})
产生的错误:
'Records': KeyError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 19, in lambda_handler
source_bucket = event['Records'][0]['s3']['bucket']['name']
KeyError: 'Records'
解决方案
推荐阅读
- excel - 改进从电子表格中获取电子邮件地址的过程
- sql - Power BI 不显示完整数据
- azure-service-fabric - 是否可以使用 Service Fabric 中 ResourceMonitorService 的“servicefabric:/_CpuCores”负载指标来平衡集群中的服务?
- database - 如何检索用户特定数据以及弹性搜索结果?
- wordpress - Wordpress Gutenberg 自动完成 - 保存属性
- sql - Oracle中如何选择计数后的最大值?
- react-native - React Native 按钮点击
- apache - 在 ubuntu 服务器 16.04 上部署 php 应用程序
- visual-studio - dotnet Cli 尝试生成代码覆盖率统计信息时出错
- sublimetext3 - 如何使用类似 VIM 的“yX”键盘组合在 Sublime 文本中拉到剪贴板