I'm using the UserData
field in a CloudFormation
template to install software on the instance. When I update the UserData
I would like CloudFormation
to replace the instance. However, UserData
is not a replace field and as a result the instance is stopped but not replaced and the new UserData
script is never run.
Is there a way I can update the UserData
with CloudFormation
?
I'm referring to this documentation.
When you directly update a stack, you submit changes and AWS CloudFormation immediately deploys them. Use direct updates when you want to quickly deploy your updates. With change sets, you can preview the changes AWS CloudFormation will make to your stack, and then decide whether to apply those changes.
Sign in to the AWS Management Console and open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation . In the AWS CloudFormation console , from the list of stacks, select the running stack that you want to update. In the stack details pane, choose Update.
As you can see in the documentation, updating user data doesn't necessarily (and in most cases shouldn't) require replacing the instance.
You could try and run the updated User Data script from a Systems Manager command. The script should be stored in /var/lib/cloud/instances/[instance-id]/user-data.txt
OR you can set it to run after rebooting. Check out the guide at https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/ , and more examples at https://cloudinit.readthedocs.io/en/latest/topics/examples.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With