如何从在Fargate上运行的Docker容器上载文件到S3存储桶? [英] How to upload a file from a Docker container that runs on Fargate to S3 bucket?

查看:178
本文介绍了如何从在Fargate上运行的Docker容器上载文件到S3存储桶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个容器化项目,输出文件写在本地容器中(执行完成后删除),该容器在Fargate上运行,我想编写一个Python脚本,该脚本可以调用在Fargate上运行的模型并获取输出文件并将其上传到S3存储桶,对于AWS和Docker来说我是新手,有人可以给我发送示例或分享一些有关实现此目标的想法吗?

I have a containerized project, the output files are written in the local container (and are deleted when the execution completes), the container runs on Fargate, I want to write a Python script that can call the model that runs on Fargate and get the output file and upload it to an S3 bucket, I'm very new to AWS and Docker, can someone send me an example or share some ideas about how to achieve this?

我认为@jbleduigou的回答使事情变得复杂,现在我可以使用命令从容器中将文件复制到本地计算机上,我只需要编写脚本来调用模型并将其复制并上传即可到S3,我知道这个概念,但是找不到示例.任何人都可以给我一个示例来实现这一目标吗?

I think the answer by @jbleduigou makes things complicated, now I can use command to copy the file on my local machine from the container, I just need to write a script to call the model and copy this file out and upload it to S3, I know the concept but couldn't find an example.Anyone can give me an example to achieve this?

推荐答案

您需要执行或等同于Python:

Or equivalent in Python:

import boto3

client = boto3.client('s3')

response = client.put_object(
    Body='c:\HappyFace.jpg',
    Bucket='examplebucket',
    Key='HappyFace.jpg'
)

print(response)

为了使您的容器有权将文件上传到S3,您需要设置

In order for your container to have the right to upload files to S3 you need to setup Task Execution Role and assign it to your task.

这篇关于如何从在Fargate上运行的Docker容器上载文件到S3存储桶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆