Easy to use ECS

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 be…


This content originally appeared on DEV Community and was authored by Pin Xiong

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

Architecture

There are several steps as below, and all of source codes have been put in my github repo(infrastructure and golang-web).

Prerequisites

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:

  1. Set bucket as the output of s3_bucket_terraform_state
  2. Set key as the path to store *.tfstate file in s3 bucket
  3. Update region as the region code that you entered when creating s3 bucket above
  4. Set encrypt as true
  • 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.
Confirm the listed resources

After 10 minutes, all resources are created.
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 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 VPC
  • Subnets Subnets

and then the codepipe has been built

  • CodeCommit
    CodeCommit

  • CodeBuild
    CodeBuild

  • CodePipeline
    CodePipeline
    CodePipeline

  • ECR
    ECR

we also can see that a public endpoint is created.

  • ELB
    ELB

  • Target group
    Target group

Now, It's time to see CES

  • ECS Dashboard
    ECS Dashboard

  • ECS Cluster
    ECS Cluster

  • ECS Service
    ECS Service

  • Task Definition
    Task Definition

Verification

  • Access public endpoint
    Access public endpoint

  • Scale out
    Access start api will exhaust CPU resource serval times
    Exhaust CPU resource

and then see the monitor in Cloud watch
Cloud watch

the ecs has been created 2 new tasks
Created 2 new tasks

  • Scale in Access stop api will release CPU resource serval times Release CPU resource

and then see the monitor in Cloud watch
Cloud watch

the ecs has been draining tasks
Drain tasks


This content originally appeared on DEV Community and was authored by Pin Xiong


Print Share Comment Cite Upload Translate Updates
APA

Pin Xiong | Sciencx (2022-07-15T14:00:09+00:00) Easy to use ECS. Retrieved from https://www.scien.cx/2022/07/15/easy-to-use-ecs/

MLA
" » Easy to use ECS." Pin Xiong | Sciencx - Friday July 15, 2022, https://www.scien.cx/2022/07/15/easy-to-use-ecs/
HARVARD
Pin Xiong | Sciencx Friday July 15, 2022 » Easy to use ECS., viewed ,<https://www.scien.cx/2022/07/15/easy-to-use-ecs/>
VANCOUVER
Pin Xiong | Sciencx - » Easy to use ECS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/15/easy-to-use-ecs/
CHICAGO
" » Easy to use ECS." Pin Xiong | Sciencx - Accessed . https://www.scien.cx/2022/07/15/easy-to-use-ecs/
IEEE
" » Easy to use ECS." Pin Xiong | Sciencx [Online]. Available: https://www.scien.cx/2022/07/15/easy-to-use-ecs/. [Accessed: ]
rf:citation
» Easy to use ECS | Pin Xiong | Sciencx | https://www.scien.cx/2022/07/15/easy-to-use-ecs/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.