Create ECS Fargate
Published: 2022-05-05 12:28:53

Written with [Cameron Gibson](https://github.com/cgcamcam) 

## Prepare Docker Image at ECR
If you don't have an image at ECR, please check this article: [Push Docker image to AWS ECR](https://dev.to/jun_uen0/push-docker-image-to-aws-ecr-fb2)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/svxojr7pax7g8ba1bprh.png) 
2. Select "Only net-working (Fargate)"
![Only net-working](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7pdboqid5akr99kanciy.png)
3. Name cluster
4. Create VPC (optional)
5. "Create"
![Create Cluster2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gazrm34t51c55gt7p40b.png)
 
※ 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nh3dn0jl206fb9hy81w.png) 
9. Add container
    - Container name: Insert name
    - Image: Copy ECR Image URI including tag![Copy ECR Image URI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rqcqd4cd29gdzylcz7qh.png)
    - Port mappings: "3000"![Port mappings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m98mgrjuc7fqiqrrfks0.png)
 
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
1. Select "Cluster" at the ECS console
2. Select the cluster you created
3. Select the "Service" tab
4. Select "Create"
5. Launch type: "Fargate"
6. Task Definition: Select the task you created
7. Service name: Insert name
8. Number of tasks: 1
9. "Next step" and skip other items

- Configure network
1. Cluster VPC: choose your VPC for ECS (If you created VPC at "1. Create ECS Cluster", use it )
2. Select Subnets as many as you need
3. Click "Edit" for Security groups
    - Add Inbound rules： custom TCP / Anywhere / port 3000![Add Inbound rules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0wd084kzhk1tyt53hdb.png)
 
4. "Next step" and skip other items

- Set Auto Scaling
1. Select "Do not adjust the service’s desired count"
2. "Next step"
![Create Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eh9e6f4yly4u6kq4eb29.png)
 
⇒ 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s8jjvm48x6ow6beqbxx.png)
6. Access to public IP with `:3000`
![3000](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jveb28lndvhel9zsmc2p.png) 

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.