- Newest
- Most votes
- Most comments
Based on the information provided, it seems you're facing an issue with downloading ONNX model files from S3 during your FastAPI application startup in an ECS Fargate environment. This is a common challenge when working with large model files that shouldn't be included in Git repositories.
For downloading model files from S3 when a FastAPI app starts in ECS Fargate, here are some best practices:
- Use an entrypoint script instead of FastAPI startup events: Rather than relying on FastAPI's startup event, create a shell script as your Docker entrypoint that downloads the models from S3 before starting the application. This ensures the models are available before the application starts.
Example entrypoint.sh:
#!/bin/bash # Download models from S3 python download_models.py # Then start the application exec gunicorn -k uvicorn.workers.UvicornWorker main:app
-
Implement a health check endpoint: Create a health check endpoint in your FastAPI app that verifies the models are loaded correctly. This helps ECS determine if your container is truly ready to serve requests.
-
Use AWS DataSync for larger transfers: For very large model files, consider using AWS DataSync to manage object transfers between your S3 bucket and the container filesystem.
-
Consider using S3 mounting solutions: For production environments, you might want to explore solutions that can mount S3 buckets as local filesystems, allowing your application to access the models without downloading them first.
-
Implement proper error handling and retries: When downloading from S3, implement robust error handling and retry mechanisms to handle temporary network issues.
-
Use IAM roles for ECS tasks: Ensure your ECS task has the appropriate IAM role with permissions to access the S3 bucket containing your models.
The issue with your current approach might be related to how gunicorn workers initialize. When using multiple workers, each worker might be trying to download the models independently, or the startup event might not be firing as expected in the containerized environment.
Sources
Use the AWS InfluxDB migration script to migrate your InfluxDB OSS 2.x data to Amazon Timestream for InfluxDB | AWS Database Blog
Amazon S3 on Outposts | On-Premises Object Storage | AWS
answered a year ago
Hello.
Why not use EFS to host your model data instead of embedding it directly in your container?
https://repost.aws/articles/ARLakw4VYTTnCdFV33wOssxg/aws-re-invent-2024-supercharge-your-ai-and-ml-workloads-on-amazon-ecs
The following session video provides a demonstration of an application hosted on EFS, which may be helpful.
https://www.youtube.com/watch?v=6YfG7ca4wWM
Relevant content
- AWS OFFICIALUpdated 4 years ago
