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:

    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?

  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 :)

| improve this answer | |
  • We can attach volumes from launch script but creating volumes I am not so sure. I am not sure why it's not being created at all, the volume with the region and availability zones that I have mentioned. My mentor has let me know that this kind of problem falls under the infrastructure management. – Ufomammut Jan 9 at 23:35
  • About the permission, I have given the administrator access to the IAM role that I have created for the user. – Ufomammut Jan 9 at 23:37
  • About the second point, where can I find the var/log/cloud-init-output.log. Also what do you mean by we cannot attach volumes from other availability zones. The ec2 instance that I have created and the availability zones that I have set for the volume are same. Right now I just want to create two volumes based on availability zones. – Ufomammut Jan 9 at 23:38
  • @Ufomammut are there any issues reported in cloud-init-output.log? Are the commands actually run? Do you see the calls in CloudTrail? – MLu Jan 9 at 23:39
  • 1
    Updated the answer. If it works please upvote and accept it. – MLu Jan 10 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.