【问题标题】:cfn-init specify custom jsoncfn-init 指定自定义 json
【发布时间】:2017-11-03 00:43:15
【问题描述】:

有没有办法告诉 cfn-init 使用从磁盘加载的自定义 JSON 文件?这样我可以快速解决问题,否则更改AWS::CloudFormation::Init 部分的唯一方法是删除堆栈并重新创建它。

我宁愿只对我的template.json 进行更改,然后告诉cfn-init -f C:\template.json ... 之类的内容,以便它使用C:\template.json 而不是从169.254.169.254 获取模板,或者不管它获取它。

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    原来 cfn-init 确实接受一个文件,但该文件需要有 "Metadata" 键作为根键。

    所以如果我们把它保存到template.json:

    {
        "AWS::CloudFormation::Init": {
            "config": {
                "files": {
                    "C:\\Users\\Administrator\\Desktop\\test-file": {
                        "source": "https://s3.us-east-2.amazonaws.com/example-bucket/example-file"
                    }
                }
            }
        },
        "AWS::CloudFormation::Authentication": {
            "S3AccessCreds": {
                "type": "S3",
                "buckets": ["example-bucket"],
                "roleName": "s3access"
            }
        }
    }
    

    然后我们可以执行cfn-init -v --region us-east-2 template.json

    注意:不要包含堆栈或资源,如果你使用cfn-init -v -s my_stack -r my_instance --region us-east-2 template.json你会得到:

    错误:您不能为元数据指定多个输入源

    如果你把整个模板文件而不只是“元数据”作为根,你会得到:

    在 template.json 中找不到 'AWS::CloudFormation::Init' 键

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 2012-12-16
      • 2017-04-04
      • 2019-06-13
      • 2017-04-30
      • 1970-01-01
      相关资源
      最近更新 更多