Refactor user data to cfn-init with cfn-hup, and enforce the SSM document with a State Manager association
Short answer
BE Refactor user data to cfn-init with cfn-hup, and use an SSM document with a State Manager association to apply changes to running instances.
Question
Key Takeaways
cfn-hup is a daemon that watches the instance metadata for changes and re-invokes cfn-init, which is exactly the mechanism for applying template updates to running instances (B). An SSM document combined with a State Manager association keeps re-applying the desired state automatically (E). Run Command from user data (D) fails because user data never re-runs, and an Auto Scaling scheduled action (C) replaces instances instead of updating the running ones.
User data only runs when an instance boots, so editing it in the CloudFormation template does not update already-running EC2 instances. Refactoring the user data to use the cfn-init helper plus the cfn-hup daemon lets CloudFormation detect metadata changes and re-run cfn-init on running instances. Complementarily, moving the logic into an SSM document and creating a State Manager association makes Systems Manager continuously enforce the document on the fleet, so the application version converges without manual steps.
Common mistake: Using Systems Manager Run Command invoked from user data (D)—user data executes only at instance launch, so it never reaches already-running instances, adding an unnecessary indirection. Using an Auto Scaling group scheduled action with a launch template (C)—that rotates instances rather than updating the application on the existing ones, which is not what the requirement asks. CloudFormation's own answer is cfn-init plus cfn-hup, optionally reinforced by State Manager.
Expert Analysis
Why the Answer Is Correct
EC2 user data is consumed only during instance bootstrap, so applying a stack update that changes user data does not re-run it on running instances. Refactoring the commands into the cfn-init helper and installing the cfn-hup daemon makes CloudFormation poll the instance metadata and automatically re-execute cfn-init when metadata changes, which applies the new application version in place. Independently, defining the work as an SSM document and creating a State Manager association makes Systems Manager continuously enforce that document on the instances, guaranteeing convergence to the stable version.
Why the Other Options Are Wrong
C uses a launch template plus an Auto Scaling scheduled action, which terminates and replaces instances rather than updating the application on the existing running instances, so it does not meet the stated requirement. D invokes Systems Manager Run Command from user data, but because user data runs only at launch, that command never executes on instances that are already running. A is about MIME multipart formatting, which changes how user data is delivered but does not make it re-run. B and E are the correct pair.
Community Comment Notes
Community voted B,E (70), with B,D a minority (26). Commenters emphasized that cfn-hup plus cfn-init applies metadata changes to running instances and that a State Manager association automates ongoing enforcement, whereas Run Command from user data adds an unnecessary step and manual effort.
Official Reference
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-init.html
- https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-state-manager.html
These links open the official vendor documentation in a new tab.
Exam Strategy
Eliminate options relying solely on 'user data' for runtime updates, as it executes only during bootstrap. Choose solutions that actively monitor or enforce configuration on live instances, such as the cfn-hup daemon or SSM State Manager associations.
Frequently Asked Questions
Why doesn't CloudFormation update EC2 apps after stack change?
How does cfn-hup fix this in option B?
What is the role of SSM State Manager in option E?
Community Votes
73% of anonymous learners picked answer BE. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 12 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 12
-
vortegon 👍 8B and E are the most effective in ensuring that updates to the application are installed on the running EC2 instances by leveraging CloudFormation's and AWS Systems Manager's capabilities for managing and applying updates.
-
dkp 👍 3B&E D. Systems Manager Run Command (with user data): Using Run Command within user data to apply an SSM document introduces an unnecessary step. Option E with State Manager automates the process.
-
vmahilevskyi 👍 3EC2 instance profile with AmazonSSMManagedinstanceCore policy doesn't have permissions to SSM Run Command, so D is incorrect. So for me it's BE.
-
Ramdi1 👍 2Here's why these options are correct: Option B: cfn-init is a powerful tool for managing configuration on EC2 instances. By using cfn-init, the DevOps engineer can ensure that the new application version is installed regardless of the current state of the instances. cfn-hup helps keep cfn-init updated with the latest configuration changes. Option D: SSM documents provide a centralized and reusable way to manage configurations. By using Run Command, the engineer can trigger the application update on all instances directly from the template. This approach allows for easier management and updates in the future.
-
thanhnv142 👍 2B and D: A: irrelevant B: cfn-init is perfectly correct for this purpose C: irrelevant. The question does not mention autoscaling group D: <Systems Manager Run Command > can help install packages, so it is correct E: < Systems Manager State Manager> is used to maintain, not to update
Show 7 more comments
-
ogerber 👍 2"Add an AWS CLI command in the user data to use Systems Manager Run Command to apply the SSM document to the EC2 instances."
-
hotblooded 👍 2cfn-hup to chek for updates in cloudformation and ssm run command to run commands if required for application
-
WhyIronMan 👍 2B, E. "Association" is the key. Details are everything during an Investigation...
-
fdoxxx 👍 1B and D A. This option is not applicable for updating applications on EC2 instances. B. Refactoring the user data commands to use the cfn-init helper script helps in handling metadata changes and applying them to the EC2 instances. This is especially useful in CloudFormation stack updates. C. Creating a new EC2 Auto Scaling group with an update policy doesn't necessarily address the application update requirement in this scenario. D. Refactoring the user data commands to use an AWS Systems Manager document and using Run Command to apply the SSM document is a valid approach for updating applications on EC2 instances. E. While using Systems Manager documents and State Manager is a valid approach, it might be more complex than needed for a straightforward update of an application on EC2 instances. Therefore, options B and D together provide a good solution for updating the application on the running EC2 instances.
-
Srikantha 👍 1The best combination of steps to ensure the application is updated on the running EC2 instances during a CloudFormation stack update is: B. Refactor the user data commands to use the cfn-init helper script. Update the user data to install and configure the cfn-hup and cfn-init helper scripts to monitor and apply the metadata changes. D. Refactor the user data commands to use an AWS Systems Manager document (SSM document). Add an AWS CLI command in the user data to use Systems Manager Run Command to apply the SSM document to the EC2 instances.
-
Ramdi1 👍 1ption B: cfn-init is a powerful tool for managing configuration on EC2 instances. By using cfn-init, the DevOps engineer can ensure that the new application version is installed regardless of the current state of the instances Option D: SSM documents provide a centralized and reusable way to manage configurations. By using Run Command, the engineer can trigger the application update on all instances directly from the template.
-
Seoyong 👍 1 Answered EUser data is executed when the system starts, not executed in runing EC2.
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All DOP-C02 Questions
Access 85 questions with complete answers and detailed explanations.
View Full DOP-C02 Practice Test →