2016-08-11 85 views
1

我正在寫一個亞馬遜lambda的函數,並在下面寫了腳本,但我得到一個錯誤。只要將對象放入S3桶中,腳本就會運行。Errno 18:無效的跨設備鏈接

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的桶是美國標準,我認爲這是美國East1,而lambda函數是在美國-N。弗吉尼亞州)

回答

0

您的問題類似於這樣一個https://github.com/amorton/cassback/issues/2

如何建立相對路徑而不是從/ tmp文件?

此外,爲什麼你需要獲取服務器中的文件?

+0

每當視頻上傳到S3存儲桶時,我都需要運行腳本。我遵循本教程中的代碼在Python部分:[aws lambda python example](http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html)和他們使用了/ tmp文件的路徑 – alienboy