DEV Community

Jun Ueno
Jun Ueno

Posted on

Create ECS Fargate

Written with Cameron Gibson

Prepare Docker Image at ECR

If you don't have an image at ECR, please check this article: Push Docker image to AWS ECR
In this article, I use React app image.

About ECS

= AWS Elastic Container Service
It's a highly scalable and fast container management service.

■ Terminologies in ECS

  • Task / Task Definition: For setting container
  • Service: For setting tasks, auto-scaling, VPC, etc
  • Cluster: The cluster of services

Hands-On Steps

  1. Create ECS Cluster
  2. Create ECS Task Definition
  3. Create ECS Service
  4. Confirm ECS Fargate running

1. Create ECS Cluster

ECS Cluster is a cluster of services that is EC3 instances. But no one can control the EC2 via SSH access because each EC2 instance is hidden.

  1. Select "Create Cluster" at the ECS console Create Cluster
  2. Select "Only net-working (Fargate)" Only net-working
  3. Name cluster
  4. Create VPC (optional)
  5. "Create" Create Cluster2

※ Wait 1 or 2 minutes.

2. Create ECS Task Definition

Task is like a Docker container. In this configure console, you can configure the container. So it's like a docker-compose.yml.

  1. Select "Task Definitions" at the ECS console
  2. Select "Create new Task Definition"
  3. Select "Fargate"
  4. Name task definition
  5. Select "ecsTaskExecution" for task role
  6. Select "Linux" for Operating system family
  7. Select "0.5GB" for Task memory
  8. Select "0.25vCPU" for Task CPU Task Definitions
  9. Add container

    • Container name: Insert name
    • Image: Copy ECR Image URI including tagCopy ECR Image URI
    • Port mappings: "3000"Port mappings
  10. Create

3 Create ECS Service

ECS Service is the collection of ECS Tasks and it's related to ALB and AutoScaling Group. ECS Service needs ECS Task when created, but it's technically not superordinate of ECS Task because you can assign ECS Task to ECS Cluster without Service setting.

  • Configure service
  • Select "Cluster" at the ECS console
  • Select the cluster you created
  • Select the "Service" tab
  • Select "Create"
  • Launch type: "Fargate"
  • Task Definition: Select the task you created
  • Service name: Insert name
  • Number of tasks: 1
  • "Next step" and skip other items

  • Configure network

  • Cluster VPC: choose your VPC for ECS (If you created VPC at "1. Create ECS Cluster", use it )

  • Select Subnets as many as you need

  • Click "Edit" for Security groups

    • Add Inbound rules: custom TCP / Anywhere / port 3000Add Inbound rules
  1. "Next step" and skip other items
  • Set Auto Scaling
  • Select "Do not adjust the service’s desired count"
  • "Next step" Create Service

⇒ Check all items again, and "Create Service"

4. Confirm ECS Fargate running

  1. Select "Cluster" at the ECS console
  2. Select the cluster you created
  3. Select the "Tasks" tab
  4. Select task running
  5. Copy public IP Confirm ECS Fargate
  6. Access to public IP with :3000 3000

Good job.
Please make sure you deleted the cluster.
It's better to delete any resources in AWS if you don't need to operate it for a long time or just created it for learning.

Top comments (0)