DEV Community

Rajesh Kumar
Rajesh Kumar

Posted on

Deploy dockerized app in Aws ECS in existing vpc.

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,

  1. Your docker container image needs to be push to ECR.
  2. 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

  1. 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.
  2. aws cli & terraform cli must be available in your command line. aws --version terraform --version
  3. aws details must be avaialble
    AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXX
    AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXX
    AWS_REGION=ap-southeast-1
    AWS_PROFILE=dev

  4. You 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"
}

Enter fullscreen mode Exit fullscreen mode
Application
  1. go to deploy folder
  2. update AWS parameters in create_repo_in_ecr.sh and run this file.
  3. Above script will create a repo in your aws account and print that ecr repo link in your console.
  4. Copy ecr link & update aws parameter in push_image_to_ecr_&_deploy_ecs.sh file.
  5. 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
Enter fullscreen mode Exit fullscreen mode

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

  1. Replace your application inside demo-app content & make sure your application working dockerized.
  2. Create health check api - api/index This is configured inside variable.tf file in terraform folder
  3. 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)

Collapse
 
tsamaya profile image
Arnaud Ferrand

Thank you for this tutorial, much appreciated

Collapse
 
diek profile image
diek

Interesting, thank you!