You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从已停止的Fargate任务下载文件?含ECS测试结果下载需求

Handling File Downloads and Task Metadata for Stopped Fargate ECS Tasks

Got it, let's walk through exactly how to tackle your two main needs—pulling files from a stopped Fargate task, and retrieving test results, logs, and exit codes. Since Fargate tasks use ephemeral storage by default, we'll cover different scenarios based on how your task was set up.

1. Downloading Files from a Stopped Fargate Task

First, keep in mind: if your task didn't use persistent storage or export files elsewhere, the temporary container storage is deleted once the task stops. Here are your actionable options:

  • If your task used EFS (Elastic File System) for storage:
    If you mounted an EFS volume to your Fargate task, the files are still stored on EFS. You can access them by launching a temporary EC2 instance or another Fargate task that mounts the same EFS volume. Once connected, use tools like scp (for EC2) or AWS CLI to copy the files to your local machine.

  • If files were logged to stdout/stderr (sent to CloudWatch Logs):
    If your application wrote file content to the console, those logs are in CloudWatch. Use the AWS CLI to export them locally:

    # Replace placeholders with your log group/stream names
    aws logs get-log-events --log-group-name /aws/ecs/your-cluster-log-group --log-stream-name your-task-log-stream --output text > downloaded-file.txt
    

    Alternatively, go to the CloudWatch Console, find the log stream, and use the "Download" button to save logs as a text file.

  • If files were uploaded to S3 during task execution:
    If your test task was configured to upload results/files to an S3 bucket, just use the AWS CLI to pull them down:

    aws s3 cp s3://your-bucket/path/to/test-results/ ./local-output-folder/ --recursive
    

2. Retrieving Test Results, Logs, and Container Exit Code

Let's break this into individual steps:

Get the Container Exit Code

Use the AWS CLI to describe your task—this will return the exit code along with other metadata. You can even use jq to extract just the exit code for simplicity:

# Replace with your cluster name and task ID
aws ecs describe-tasks --cluster your-ecs-cluster --tasks your-task-id | jq '.tasks[0].containers[0].exitCode'

If you don't have jq, you can parse the JSON manually or use the ECS Console: navigate to your task details, find the container section, and look for the "Exit Code" field.

Access and Download Logs (including test results)

As mentioned earlier, logs are stored in CloudWatch Logs. For quick access, use:

# Tail logs (useful if you want to review before downloading)
aws logs tail /aws/ecs/your-log-group --log-stream-name your-task-log-stream --since 24h

# Download full log stream to a local file
aws logs get-log-events --log-group-name /aws/ecs/your-log-group --log-stream-name your-task-log-stream --output text > test-logs-and-results.txt

You can also filter logs in the CloudWatch Console to find specific test result entries, then download the filtered logs.

Download Test Result Files

Follow the same logic as section 1:

  • If results are on EFS: mount the volume and copy them.
  • If results were logged: export from CloudWatch.
  • If results were uploaded to S3: use aws s3 cp to download.

Pro tip: For future tasks, set up automatic uploads to S3 or use EFS for persistent storage—this avoids losing files when tasks stop.

内容的提问来源于stack exchange,提问作者Ryan Shillington

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:33:13