gpt4 book ai didi

amazon-web-services - CloudFormation 模板无法在元数据部分下创建 "files"

转载 作者:行者123 更新时间:2023-12-03 07:32:39 25 4
gpt4 key购买 nike

有人可以帮我指出我在这里做错了什么吗?我无法理解元数据部分如何使用身份验证资源,在 AWS::CloudFormation::Authentication 部分中,我提到了与附加到实例的角色相同的角色,但我无法创建文件“一些.txt”

{

"Parameters": {

"SecurityGroupId": {
"Description": "Security group for instance",
"Type": "AWS::EC2::SecurityGroup::Id"
}

},


"Resources": {
"MyInstance": {
"Type": "AWS::EC2::Instance",
"Metadata": {
"AWS::CloudFormation::Init": {
"configsets": {
"InstallIt": ["config1"]
},

"config1": {
"files": {
"/home/ec2-user/some.txt": {
"content": "This is my name ",
"encoding": "base64",
"mode": "000644",
"owner": "root",
"group": "root"
}
}
}
},

"AWS::CloudFormation::Authentication": {
"HelpMe": {
"type": "S3",
"buckets": "poc-bucket",
"roleName": "EC2andS3"
}

}
},
"Properties": {
"KeyName": "GoldenImage-NV-Anant",
"DisableApiTermination": "false",
"ImageId": "ami-0b33d91d",
"InstanceType": "t2.micro",
"Monitoring": "false",
"SubnetId": "subnet-73487a59",
"SecurityGroupIds": [{
"Ref": "SecurityGroupId"
}],
"IamInstanceProfile": {
"Ref": "MyInstanceProfile"
},
"Tags": [{
"Key": "Name",
"Value": "GeicoUserDataPocInstance"
}],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"", [
"#!/bin/bash -ex \n",
"echo \"hello dudes\" > /home/ec2-user/hello.txt \n",
"yum update -y aws-cfn-bootstrap\n",
"/opt/aws/bin/cfn-init -v",
" --stack ", {
"Ref": "AWS::StackId"
},
" --resource MyInstance ",
" --configsets InstallIt ",
" --region ", {
"Ref": "AWS::Region"
}, "\n",
"echo \"bye dudes\" > /home/ec2-user/bye.txt", "\n",


"/opt/aws/bin/cfn-signal -e $? ",
" --stack ", {
"Ref": "AWS::StackId"
},
" --resource MyInstance ",
" --region ", {
"Ref": "AWS::Region"
}, "\n"
]
]
}
}
},

"CreationPolicy": {
"ResourceSignal": {
"Timeout": "PT90M",
"Count": "1"
}
}
},

"MyInstanceProfile": {
"Description": "Instance profile for the instance",
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Path": "/",
"Roles": ["EC2andS3"]
}
}
}
}

最佳答案

  • configsets 应该是 configSets大写S:

    "configSets": {
    "InstallIt": ["config1"]
    },
  • buckets属性需要是字符串列表(这可能不是必需的,文档有点不清楚):

    "buckets": ["poc-bucket"]
  • AWS::CloudFormation::Authentication除非文件源是 S3 存储桶,否则资源不是必需的。即使如此,在使用附加的实例配置文件时仍然没有必要,因为默认情况下它将使用实例配置文件进行身份验证。

关于amazon-web-services - CloudFormation 模板无法在元数据部分下创建 "files",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42452874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com