Skip to content

Instantly share code, notes, and snippets.

@pofider
Created September 10, 2015 15:14
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pofider/17a096358e4fe34ca39f to your computer and use it in GitHub Desktop.
Save pofider/17a096358e4fe34ca39f to your computer and use it in GitHub Desktop.
Attach EBS volume to amazon elastic beanstalk
# .ebextensions/01-ebs.config
commands:
01clear-if-unmounted:
command: if ! mount | grep /media/ebs_volume > /dev/nul; then rm -rf /media/ebs_volume; fi
02attach-volume:
command: aws ec2 attach-volume --region eu-central-1 --volume-id vol-ddb08e34 --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdh
ignoreErrors: true
03wait:
command: sleep 10
04trymount:
command: |
mkdir /media/ebs_volume
mount /dev/sdh /media/ebs_volume
ignoreErrors: true
05format-if-not-already:
command: if find /media/ebs_volume/ -maxdepth 0 -empty | read v; then mkfs -t ext3 /dev/sdh; fi
06mount-volume:
command: |
mkdir /media/ebs_volume
mount /dev/sdh /media/ebs_volume
@ratnesh-gupta
Copy link

Hi Jan,
Thanks for sharing this script.
I am new to AWS elastic Beanstalk.
Currently I am trying elastic beanstalk for one of my product.
I have followed below steps :

  1. i have created a volume in the same AZ in which i am having Elastic Beanstalk Application.
  2. i have created the .ebextension folder under my root folder
  3. i have added you script in the .ebextesnion folder after replacing the " vol-ddb08e34" and "eu-central-1", with my values.

When i upload the zip for testing i am getting below error :

Output: mount: wrong fs type, bad option, bad superblock on /dev/xvdh, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so. container_command 06_mount in .ebextensions/01-ebs.config failed.

Can you please help me on this

@pofider
Copy link
Author

pofider commented Jul 10, 2019

Sorry, it is a long time since I was testing this script. You can rather try a question on stackoverflow.

@ratnesh-gupta
Copy link

No issues, Jan
Thanks for quick reply .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment