After struggling for few days to deploy a dockerrized applicatin in ECS, found the solution & simplified into script, so that anyone can deploy easily simply replacing app folder.
To deploy your application in ECS,
- Your docker container image needs to be push to ECR.
- From ECR repo, application will deploy in ECS
git location
https://github.com/rajeshkumarbehura/ecs-app-deploy
Requirement an application to deploy in Aws ECS
- Project must dockerized. In my repo, its demo-app folder which is nestjs based simple application.You can have java/nodejs/python any kind of project as long as it is dockerized.
- aws cli & terraform cli must be available in your command line. aws --version terraform --version
aws details must be avaialble
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXX
AWS_REGION=ap-southeast-1
AWS_PROFILE=devYou should know, whats your existing vpc & public subnet name in aws account.
Steps to deploy
Clone the project in your local.
Update VPC details in terraform
Go to /deploy/terraform/network.tf and replace dev-data-stream-vpc name with your existing vpc name.
Replace dev-data-stream-public-subnet name, with your existing public subnet tied with your existing vpc name.
variable "existing_vpc_name" {
description = "Existing VPC in your aws cloud"
default = "dev-data-stream-vpc"
}
variable "existing_vpc_public_subnet_name" {
description = "public subnet name which tie up with existing vpc"
default = "dev-data-stream-public-subnet"
}
Application
- go to deploy folder
- update AWS parameters in create_repo_in_ecr.sh and run this file.
- Above script will create a repo in your aws account and print that ecr repo link in your console.
- Copy ecr link & update aws parameter in push_image_to_ecr_&_deploy_ecs.sh file.
- finally run push_image_to_ecr_&_deploy_ecs.sh script on your console to deploy this application
Destroy in AWS
Cleaning or deleteing all resources in aws, use below command.
terraform destroy
Once you can deploy and destroy successfully, then you can change more parameter and play around terraform files to understand more.
How to deploy your own application
- Replace your application inside demo-app content & make sure your application working dockerized.
- Create health check api - api/index This is configured inside variable.tf file in terraform folder
- Optional step- to create your all configuration with a new name, do a find all for "demoapp" text inside terraform folder and replace with ur own text. For example- replace "demoapp" text with "customerapp". Then do terraform plan, and check all things are working or not. if any place, please rename according to your text.
Play with terraform, ecr & ecs to explore more.
Top comments (2)
Thank you for this tutorial, much appreciated
Interesting, thank you!