question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ecs] AutoScalingGroup.UserData contains invalid commands for Windows nodes

See original GitHub issue

If 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:

https://github.com/aws/aws-cdk/blob/fff798c0be3611671050dee8eb8c55de645a7527/packages/%40aws-cdk/aws-ecs/lib/cluster.ts#L186-L196

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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ghostcommented, Nov 13, 2019

I figured out how to mutate the user data.

const launchConfig = asg.node.findChild('LaunchConfig') as CfnLaunchConfiguration;
    const userDataScript = '<powershell>Import-Module ECSTools' + '\n' + `Initialize-ECSAgent -Cluster ${ecsCluster.clusterName} -EnableTaskIAMRole</powershell>`+ '\n' +'<persist>true</persist>';
    launchConfig.addPropertyOverride('UserData', Fn.base64(userDataScript));
0reactions
github-actions[bot]commented, Jan 12, 2021

⚠️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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found