【问题标题】:Name the resources with the supplied parameters to cloud formation stack使用提供的参数将资源命名为云形成堆栈
【发布时间】:2020-03-27 20:06:58
【问题描述】:

我是 cloudformation 和内在函数的新手。 我正在尝试使用接受 ent 类型作为参数的模板运行堆栈 使用此参数,我想命名我的 s3 存储桶。

但我收到 400 错误请求

我的模板 { "AWSTemplateFormatVersion": "2010-09-09", "Description": "使用提供的参数创建一个 S3 存储桶。", “参数”:{

    "AssetInsightId": {
        "Description": "Asset Insight ID",
        "Type": "String",
        "Default": "###"
    },
    "ResourceOwner": {
        "Description": "tr:resource-owner",
        "Type": "String",
        "Default": "###"
    },
    "EnvironmentType": {
        "Description": "tr:environment-type",

         "Default": "PREPROD",
        "Type": "String",
        "AllowedValues": ["PREPROD", "PROD"],
        "ConstraintDescription": "must specify PREPROD, PROD."
    }
},
"Resources": {
    "ResourceBucket": {
        "Type": "AWS::S3::Bucket",
        "Properties": {
            "BucketName": "!Sub a${AssetInsightId}-S3Bucket-${EnvironmentType}",
            "VersioningConfiguration": {
                "Status": "Enabled"
            },
            "Tags": [

                {
                    "Key": "tr:application-asset-insight-id",
                    "Value": "${AssetInsightId}"
                },
                {
                    "Key": "tr:resource-owner",
                    "Value": "${ResourceOwner}"
                },
                {
                    "Key": "tr:environment-type",
                    "Value": "${EnvironmentType}"
                }
            ]
        }
    }
},
"Outputs": {
    "BucketName": {
        "Description": "Name of the S3 Resource Bucket",
        "Value": "!Ref ResourceBucket"
    }
}

}

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-cloudformation


    【解决方案1】:

    使用 AWS CLI - 传递动态参数

    aws cloudformation create-stack  --stack-name my-stack
    --template-body template.json 
    --parameters  ParameterKey=EnvironmentType,ParameterValue=Development
    

    From here

    !Sub 也是 Fn::Sub: 的缩写形式的语法 - 用于模板 YAML

    { "Fn::Sub" : String } - 在模板 JSON 中使用

    Fn::Sub

    改变

    "BucketName": "!Sub a${AssetInsightId}-S3Bucket-${EnvironmentType}",
    

    "BucketName": { "Fn::Sub": "a${AssetInsightId}-S3Bucket-${EnvironmentType}"},
    

    Example

    【讨论】:

    • @Swathi 如果我的回答解决了您的问题,请随时投票和/或接受答案。谢谢
    猜你喜欢
    • 2021-12-18
    • 2015-02-15
    • 1970-01-01
    • 2017-01-31
    • 2018-06-21
    • 2020-06-18
    • 1970-01-01
    • 2021-04-07
    • 2016-03-10
    相关资源
    最近更新 更多