Skip to Content

Working with User Data: User Data Default Behavior in AWS EC2 Instances

Learn about the default behavior of user data in AWS EC2 instances. Discover when user data scripts run and how they can be modified to automate instance configuration.

Table of Contents

Question

Which statement about user data is correct?

A. By default, user data only runs new commands in a modified script.
B. By default, user data runs every time it’s modified.
C. By default, user data runs every time the instance reboots.
D. By default, user data runs only when the instance is first launched.

Answer

D. By default, user data runs only when the instance is first launched.

Explanation

To re-run user data scripts, you must first log into the instance and delete the config_scripts_user file. Then, when you restart the instance, the user data will run again.

When you launch a new EC2 instance, you have the option to pass user data to the instance. User data is data that is supplied by the user at instance launch in the form of a script. By default, the user data script is only executed once when the instance is first launched.

The script is run with root user privileges and can be used to perform common automated configuration tasks and even run scripts after the instance starts. For example, you could use user data to patch and update the operating system, install additional software, or copy data to the instance.

After the initial launch, the user data script does not run again automatically, even if the instance reboots or the user data is modified. To execute the user data script again after modifying it, you would need to explicitly configure that behavior using cloud-init directives or by using the AWS::CloudFormation::Init resource in an AWS CloudFormation template.

So in summary, user data provides a convenient way to automatically configure instances at launch, but by default it only runs once when the instance is first started, not on subsequent reboots or modifications, unless explicitly configured to do so.

Working with User Data EDDATAv1EN-US course final assessment question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Working with User Data EDDATAv1EN-US course and earn Working with User Data EDDATAv1EN-US qualification.