Configuration of ECS Fargate starts from defining a Task. To define a Task with docker we need to dockerize the code base and need to upload to ECR.
Make Docker image
docker build -t <name> .
Tag the image
docker tag aws-rds-node-api:latest 9999999999999.dkr.ecr.us-east-1.amazonaws.com/aws-rds-node-api:latest
Retrive login passward for he repository
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 999999999999.dkr.ecr.us-east-1.amazonaws.com
Push the image to ECR
docker push 9999999999.dkr.ecr.us-east-1.amazonaws.com/aws-rds-node-api:latest
Now the image is ready in the ECR for deployment
Fargate Task Configuration There are two things need to do before start the Task Configuration. There must be Task Role. Other one is define production environment variables.
Create production.env I created S3 bucket to store production.env under the folder cssamlabs/lab-node-atlas-api/.
Then create a Task Execution Role. I added RDSFullAccess since application needs to access RDS.
There must be a policy to access S3 to read productio.env file.
Now start configuring Task Definition
Copy image name from ECR Port is map to 3040 where NodeJS application configured in Dockerfile.
Configure Production env in Environment Files section by giving the file's ARN
Once create Task Definition is like
Next step is to create Fargate Cluster Configured Cluster is
Create a Container Service A Service Name needed. Select the Cluster created above.
Select the VPC and Subnects. Usually it creates new Security Group.
Now Creating a Task from Task Definition could carryout. Task running in Fargate Service