目前,我尝试简单地启动一个 ec2 实例,以在当前云形成启动的 tmp 文件夹中显示 myfile2.txt。但没有文件。我尝试在命令行中解决问题并检查日志,但我不明白问题是什么。我在 AWS::CloudFormation::Init: 方面遇到了麻烦有一段时间了,想知道是否有人有任何建议? ?
这只是一个简单的练习,是一个更大项目的一部分。
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
InstanceTypeParameter:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- m1.small
- m1.large
Description: Enter t2.micro, m1.small, or m1.large. Default is t2.micro.
KeyName:
Description: key pair name
Type: AWS::EC2::KeyPair::KeyName
Resources:
WebInstance:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Init:
config:
files:
'/tmp/myfile2.txt':
content: "Hello sir"
mode: '000755'
owner: root
group: root
Properties:
InstanceType:
Ref: InstanceTypeParameter
ImageId: ami-04b762b4289fba92b
SecurityGroupIds:
- sg-0394c353eef246c71
SubnetId: subnet-476a773e
Tags:
-
Key: Name
Value: Trovo-webserver
KeyName:
Ref: KeyName
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
最佳答案
尚不清楚您是否正在运行 cfn-init 命令。理想情况下,您的 userdata 部分将有一个命令 cfn-init ,该命令反过来会调用 Init 键下定义的配置集。请检查下面的示例片段。
UserData: !Base64
'Fn::Join':
- ''
- - |
#!/bin/bash -xe
- |
# Install the files and packages from the metadata
- '/opt/aws/bin/cfn-init -v '
- ' --stack '
- !Ref 'AWS::StackName'
- ' --resource WebServerInstance '
- ' --configsets InstallAndRun '
- ' --region '
- !Ref 'AWS::Region'
- |+
关于amazon-web-services - 我试图在 cloudformation 中获取一个文件以在 ec2 实例中生成,但似乎无法在 ec2 实例上看到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58086116/