Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ec2): Make it easy/possible to create persistent UserData on a Windows instance. #21708

Closed
2 tasks
ddneilson opened this issue Aug 22, 2022 · 2 comments
Closed
2 tasks
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@ddneilson
Copy link
Contributor

Describe the feature

By default, EC2 UserData is run once when an instance is first started after being provisioned. However, it is possible to persist that userdata so that it is run on every instance start. This is a request to expose that functionality in the UserData class for the CDK; specifically, for Windows.

On Linux systems, this persistence is achieved via multipart userdata as in this knowledgebase article. However, on Windows the persist flag must be set as a decorator to the userdata script itself -- outside of the tags (see the tag).

Right now, the only way to achieve this on Windows is through the use of an escape hatch with code that looks something like:

fleet = AutoScalingGroup(...)
 
# Grab the user data from the fleet and add the persist flags as a new string
fleet_user_data = fleet.user_data.render()
new_user_data = f"{fleet_user_data}<persist>true</persist>"
 
# Find the CfnLaunchConfiguration child of the ASG
launch_config = fleet.node.find_child('LaunchConfig')
 
# Replace the user_data property on the CfnLaunchConfiguration
launch_config.user_data = Fn.base64(new_user_data)

This is extremely non-obvious for anyone that isn't a fairly expert user of the CDK; just creating this code involved digging into the depths of the implementation of the ASG L2 construct.

Use Case

Anyone dynamically attaching their Windows instance to an Active Directory (AD) during instance startup needs this functionality; connecting to an AD involves rebooting the instance while running startup scripting both before and after that reboot.

Proposed Solution

I have a PR prepared and will be posting it momentarily.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.38.1

Environment details (OS name and version, etc.)

Any

@ddneilson ddneilson added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Aug 22, 2022
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Aug 22, 2022
@corymhall
Copy link
Contributor

@ddneilson thanks for the feature request and the PR! It looks like someone from the team is reviewing the PR.

@corymhall corymhall added p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Aug 22, 2022
mergify bot pushed a commit that referenced this issue Oct 12, 2022
)

To set the UserData for Windows instances to run on every instance start, rather than only the first startup, requires adding "<persist>true</persist>" to the end of the user data string. Currently, users must use an escape hatch to hack the userdata of
windows instances to add this string. This PR makes it possible to add this text directly on the UserData without using an escape hatch.

Implements: #21708

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants