我使用Terraform脚本创建aws弹性beanstalk环境,我需要在实例启动时启动shell脚本
我已经尝试了以下
resource "aws_elastic_beanstalk_environment" "Environment" {
name = "${var.ebs_env_name}"
application = "${var.ebs_app_name}"
---
---
---
setting = {
namespace = "aws:autoscaling:launchconfiguration"
name = "user_data"
value = "${file("user-data.sh")}"
}
}
这是抛出错误
应用计划时出错:
发生1个错误:
aws_elastic_beanstalk_environment.Environment:ConfigurationValidationException:配置验证异常:无效的选项规范(命名空间:' aws:autoscaling:launchconfiguration',OptionName:' user_data'):未知的配置设置。 状态代码:400,请求ID:xxxxx-xxxxxx
请帮助
答案 0 :(得分:3)
我无法在AWS Elastic Beanstalk服务上找到任何有关修改实例user_data
的方法的信息。但是,您可以调整使用的AMI,因此您可以使用Packer之类的工具为自己构建一个自定义AMI,其中包含user_data
。
答案 1 :(得分:3)
感谢您的回答,我提供了一个解决方案
我创建了一个.ebextensions文件夹,并在名为99delayed_job.config的文件夹中创建了一个文件(你可以给出任何名字)
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/pre"
ignoreErrors: true
files:
/opt/elasticbeanstalk/hooks/appdeploy/pre/99_restart_delayed_job.sh:
group: root
mode: "000755"
owner: root
content: |-
#!/usr/bin/env bash
<My shell script here>
A并使用&#39; Dockerrun.aws.json&#39;这个zip我发送到s3并用于部署
工作正常:)