AWS Launch Configuration does not collect user data

We are trying to create an autoscale group (say AS) configured with elastic load balancing (say ELB) in AWS. The autoscale group is set up with a launch configuration (say LC). As far as I understood from the AWS documentation, inserting the script as it is in the custom data section of the launch config would run this script for every instance launched into an autoscale group, the associated autoscale group.

For example, pasting this into user data will have a file named configure available in the home folder of the micro ubuntu t2 image:

#!/bin/bash
cd
touch configure
      

Run codeHide result


Our end goal: Increase the number of instances in the autoscale group, they are started by our run script and this new instance is added behind the load balancer tagged by the autoscale group. But the script was not running when the instance started. My questions are: 1. Am I missing something? 2. What do I need to do to get our run script to run when any new instance is started in the autoscale group? 3. Is there a way to check if user data was actually loaded at startup?

+3


source to share


1 answer


The direction you are following is correct. What is wrong is your custom script data.

Problem 1:

What you have to remember is that the user data will be executed as a user root

, not ubuntu

. So if your script worked fine, you will find your file at /root/configure

, NOT IN /home/ubuntu/configure

.

Problem 2:

Your script is actually executed, but it is wrong and does not work in command cd

, so no file is created.

cd

the built-in command without any given directory will try to execute cd $HOME

, however $HOME

WILL NOT INSTALL when cloud-init starts up, so you must be explicit here.




Change your script to below and it will work:

#!/bin/bash
cd /root
touch configure

      

You can also debug problems with your custom script data by checking the log file /var/log/cloud-init.log

, specifically checking for errors in it:grep -i error /var/log/cloud-init.log

Hope it helps!

+3


source







All Articles