This Flask application provides functionality to upload and download images from an Amazon S3 bucket. The app is designed to run on Amazon ECS and interacts with AWS services using specific IAM permissions.
- Description: Displays images available in the S3 bucket.
- Details:
- Images must be present in s3 bucket.
- The route displays image provided in request fetching the corresponding images from the bucket.
- Requires the following permissions:
s3:GetObject
kms:Decrypt
- Description: Uploads an image to the specified S3 bucket.
- Details:
- Users can upload images to the bucket provided in the environment variables.
- only .jpg format is accepted
- Requires the following permissions:
s3:PutObject
kms:Encrypt
kms:GenerateDataKey
- Description: A simple health check endpoint.
- Details: Returns a status indicating the health of the application.
The following environment variables must be set for the application to function correctly:
IMAGES_BUCKET
: The name of your S3 bucket where images are stored.AWS_REGION
: The AWS region where the ECS task is running.
- AWS account with an S3 bucket.
- IAM role with the necessary permissions.
- Docker and AWS CLI installed.
- ECS cluster configured.
-
Clone the Repository:
git clone https://github.com/your-repo/ImagesRepo.git cd ImagesRepo
-
Build the Docker Image:
docker build -t flask-ecs-image-app .
-
Run the Container Locally (for testing):
docker run -e IMAGES_BUCKET=your-bucket-name -e AWS_REGION=your-region -p 5000:5000 flask-ecs-image-app
-
Deploy on ECS:
- Create an ECS task definition with the necessary environment variables and IAM role.
- Create a service using this task definition.
Ensure the IAM role attached to your ECS task has the following permissions:
-
For
/image?image_name={image_name}
route:s3:GetObject
kms:Decrypt
-
For
/upload
route:s3:PutObject
kms:Encrypt
kms:GenerateDataKey
You can upload an image using a tool like curl
or Postman:
curl -X POST -F "file=@path/to/your/image.jpg" http://localhost:5000/upload
Navigate to http://localhost:5000/image?image_name=image
to see a random selection of images from your S3 bucket.
Visit http://localhost:5000/health
to perform a health check on the application.
docker pull srokade/s3ecsapp:image5
This Flask application provides a simple interface for uploading and downloading images to and from an S3 bucket, leveraging AWS services and running on ECS. Ensure all necessary environment variables are set and IAM permissions are correctly configured for seamless operation.