Background
By default, when we create a new ec2 instance, ecs will automatically assign that ec2 instance to the cluster named "default", but we want ecs to put it in an already created cluster.
How
When creating the ec2 instance, remember 3 major things
- Select "ECS-optimized" instances in AMI community
- Create IAM "ecsInstanceRole" to allow ecs have the right to run commands in ec2 instances
- Refer to https://docs.aws.amazon.com/AmazonECS/latest/developerguide/instance_IAM_role.html for more info
- Configure "User Data" entry to let ecs know which cluster we want to place the ec2 instance to
#!/bin/bash echo ECS_CLUSTER=[CLUSTER_NAME] >> /etc/ecs/ecs.config
沒有留言:
張貼留言