[ECS] [request]: Have ECS agent check user data before connecting to default cluster
- Dominant language
- Shell
- Stars
- 5.4k
- Forks
- 334
- PR merge metrics
- No merged PRs in 30d
Description
### Community Note
* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment
**Tell us about your request**
What do you want us to build? Have the ECS agent check instance metadata to confirm if it is connecting to the correct cluster before connecting to the default cluster.
**Which service(s) is this request for?**
ECS
**Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard?**
What outcome are you trying to achieve, ultimately, and why is it hard/impossible to do right now? What is the impact of not having this problem solved? The more details you can provide, the better we'll be able to understand and solve the problem.
In the event that cloud-init fails to run for some reason but the instances is not declared unhealthy and terminated, the userdata script can fail to run which results in ecs.config not getting the correct cluster name. This will cause the node to connect to and possibly create the default cluster.
**Are you currently working around this issue?**
How are you currently solving this problem?
Adding a daemonset to the default cluster using the below Dockerfile and script to auto terminate any nodes that get connected to the default cluster.
[1]
#Dockerfile
```
FROM amazonlinux
RUN yum install -y unzip wget
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip " -o "awscliv2.zip "
RUN unzip awscliv2.zip
RUN ./aws/install
COPY ./terminatescript.sh .
RUN chmod +x ./terminatescript.sh
CMD ./terminatescript.sh
```
terminatescript.sh
```
#!/bin/bash
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id` "
EC2_AVAIL_ZONE="`wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone` "
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
aws ec2 terminate-instances --instance-ids $EC2_INSTANCE_ID --region $EC2_REGION
sleep 10
```
**Additional context**
Anything else we should know?
**Attachments**
If you think you might have additional information that you'd like to include via an attachment, please do - we'll take a look. (Remember to remove any personally-identifiable information.)
Contributor guide
Research direction
Start by reviewing the ECS agent behavior around instance metadata, user data, and selection of the default cluster; the issue does not name repository files, tests, or an entry point. Done would mean the agent verifies the intended cluster configuration before connecting, with coverage for the cloud-init failure scenario described here.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100