How to transfer user data when starting AWS instances using the CLI

I use AWS CLI to run instances, and the command: aws ec2 run instances

what i expect is to pass in the script as user data. so I did: DATA = base64 ./my_script on my Mac OSX, and then pass DATA: aws ec2 run instances - user data $ DATA

BUT, nothing happened after starting the instance

So how should I do this?

Thanks!!

+7
command-line-interface amazon-web-services
source share
2 answers

There is no need for base64 to encode data on its own.

You can prefix the file name / path with the file: //

So,

 aws ec2 run-instances --user-data file://my_script 

or

 aws ec2 run-instances --user-data file:///full/path/to/my_script 
+15
source share

To pass a script as a string, be sure to specify the interpreter as usual before your commands. Entering an open line allows you to add a new line. Example:.

 $ aws ec2 run-instances --image-id ami-16d4986e --user-data '#!/bin/bash > poweroff' 
+2
source share

All Articles