![](/img/trans.png)
[英]Running python boto3 inside a docker container requirements on AWS
[英]Running Python code (Boto3) remotely (AWS)
我有將項目從一個s3存儲桶移動到另一個的代碼。 我正在計算機上本地運行它。 但是,由於存儲桶中有很多項目,因此需要很長時間才能完成運行。
import boto3
#Get resource
s3 = boto3.resource('s3')
#Get reference to buckets
src = s3.Bucket('src')
dst = s3.Bucket('dst')
#Iterate through the items in the source bucket
for item in src.objects.all():
#Creates a copy of the item?
copy_source = {
'Bucket' : 'src',
'Key' : item.key
}
#Places the copy of the item in the destination bucket
dst.copy(copy_source,'Images/'+item.key)
有什么方法可以遠程運行此代碼,而不必監視它? 我已經嘗試過AWS lambda,但最長運行時間為15分鍾。 有沒有類似的東西我可以使用,但需要更長的時間。
您可以使用數據管道 。 數據管道會產生一個EC2實例,您可以在其中運行作業。 您可以安排管道至少每15分鍾運行一次。 (但不少)還可以選擇創建一個按需運行的管道。 它還提供了一個控制台,您可以在其中查看作業及其結果,並有機會重新運行失敗的作業。
對於這種活動,您可能應該使用以下方法:
https://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-object-shellcommandactivity.html
另一個選擇是僅啟動EC2實例運行您的作業,然后停止它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.