我正在Elastic Beanstalk上部署一个应用程序,我需要修改AWSEBAutoScalingLaunchConfiguration中的UserData,该数据通常由Elastic Beanstalk生成。我需要执行此操作以运行cfn-signal脚本,以便在更新环境时,AWSBAutoScalingGroup会收到成功信号,并且不会回滚。但是,当我进行这些更改时,我的实例从不发送任何运行状况数据,因此我的Elastic Beanstalk运行状况保持为“严重”。当我访问端点时,该应用程序仍然可以运行,因此实例很好,我认为运行状况守护程序由于某种原因而无法运行。
我已经尝试在.ebextensions命令中运行cfn-signal命令,但是我相信这会引入一些循环依赖关系,我已经描述了here(但现在还没有弄清楚)。因此,我知道解决此问题的唯一方法是通过在UserData中运行命令,但是我担心自己所做的修改导致健康数据无法发送。
这是.ebextensions文件的内容,该文件设置了UserData以及ELB运行状况检查所需的其他配置。
Resources:
AWSEBAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
HealthCheckType: ELB
HealthCheckGracePeriod: 300
CreationPolicy:
ResourceSignal:
Timeout: PT5M
AWSEBAutoScalingLaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
UserData:
"Fn::Base64":
"Fn::Join":
- ""
- - |-
Content-Type: multipart/mixed; boundary="===============5189065377222898407=="
MIME-Version: 1.0
--===============5189065377222898407==
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
repo_upgrade: none
repo_releasever: 2018.03
cloud_final_modules:
- [scripts-user, always]
--===============5189065377222898407==
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="user-data.txt"
#!/bin/bash
exec > >(tee -a /var/log/eb-cfn-init.log|logger -t [eb-cfn-init] -s 2>/dev/console) 2>&1
echo [`date -u +"%Y-%m-%dT%H:%M:%SZ"`] Started EB User Data
set -x
# This signals the auto scaling group that the instance launched successfully
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-signal -e $? --stack
- ' '
- Ref: AWS::StackName
- ' '
- --resource AWSEBAutoScalingGroup --region
- ' '
- Ref: AWS::Region
- |-
function sleep_delay
{
if (( $SLEEP_TIME < $SLEEP_TIME_MAX )); then
echo Sleeping $SLEEP_TIME
sleep $SLEEP_TIME
SLEEP_TIME=$(($SLEEP_TIME * 2))
else
echo Sleeping $SLEEP_TIME_MAX
sleep $SLEEP_TIME_MAX
fi
}
# Executing bootstrap script
SLEEP_TIME=10
SLEEP_TIME_MAX=3600
while true; do
curl https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_tomcat_4.0.1.200636.0/lib/UserDataScript.sh > /tmp/ebbootstrap.sh
RESULT=$?
if [[ "$RESULT" -ne 0 ]]; then
sleep_delay
else
/bin/bash /tmp/ebbootstrap.sh 'https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_tomcat_4.0.1.200636.0/lib/aws-elasticbeanstalk-tools-1.20-1.noarch.rpm' 'https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_tomcat_4.0.1.200636.0/lib/awseb-ruby-2.2.4-x86_64-20160503_1008.tar.gz https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_tomcat_4.0.1.200636.0/lib/basehooks.tar.gz' 'https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_tomcat_4.0.1.200636.0/lib/beanstalk-core-2.12.gem https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_tomcat_4.0.1.200636.0/lib/beanstalk-core-healthd-1.1.gem https://s3.dualstack.us-west-2.amazonaws.com/elasticbeanstalk-env-resources-us-west-2/stalks/eb_tomcat_4.0.1.200636.0/lib/executor-1.2.gem' '
- Ref: AWSEBInstanceLaunchWaitHandle
- |-
' '
- Ref: AWS::StackId
- |-
' '
- Ref: AWS::Region
- |
' 'e2232d72b415' '1eb8fb9e-3237-488f-a962-facde7d5f717' '' 'apache' '' &&
exit 0
fi
done
--===============5189065377222898407==--
##Ec2InstanceReplacementRequest=63186836-db61-4b9d-baad-ba1ae88cc300
在进行这些更改之前,从同一Elastic Beanstalk应用程序的启动配置中复制了cfn-signal部分之外的所有内容。我的目标是通过运行cfn-signal命令来保留相同的行为。话虽这么说,但那里有一些随机的ID,我不知道它们指的是什么。如果我删除了大部分文件,就像这样
Resources:
AWSEBAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
HealthCheckType: ELB
HealthCheckGracePeriod: 300
然后,应用程序创建并且实例运行状况正常,但是,当我部署新更改时,没有成功信号发送到该资源,因此部署失败。
可以按照我的描述去做吗?修改UserData似乎过于复杂,而且我担心会因此而遇到其他一些问题。任何有关如何解决此问题或替代方法的建议都将受到赞赏。