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!!
Create Launch Configuration wizard will open. Select the required AMI. In the next window, select the Instance Type and click "Next: Configure details". Under "Configure details" -> "Advanced Details" -> Enter your USERDATA in the "User data" text box.
When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2: shell scripts and cloud-init directives.
Launch your instance To launch an Amazon EC2 instance using the AMI you selected, use the aws ec2 run-instances command.
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'
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With