22

Is it possible to run python script through AWSCLI (user-data). I tried but it didn't run and i have following in my logs

boot.log:2015-08-07 10:08:30,660 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: './step-1
cloud-init.log:2015-08-07 10:08:30,660 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: './step-1'
cloud-init-output.log:2015-08-07 10:08:30,660 - __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: './step-1'

Note step-1 is my script which i am trying to pass as user-data . Also my script is present in same directory from where i am running command so it should pick

2
  • 2
    Can you post the actual command and parameters?
    – helloV
    Commented Aug 7, 2015 at 21:21
  • 3
    It seems that your script does not specify the shell it is supposed running in. I mean, #!/bin/bash e.t.c.
    – mipo256
    Commented Oct 26, 2021 at 20:13

4 Answers 4

23

The default interpreter seems to be Python. So if you simply want to execute a shell script you'll need to start with a hash-bang, for example:

#!/bin/bash 
/yourpath/step-1

Please note, in order to debug this, try: cat /var/log/cloud-init-output.log And see: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-shell-scripts

3

You can use any command to be run under user-data. I have used user-data to bootstrap Windows Instances with Domain Controller setup or domain join using PowerShell; of course given that it is on EC2 - the properties are extensible whether you are running in Unix based or Windows Based.

So you have specified, Python - so please ensure the following

  1. Python already installed and then take an image - use that image to bootstrap
  2. You enable User-Data and pass the user-data commands during the launch time
6
  • "aws ec2 run-instances --image-id ami-XXXXX --count 1 --instance-type t2.micro --key-name PPPPPPP --security-group-ids LLLLL --subnet-id KKKKKK --user-data file://script.py" works on linux but not on windows any idea about it??
    – pkm
    Commented Aug 11, 2015 at 10:37
  • where did u place the script.py - which location ? Or trying giving the full path [ absolute path of the script.py ] Commented Aug 11, 2015 at 10:41
  • I have a doubt that if the AMI is enabled with User Data - can launch a plain ec2 instance and enable the user data and then take the ami and try using that AMI ? Commented Aug 11, 2015 at 10:50
  • enabling user-data is only for windows ? how do we enable it ?
    – pkm
    Commented Aug 11, 2015 at 10:56
  • check this out - docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/… Commented Aug 11, 2015 at 10:57
1

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

the document from aws say that only shell and cloud-init directive that are supported

3
  • I believe userData is handled by cloud-init. Commented May 8, 2017 at 7:11
  • 12
    My case, I forgot start with "#!/bin/bash"
    – rmsys
    Commented Jul 17, 2019 at 21:37
  • Like @rmsys, in my case, I missed the '#' character on the shebang.
    – M. Gleria
    Commented Sep 22, 2020 at 14:56
0
Unhandled non-multipart (text/x-not-multipart) userdata: 'b'IyE

If you encounter this error in AL 2023, you might be double encoding the user data in base64. This was the case for me. See https://github.com/amazonlinux/amazon-linux-2023/issues/401

Boto docs also warn that you don't have to encode the user data

This value will be base64 encoded automatically. Do not base64 encode this value prior to performing the operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.