- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个cloudformation堆栈,它创建一个EC2实例并使用UserData在其中安装一些东西。创建基于 RedHat 的 EC2 实例后,Cloudformation 立即报告 CREATE_COMPLETE。但此时,该实例还不能真正使用,因为用户数据需要大约 40 分钟才能完成。我阅读了文档,甚至尝试了 cfn-signal 但无法成功执行它。
有人可以告诉我具体该怎么做吗?
EC2Instance:
Type: AWS::EC2::Instance
Properties:
CreditSpecification:
CPUCredits: standard
IamInstanceProfile:
Fn::ImportValue:
!Sub ${InstanceProfileStackName}-instanceProfile
ImageId: !Ref ImageId
InstanceInitiatedShutdownBehavior: stop
InstanceType: !Ref InstanceType
SubnetId: !Ref SubnetId
SecurityGroupIds:
- !Ref DefaultSecurityGroup
- !Ref WebSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash
set -e
yum update -y
以上是我的 Cloudformation 模板的截断部分。
更新
我的脚本包含以下行
source scl_source enable rh-python36
我的实例的默认值是 python2.7,但我必须使用 python3.6 安装我的 pip 包。我不确定这是否导致 cfn 信号失败。
脚本一直进行到最后一步,但似乎在那里失败了。我正在从 EC2 IP 创建记录集,但 Cloudformation 仍然认为 EC2 实例尚未完成并等待超时。
我的日志文件名为/var/log/cloud-init.log。该目录中没有 cloud-init-output.log。
最佳答案
您需要两个组件:
CreationPolicy以便 CFN 等待来自实例的 SUCCESS 信号。
cfn-signal用于执行信号操作的辅助脚本。
因此,您的模板可以针对 Redhat 8 进行如下修改:
EC2Instance:
Type: AWS::EC2::Instance
CreationPolicy: # <--- creation policy with timeout of 5 minutes
ResourceSignal:
Timeout: PT5M
Properties:
CreditSpecification:
CPUCredits: standard
IamInstanceProfile:
Fn::ImportValue:
!Sub ${InstanceProfileStackName}-instanceProfile
ImageId: !Ref ImageId
InstanceInitiatedShutdownBehavior: stop
InstanceType: !Ref InstanceType
SubnetId: !Ref SubnetId
SecurityGroupIds:
- !Ref DefaultSecurityGroup
- !Ref WebSecurityGroup
UserData:
Fn::Base64: !Sub |
#!/bin/bash -x
yum update -y
yum -y install python2-pip
pip2 install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz
python2 /usr/bin/cfn-signal -e $? \
--stack ${AWS::StackName} \
--resource EC2Instance \
--region ${AWS::Region}
对于调试,由于用户数据可能会出错,必须登录实例并检查/var/log/cloud-init-output.log
文件
关于bash - 让 CloudFormation 等待用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61740024/
This question already has answers here: Using Variable for Thread group Ramp up time (3个答案) 3年前关闭。 从
我希望使用 RPyC 为硬件板提供 API 作为服务。该板一次只能满足一个用户的需求。有什么方法可以让 RPyC 强制执行一次只有一个用户可以访问吗? 最佳答案 我不确定这是否有效(或有效),但您可以
如果我想以每秒 10 个请求运行测试。如何让 Jmeter 选择每秒处理该请求数所需的最佳线程数。 我将线程数设置为与每秒请求数相同。 最佳答案 您可以使用恒定吞吐量计时器 click here你只需
我正在尝试进行查询以检查客户表并返回过去 30 天、过去 365 天和所有时间具有特定值的用户数。 所有时间的计数很简单: $stmt = $conn->prepare("SELECT count(i
我是一名优秀的程序员,十分优秀!