Search code examples
amazon-web-servicescloud-init

How can I prevent AWS cloudinit to execute the userdata if they contain a bash script


I am trying to package my software into an AWS AMI.

I would like to disable in my AMI the logic which executes the userdata if it detects that it contains a bash script, without disabling the whole userdata system (I am accessing the userdata through the metadata-url (169.254.169.254)).

My AMI is based on the Amazon Linux AMI x86_64 PV EBS (ami-5256b825) which uses cloud-init 0.7.2-7.20.

I have already tried to comment the following lines in the /etc/cloud/cloud.cfg.d/defaults.cfg but the AWS AMI creation process seems to overwrite this file with the default values.

 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user

Note: On the old AWS AMIs (for instance ami-5256b825), I had been doing this with the following sed command :

sed -i 's/once-per-instance/never/g' /etc/init.d/cloud-init-user-scripts

Solution

  • You can could create the cloud-init lock file (e.g. "/var/lib/cloud/sem/user-scripts.i-7f3f1d11") before it runs. As cloud-init runs last and checks for the absence of this lock file to run the user data, user data would not run. You can condition that to the user data starting with "#!/bin/bash".