Errno 18:无效的跨设备链接

时间:2016-08-11 00:00:07

标签: python-2.7 amazon-web-services amazon-s3 aws-lambda boto3

我正在亚马逊lambda上编写一个函数,并编写了下面的脚本,但我收到了一个错误。只要将对象放入S3 Bucket,脚本就会运行。

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。弗吉尼亚州)

1 个答案:

答案 0 :(得分:0)

您的问题与此问题类似https://github.com/amorton/cassback/issues/2

如何从/ tmp建立相对路径而不是文件?

另外,为什么还需要在服务器中获取文件?