我在amazon lambda上写了一个函数,并写了下面的脚本,但我得到了一个错误。只要将对象放入S3存储桶中,脚本就会运行。
s3 = boto3.client('s3')
def lambda_handler(event, context):
path = '/tmp/videos'
if not os.path.exists(path):
os.makedirs(path)
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
try:
response = s3.get_object(Bucket=bucket, Key=key)
print("CONTENT TYPE: " + response['ContentType'])
video_path = '/tmp/{}'.format(key)
download_path = '/tmp/'
print('video path: ' + video_path)
print('download path: ' + download_path)
print('key: ' + key)
print('bucket: ' + bucket)
s3.download_file(bucket, key, download_path)
except Exception as e:
print(e)
print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
raise e我测试了这个函数,得到了以下输出:
START RequestId: aa42300f-5f52-11e6-a14e-a3511b08d368 Version: $LATEST
CONTENT TYPE: video/mp4
video path: /tmp/videos/20160810-182413-jjrni-capturedvideo.mp4
download path: /tmp/
key: videos/20160810-182413-jjrni-capturedvideo.mp4
bucket: bucket
[Errno 18] Invalid cross-device link
Error getting object videos/20160810-182413-jjrni-capturedvideo.mp4 from bucket bucket. Make sure they exist and your bucket is in the same region as this function.
[Errno 18] Invalid cross-device link: OSError
Traceback (most recent call last):
File "/var/task/CreateThumbnail.py", line 48, in lambda_handler
raise e
OSError: [Errno 18] Invalid cross-device link
END RequestId: aa42300f-5f52-11e6-a14e-a3511b08d368错误来自:
s3.download_file(bucket, key, download_path)我不确定为什么当s3可以从以下位置检索密钥和存储桶时,下载文件时会出现错误:
response = s3.get_object(Bucket=bucket, Key=key)如有任何帮助,我们不胜感激!( S3存储桶采用美国标准,我认为是US-East1,而Lambda函数采用US-N。弗吉尼亚州)
发布于 2016-08-11 10:13:21
https://stackoverflow.com/questions/38885346
复制相似问题