Elastic Container Service(ECS) is a highly scalable and fast container management service that makes it easy to run, stop, and manage containers on a cluster.
Today, I'll show you how to use it!
Architecture
There are several steps as below, and all of source codes have been put in my github repo(infrastructure and golang-web).
Prerequisites
- Create an aws account with the IAM
AdministratorAccesspermission - Install and configure aws CLI
- Install and configure Terraform
Setup environment
Terraform saves all changes in *.tfstate file, so we'd better store *.tfstate in aws s3 bucket instead of local machine. This step will build a aws s3 bucket to store *.tfstate file.
- Init Terraform
Download infrastructure first
$ cd setup $ terraform init - Create s3 bucket
$ terraform apply You will be prompted to enter an aws region code, such as us-east-1. After that, you need to make sure the listed resources that will be crated and then enter yes
You can see the output s3_bucket_terraform_state below
Outputs: s3_bucket_terraform_state = "**********-us-east-1" Build resources
Now, we begin to build the resources including VPC, subnets, ECS and Pipeline.
- Setup remote backup
$ cd ../region/virginia and then, update the block of s3 in providers.tf file
backend "s3" { bucket = "**********-us-east-1" key = "terraform/backend.tfstate" region = "us-east-1" encrypt = "true" } The following things maybe need to be modified:
- Set
bucketas the output ofs3_bucket_terraform_state - Set
keyas the path to store*.tfstatefile in s3 bucket - Update
regionas the region code that you entered when creating s3 bucket above - Set
encryptastrue
- Create resources
You can modify the configuration in the main.tf file according to your needs, and then run the following commands
$ terraform init $ terraform apply You will be prompted to enter yes after confirmed the listed resources.

After 10 minutes, all resources are created.

Deploy your code
Download golang-web first and then set your git remote as below
$ git remote add aws ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/golang-web $ git remote -v $ git push aws master:master Enumerating objects: 62, done. Counting objects: 100% (62/62), done. Delta compression using up to 12 threads Compressing objects: 100% (55/55), done. Writing objects: 100% (62/62), 25.36 KiB | 6.34 MiB/s, done. Total 62 (delta 26), reused 3 (delta 0), pack-reused 0 To ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/golang-web * [new branch] master -> master Now, everything is done, let's take a look at the outputs in aws.
Outputs
First, we can see VPC and subnet have been created.
- VPC
- Subnets
and then the codepipe has been built
we also can see that a public endpoint is created.
Now, It's time to see CES
Verification
and then see the monitor in Cloud watch

the ecs has been created 2 new tasks

- Scale in Access
stopapi will release CPU resource serval times

















Top comments (0)