AWS Cloudformation-如何在json / yaml模板中执行字符串大写或小写 [英] AWS Cloudformation- How to do string Uppercase or lowercase in json/yaml template

本文介绍了AWS Cloudformation-如何在json / yaml模板中执行字符串大写或小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究AWS CloudFormation,并创建了一个模板,要求用户选择环境。

I am working on AWS CloudFormation and I created one template in which I asked user to select Environment.

在选择值的基础上,我创建了资源。用户必须在DEV,QA,PROD,UAT等之间进行选择,但是当我将此值后缀添加到S3存储桶名称(-downloads.com)时,由于在S3存储桶名称中不允许使用大写字母,因此不允许这样做。

On the basis of selected value I created the resources. User have to select between DEV, QA, PROD, UAT etc. but when I suffix this value to S3 bucket name (-downloads.com) it not allowed because capital letter is not allowed in S3 bucket name.

所以我确实在JSON中进行了更改,在 fn :: Transform Condition: Lower
中使用

So I did change in JSON where I use fn::Transform with "Condition":"Lower" but then while creating resources below error occurs.


未找到名为871247504605 :: String的转换。.用户请求回滚。

No transform named 871247504605::String found.. Rollback requested by user.

以下是我的CloudFormation JSON

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Provides nesting for required stacks to deploy a full resource of ****",
    "Metadata": {
        "AWS::CloudFormation::Interface": {
            "ParameterGroups": [
                {
                    "Label": {
                        "default": "Enviroment Selection"
                    },
                    "Parameters": [
                        "selectedEnv"
                    ]
                }
            ],
            "ParameterLabels": {
                "selectedEnv": {
                    "default": "Please select Enviroment"
                }
            }
        }
    },
    "Parameters": {
        "selectedEnv": {
            "Type": "String",
            "Default": "DEV",
            "AllowedValues": [
                "DEV",
                "QA",
                "UAT",
                "PROD"
            ]
        }
    },
    "Resources": {
        "S3BucketName": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "BucketName": {
                    "Fn::Join": [
                        "",
                        [
                            {
                                "Fn::Transform": {
                                    "Name": "MyString",
                                    "Parameters": {
                                        "InputString": {
                                            "Ref": "selectedEnv"
                                        },
                                        "Operation": "Lower"
                                    }
                                }
                            },
                            "-deployment.companyname.com"
                        ]
                    ]
                },
                "PublicAccessBlockConfiguration": {
                    "BlockPublicAcls": "true",
                    "BlockPublicPolicy": "true",
                    "IgnorePublicAcls": "true",
                    "RestrictPublicBuckets": "true"
                },
                "Tags": [
                    {
                        "Key": "ENV",
                        "Value": {
                            "Ref": "selectedEnv"
                        }
                    },
                    {
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "",
                                [
                                    {
                                        "Ref": "selectedEnv"
                                    },
                                    "deployments"
                                ]
                            ]
                        }
                    }
                ]
            },
            "Metadata": {
                "AWS::CloudFormation::Designer": {
                    "id": "c81705e6-6c88-4a3d-bc49-80d8736bd88e"
                }
            }
        },
        "QueueForIOT": {
            "Type": "AWS::SQS::Queue",
            "Properties": {
                "QueueName": {
                    "Fn::Join": [
                        "",
                        [
                            {
                                "Ref": "selectedEnv"
                            },
                            "QueueForIOT"
                        ]
                    ]
                },
                "DelaySeconds": "0",
                "MaximumMessageSize": "262144",
                "MessageRetentionPeriod": "345600",
                "ReceiveMessageWaitTimeSeconds": "20",
                "VisibilityTimeout": "30"
            },
            "Metadata": {
                "AWS::CloudFormation::Designer": {
                    "id": "6484fbb7-a188-4a57-a40e-ba9bd69d4597"
                }
            }
        }
    },
    "Outputs": {
        "Help": {
            "Description": "This is description",
            "Value": ""
        }
    }
}

我的问题是我想对S3存储桶或任何其他资源执行小写或有时大写的值。
怎么办?

My question is I want to do lowercase or sometimes uppercase value for S3 bucket or any other resources. How to do? Thanks in advance.

附加了模板创建错误的图像。

Image of template creation error attached.

推荐答案

我得到了这个问题的答案。
为此,我使用了Mappings JSON,在其中添加了诸如If Selected Value是DEV的值,然后使用dev,如果QA然后qa这样的值,并在JSON之下使用了 Fn:FindInMap

I got the answer of this question. For this I have used Mappings JSON in which I have added values like If Selected value is DEV then use dev, If QA then qa like this, and used below JSON which used Fn:FindInMap


[
{
Fn :: FindInMap:[
Enviroment,
PlatformName,
{
Ref: selectedEnv
}
]
},
clientname
]

[ { "Fn::FindInMap": [ "Enviroment", "PlatformName", { "Ref": "selectedEnv" } ] }, "clientname" ]

以下是映射JSON:


映射:{
环境:{
PlatformName:{
DEV: dev,
QA : qa,
UAT: uat,
PROD: prod
}
}
}

"Mappings" : { "Enviroment" : { "PlatformName" : { "DEV" : "dev", "QA" : "qa", "UAT" : "uat", "PROD" : "prod" } } }

这篇关于AWS Cloudformation-如何在json / yaml模板中执行字符串大写或小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆