EC2 User Data In CloudFormation (cfn init, wait, and signal)
Learn about EC2 user data in CloudFormation, an essential exam topic.
Introduction
The EC2 resource in CloudFormation has a UserData
property that allows users to pass EC2 user data to the instances created by a template. The UserData
property isn’t required for EC2 resources, and we can create an EC2 instance without specifying any value for this property, as we did in the previous lesson.
Note: User data is used to specify commands that have to run when the EC2 instance is launched. Generally, it contains commands to update the EC2 software and download any dependencies required for EC2 to perform its actions.
The outputs of a user data script are stored in the /var/log/cloud-init-output.log
file.
The following code sample uses the CloudFormation intrinsic function Base64
to encode the user data script as a Base64
string. Creating an EC2 instance with this user data will automatically start an httpd web server on the instance.
Get hands-on with 1400+ tech skills courses.