I can able to create an instace with follwoing command
aws ec2 run-instances --image-id $AMI_ID --count 1 --instance-type ${INSTANCE_TYPE} --key-name KEY_NAME --region us-east-1 --security-groups MYSECURITY_GROUP
But I did not find any option to attach elastic IP address to it. Is it possible to attach a Elastic IP during bootstrapping? Or post bootstrapping?
To associate an Elastic IP address with an instance Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Elastic IPs. Select an Elastic IP address and choose Actions, Associate address. Select the instance from Instance and then choose Associate.
Choose Instances, and then select the instance that you're trying to connect to. On the Networking tab, select the elastic network interface that has the attached Elastic IP address. Then, select the elastic network interface ID. On the Details tab, select the associated Subnet ID.
To tag an Elastic IP address Open the Amazon VPC console at https://console.aws.amazon.com/vpc/ . In the navigation pane, choose Elastic IPs. Select the Elastic IP address and choose Tags. Choose Manage tags, enter the tag keys and values as required, and choose Save.
You can use --user-data (string)
option to run-instances
. The user data that you pass will contain the CLI to associate the elastic IP. The CLI command is given below. To get the instance-id
in user data, use the metadata server:
curl instance-data/latest/meta-data/instance-id
You can also attach an elastic IP after you launch. Use associate-address
to attach an elastic IP.
More examples in: associate-address
This example uses the new style (longer) instance id.
aws ec2 associate-address --instance-id i-0b263919b6498b123 --allocation-id eipalloc-64d5890a
You can get the allocation id from
aws ec2 describe-addresses
describe-addresses
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