[ecs] AutoScalingGroup.UserData contains invalid commands for Windows nodes
See original GitHub issueIf ECS AutoScalingGroup is used with Windows containers, resulting UserData has invalid commands, not applicable to Windows nodes:
<powershell>
echo ECS_CLUSTER=win-cluster611F8AFF-UX2YM1DXYE1E >> /etc/ecs/ecs.config
sudo iptables --insert FORWARD 1 --in-interface docker+ --destination 169.254.169.254/32 --jump DROP
sudo service iptables save
echo ECS_AWSVPC_BLOCK_IMDS=true >> /etc/ecs/ecs.config
</powershell>
There is no way to override this, as far as I can tell. Here is the responsible code:
Reproduction Steps
Here is the snippet (in C#, TypeScript would be a direct equivalent):
var userData = UserData.ForWindows();
// It is necessary to run this command to join the cluster
userData.AddCommands($"Initialize-ECSAgent -Cluster {cluster.ClusterName} -EnableTaskIAMRole -LoggingDrivers '[\"json-file\",\"awslogs\"]'");
var autoScalingGroup = new AutoScalingGroup(this, "autoScalingGroup", new AutoScalingGroupProps
{
// ...
UserData = userData
});
cluster.AddAutoScalingGroup(autoScalingGroup);
Resulting CloudFormation:
UserData:
Fn::Base64:
Fn::Join:
- ""
- - "<powershell>Initialize-ECSAgent -Cluster "
- Ref: cluster611F8AFF
- >-2
-EnableTaskIAMRole -LoggingDrivers '["json-file","awslogs"]'
echo ECS_CLUSTER=
- Ref: cluster611F8AFF
- >-2
>> /etc/ecs/ecs.config
sudo iptables --insert FORWARD 1 --in-interface docker+ --destination 169.254.169.254/32 --jump DROP
sudo service iptables save
echo ECS_AWSVPC_BLOCK_IMDS=true >> /etc/ecs/ecs.config</powershell>
Other
I believe what we are trying to do here is to codify the best practices for cluster nodes so CDK customer does not need to worry about these details. The problem is that the best practices are different between Linux and Windows platforms.
At the moment Windows cluster nodes have to be configured manually, according to AWS docs.
It would be great to incorporate these guidelines into CDK to streamline ECS cluster creation for Windows AMIs.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Troubleshoot why your ECS or EC2 instance can't join the ...
The instance user data for your ECS container isn't configured properly. The ECS agent is stopped or not running on the instance. The...
Read more >AWS EKS Module - Terraform Registry
Windows based node support is limited to a default user data template that is provided due to the lack of Windows support and...
Read more >User-data scripts is not running on my custom AMI, but ...
User_data is run only at the first start up. As your image is a custom one, I suppose it have already been started...
Read more >AWS Dev Practice Questions Flashcards - Quizlet
The firm needs a certain software to be available on the instances to support their daily workflows. The developer team has been told...
Read more >AWS Solutions Architect Associate SAA-C02 Practice ...
Part 6 in series AWS Solutions Architect Associate SAA-C02 Practice Exam. This part include 65 high quality practice questions and it's free ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured out how to mutate the user data.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.