Start your EC2 instance again, and validate that your script runs correctly. Note: Replace the line /bin/echo "Hello World." > /tmp/testfile.txt with the shell script that you want to run during the instance boot.ħ. In this example, there is only one line to be run, which is /bin/echo "Hello World." > /tmp/testfile.txt. The text/x-shellscript content type provides the actual user script to be run by the cloud-init cloud_final_modules module. The text/cloud-config content type overrides how frequently user data is run in the cloud-init package by setting the SCRIPTS-USER parameter to ALWAYS. However, this example shows both text/cloud-config and text/x-shellscript content-types in a mime-multi part file. bin/echo "Hello World" > /tmp/testfile.txtīy default, cloud-init allows only one content type in user data at a time. Content-Type: multipart/mixed boundary="//"Ĭontent-Type: text/cloud-config charset="us-ascii"Ĭontent-Disposition: attachment filename="cloud-config.txt"Ĭontent-Type: text/x-shellscript charset="us-ascii"Ĭontent-Disposition: attachment filename="userdata.txt" The following example is a shell script that writes "Hello World" to a testfile.txt file in a /tmp directory. Copy your user script into the Edit user data box, and then choose Save. Choose Actions, choose Instance Settings, and then choose Edit User Data.Ħ. For security reasons, create an IAM policy to restrict the users who are allowed to add or remove user data through the ModifyInstanceAttribute API.ĥ. Make sure that the latest version of cloud-init is installed and functioning properly on your EC2 instance.Ģ. Elastic IP addresses persist after an instance stop and start.ġ. If you need the instance to have a static public IPv4 address, consider using an Elastic IP address. If your EC2 instance has an auto-assigned public IPv4 address, then stopping and starting the instance causes the IPv4 address to change.For more information, see Determine the root device type of your AMI. Be sure that you back up any data on the instance store volumes that you want to keep. Stopping and starting the instance erases any data on instance store volumes.Warning: Before starting this procedure, review the following: Note: It's a best practice to create a snapshot of your instance before proceeding with the following resolution. For more information on mime multi-part files, see Mime Multi Part Archive on the cloud-init website. A mime multi-part file allows your script to override how frequently user data is run in the cloud-init package. CloudWatch does not provide any memory, disk space, or load average metrics without running additional software on the instance. However, you can configure your user data script and cloud-init directives with a mime multi-part file. Amazon CloudWatch is a web service that provides real-time monitoring to Amazon's EC2 customers on their resource utilization such as CPU, disk, network and replica lag for RDS Database replicas. By default, user data scripts and cloud-init directives run only during the first boot cycle when an EC2 instance is launched.
0 Comments
Leave a Reply. |