Edward
Edward

Reputation: 157

how to pass in the user-data when launching AWS instances using CLI

I'm using the AWS CLI to launch instances, and the command is: aws ec2 run-instances

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

BUT, nothing happened after the instance launched

So, how exactly should I do?

Thanks!!

Upvotes: 10

Views: 9038

Answers (2)

Eric Hammond
Eric Hammond

Reputation: 22417

There is no need to base64 encode the data yourself.

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

So,

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

or

aws ec2 run-instances --user-data file:///full/path/to/my_script

Upvotes: 20

AXE Labs
AXE Labs

Reputation: 4541

To pass the script as a string, make sure to specify the interpreter as normal prior to your commands. Hitting enter in the open string allows for adding a new line. Ex.:

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

Upvotes: 6

Related Questions