Answers: <ol>
  <li><p>Make sure the EC2 instance has permissions to create the volumes. See <a href="https://aws.nz/best-practice/ec2-instance-roles/" rel="nofollow noreferrer">https://aws.nz/best-practice/ec2-instance-roles/</a></p></li>
  <li><p>Check for the errors in <code>/var/log/cloud-init-output.log</code> and (much more verbose) <code>/var/log/cloud-init.log</code></p></li>
  <li><p>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.</p></li>
  <li><p><em>(added based on comments)</em> Specify region: <code>aws --region us-east-1 ec2 create-volume ...</code></p></li>
  </ol>
  
  <p>Hope that helps :)</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-01-09T23:35:52.703Z
Answers: 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.
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-09T23:37:40.717Z
Answers: About the permission, I have given the administrator access to the IAM role that I have created for the user.
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-09T23:38:38.777Z
Answers: 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.
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-09T23:39:38.010Z
Answers: @Ufomammut are there any issues reported in `cloud-init-output.log`? Are the commands actually run? Do you see the calls in CloudTrail?
Answers: MLu
Answers: CC BY-SA 4.0
Answers: 2020-01-09T23:51:52.380Z
Answers: Hey I am new to aws and I don't know where to look for tthis cloud-init-output.log?
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-09T23:53:09.253Z
Answers: It’s in my answer - `/var/log/cloud-init-output.log`
Answers: MLu
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:00:09.567Z
Answers: You must specify a region. You can also configure your region by running "aws configure".
  You must specify a region. You can also configure your region by running "aws configure".
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:00:27.370Z
Answers: Jan 09 23:45:05 cloud-init[3388]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [255]
  Jan 09 23:45:05 cloud-init[3388]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
  Jan 09 23:45:05 cloud-init[3388]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
  Cloud-init v. 18.5-2.amzn2 finished at Thu, 09 Jan 2020 23:45:05 +0000. Datasource DataSourceEc2.  Up 17.85 seconds
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:01:27.237Z
Answers: Hey this is what I found in my cloud-init-output.log
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:02:21.740Z
Answers: @Ufomammut See, pretty self-explanatory. Simply use `aws --region us-east-1 ec2 create-volume ...`
Answers: MLu
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:06:16.067Z
Answers: Updated the answer. If it works please upvote and accept it.
Answers: MLu
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:06:23.163Z
Answers: Let me see but I think I tried putting only us-east-1. Let me try it again.
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:30:19.623Z
Answers: Finally it works
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-10T00:38:58.007Z
Answers: Good to hear that :)
Answers: MLu
Answers: CC BY-SA 4.0
Answers: 2020-01-11T14:05:54.813Z
Answers: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/103174/discussion-between-ufomammut-and-mlu).
Answers: Four Seasons
Answers: CC BY-SA 4.0
Answers: 2020-01-09T23:33:09.777Z
Answers: 2020-01-10T00:05:36.297Z
Answers: 2020-01-10T00:05:36.297Z
Answers: MLu
Body: <p>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:</p>
  <pre><code>    #!/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
  </code></pre>
  <p>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?</p>
  
Tags: <amazon-web-services>
Title: User Data in launch configuration of amazon web services
UserDisplayName: Four Seasons
ThreadText: # User Data in launch configuration of amazon web services
  
  (Asked by: username_0 on 2020-01-09)
  
  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?
  
  **Tags:** amazon-web-services
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-01-09. Score: 2 | Accepted 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 :)
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_0**: About the permission, I have given the administrator access to the IAM role that I have created for the user.  
  > **username_0**: 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.  
  > **username_1**: @Ufomammut are there any issues reported in `cloud-init-output.log`? Are the commands actually run? Do you see the calls in CloudTrail?  
  > **username_0**: Hey I am new to aws and I don't know where to look for tthis cloud-init-output.log?  
  > **username_1**: It’s in my answer - `/var/log/cloud-init-output.log`  
  > **username_0**: You must specify a region. You can also configure your region by running "aws configure". You must specify a region. You can also configure your region by running "aws configure".  
  > **username_0**: Jan 09 23:45:05 cloud-init[3388]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [255] Jan 09 23:45:05 cloud-init[3388]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts) Jan 09 23:45:05 cloud-init[3388]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed Cloud-init v. 18.5-2.amzn2 finished at Thu, 09 Jan 2020 23:45:05 +0000. Datasource DataSourceEc2.  Up 17.85 seconds  
  > **username_0**: Hey this is what I found in my cloud-init-output.log  
  > **username_1**: @Ufomammut See, pretty self-explanatory. Simply use `aws --region us-east-1 ec2 create-volume ...`  
  > **username_1**: Updated the answer. If it works please upvote and accept it.  
  > **username_0**: Let me see but I think I tried putting only us-east-1. Let me try it again.  
  > **username_0**: Finally it works  
  > **username_1**: Good to hear that :)  
  > **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/103174/discussion-between-ufomammut-and-mlu).  
  
  ---
  
  