pass python script in cloud init through terraform

513 views Asked by At

I am creating an ASG in which i want to call few rest api's soon after the instance is created. i know i can write a bash script and pass that in cloud-config but i want to use a python script since that will give me additional advantage of using json parsing libraries. i am not able to figure out how to pass the python file in user-data cloud-config. any help is much appreciated.

  # ...terraform stuff for ASG
  user_data = <<EOF
  #cloud-config
  #script.py(my python script)
1

There are 1 answers

0
T.H. On

One way would be to run your script inline, as in python -c "print 'Hello, World!'".

If you really need a script passed in you'll need to have the user_data script download it to the instance from some storage location. Or if you're using a custom built AMI you would be able to include the script on the AMI.