【发布时间】:2020-05-29 17:50:41
【问题描述】:
我正在尝试让一个简单的 AWS Cloudformation cfn-init 脚本工作,但没有任何成功。脚本如下所示。当我登录到创建的实例时,甚至没有安装 httpd。我正在 us-east-1 中创建一个 AWS Linux2 实例。
Resources:
...
Ec2Instance:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
config:
packages:
yum:
httpd: []
files:
/var/www/html/index.html:
content: !Sub |
<html><body>Hello, World</body></html>
services:
sysvinit:
httpd:
enabled: true
ensureRunning: true
Properties:
InstanceType: t2.micro
ImageId: ami-0323c3dd2da7fb37d
KeyName: KeyPair
SecurityGroupIds:
- !Ref InstanceSecurityGroup
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource Ec2Instance --region ${AWS::Region}
【问题讨论】:
-
您是否有可能首先创建实例,然后将 cfn-init 配置/UserData 作为更新添加到已运行的实例?
标签: amazon-web-services yaml amazon-cloudformation