Search code examples
pythonamazon-web-servicesdockerboto3amazon-ecs

How to copy files from a finished container in AWS boto3


I am starting with AWS ECS/Fargate. I have managed to create a cluster, service, task and everything else and run a container from a custom Docker image. However, all tutorials and similar seem to expect I use AWS for e.g., hosting a web app or similar. In my case, I simply do some processing (computations) in the container and when it's finished I need to get the resulting file (a .csv).

In Docker, I would achieve what I want doing

docker cp container_id:/outputs /some/local/path/

I am using boto3.

Question: How can I access the container's file system after it has finished using boto3?

I am completely new to web services so if I'm using wrong terminology or if it is a silly question for whatever reason, please let me know.


Solution

  • In general, you don't. If you're using Docker as a job runner, make sure to leave the results somewhere you can retrieve them later. (Even in plain Docker, I'd try to avoid docker cp for routine tasks.)

    In an AWS context, try copying them to an S3 bucket. You can assign an IAM role to an ECS task which would give it the required permissions. Depending on the size of the data and the frequency of results, other potential options include directly HTTP POSTing the data to another service you're running, or sending the content in the body of a RabbitMQ or SQS message. Sending an S3 path in a queue message is often a good combination to set up orchestration between tasks.