简体   繁体   English

使用提供的参数将资源命名为云形成堆栈

[英]Name the resources with the supplied parameters to cloud formation stack

Im new to cloudformation and intrinsc function.我是 cloudformation 和 intrinsc 函数的新手。 I am trying to run a stack with the template which accepts ent type as parameter Using this parameter I would like to name my s3 bucket.我正在尝试使用接受 ent 类型作为参数的模板运行堆栈使用此参数我想命名我的 s3 存储桶。

But Im getting 400 Bad request但是我收到了 400 个错误的请求

My template { "AWSTemplateFormatVersion": "2010-09-09", "Description": "Creates an S3 bucket using parameters supplied.", "Parameters": {我的模板 { "AWSTemplateFormatVersion": "2010-09-09", "Description": "使用提供的参数创建 S3 存储桶。", "Parameters": {

    "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"
    }
}

} }

Using the AWS CLI - for passing dynamic parameters使用 AWS CLI - 用于传递动态参数

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

From here 从这里

Also !Sub is the syntax for the short form of Fn::Sub: - used in template YAML另外!SubFn::Sub:的短格式的语法Fn::Sub: - 在模板 YAML 中使用

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

Fn::Sub Fn::Sub

Change改变

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

To

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

Example例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM