TransWikia.com

User Data in launch configuration of amazon web services

DevOps Asked by Ufomammut on August 22, 2021

I was trying to create an EBS volume by writing a shell script in the user data of my launch configuration. I don’t think there is anything wrong with my bash script. I kept looking up creating launch configuration and writing user data in AWS websites, but could not find anything more than what I did below. For my launch configuration, I used Amazon Linux 2 AMI which has pre-built AWS CLI. So I just wrote the following code in my user data:

    #!/bin/bash
    aws ec2 create-volume 
        --volume-type gp2 
        --size 100 
        --encrypted 
        --availability-zone us-east-1c
    
    aws ec2 create-volume 
        --volume-type gp2 
        --size 100 
        --encrypted 
        --availability-zone us-east-1d

As you can see I am trying to create EBS volumes in two availability zones, but I just could not find out why it does not create any volume for me?

One Answer

  1. Make sure the EC2 instance has permissions to create the volumes. See https://aws.nz/best-practice/ec2-instance-roles/

  2. Check for the errors in /var/log/cloud-init-output.log and (much more verbose) /var/log/cloud-init.log

  3. Be aware that you can't attach volumes from other AZs to your EC2, so not quite sure why you would want to create them from the launch script.

  4. (added based on comments) Specify region: aws --region us-east-1 ec2 create-volume ...

Hope that helps :)

Correct answer by MLu on August 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP