将EBS卷(不是快照)挂载到Elastic Beanstalk EC2 [英] Mount a EBS volume (not snapshot) to Elastic Beanstalk EC2
问题描述
我正在将旧版应用程序迁移到Elastic Beanstalk.它需要持久存储(暂时).我想挂载一个EBS卷.
I'm migrating a legacy app to Elastic Beanstalk. It needs persistent storage (for the time being). I want to mount a EBS volume.
我希望以下代码可以在 .ebextensions/ebs.config
中使用:
I was hoping the following would work in .ebextensions/ebs.config
:
commands:
01mkdir:
command: "mkdir /data"
02mount:
command: "mount /dev/sdh /data"
option_settings:
- namespace: aws:autoscaling:launchconfiguration
option_name: BlockDeviceMappings
value: /dev/sdh=vol-XXXXX
但是不幸的是,我收到以下错误消息:参数snapshotId的(vol-XXXX)无效.应为:'snap -...'."
But unfortunately I get the following error "(vol-XXXX) for parameter snapshotId is invalid. Expected: 'snap-...'."
很明显,此方法仅允许快照.任何人都可以提出修复或替代方法的建议.
Clearly this method only allows snapshots. Can anyone suggest a fix or an alternative method.
推荐答案
我找到了一个解决方案.可以通过删除"sleep 10"来改善它,但是不幸的是,由于 aws ec2 attach-volume
是异步的,并且在进行连接之前立即返回,因此需要这样做.
I have found a solution. It could be improved by removing the "sleep 10" but unfortunately that required because aws ec2 attach-volume
is async and returns straight away before the attachment takes place.
container_commands:
01mount:
command: "aws ec2 attach-volume --volume-id vol-XXXXXX --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdh"
ignoreErrors: true
02wait:
command: "sleep 10"
03mkdir:
command: "mkdir /data"
test: "[ ! -d /data ]"
04mount:
command: "mount /dev/sdh /data"
test: "! mountpoint -q /dev/sdh"
注意.理想情况下,它将在 commands
部分而不是 container_commands
中运行,但是环境变量未及时设置.
Note. Ideally it would be run in commands
section not container_commands
but the environment variables are not set in time.
这篇关于将EBS卷(不是快照)挂载到Elastic Beanstalk EC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!