Prepare Docker Image at ECR
If you don't have an image at ECR, please check this article and get it.
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
- Create ECS Cluster
- Create ECS Task Definition
- Create ECS Service
- 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.
- Select "Create Cluster" at the ECS console
- Select "Only net-working (Fargate)"
- Name cluster
- Create VPC (optional)
- Select "Create"
※ 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.
- Select "Task Definitions" at the ECS console
- Select "Create new Task Definition"
- Select "Fargate"
- Name task definition
- Select "ecsTaskExecution" for task role
- Select "Linux" for Operating system family
- Select "0.5GB" for Task memory
- Select "0.25vCPU" for Task CPU
- Add container
- Container name: Insert name
- Image: Copy ECR Image URI including tag
- Port mappings: "3000"
- 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 a subordinate 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 3000
"Next step" and skip other items
Set Auto Scaling
Select "Do not adjust the service’s desired count"
"Next step"
⇒ Check all items again, and "Create Service"
4. Confirm ECS Fargate running
- Select "Cluster" at the ECS console
- Select the cluster you created
- Select the "Tasks" tab
- Select task running
- Copy public IP
- Access to public IP with
: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 if you just created it for learning.
Top comments (0)