【发布时间】:2020-04-23 20:01:48
【问题描述】:
我正在使用 AWS CloudFormation 并创建了一个模板,我在其中要求用户选择环境。
基于选定的价值,我创建了资源。用户必须在 DEV、QA、PROD、UAT 等之间进行选择,但是当我将此值添加到 S3 存储桶名称 (-downloads.com) 后,它是不允许的,因为 S3 存储桶名称中不允许使用大写字母。
所以我确实在 JSON 中进行了更改,我使用 fn::Transform 和 "Condition":"Lower" 但随后在创建资源时出现以下错误。
找不到名为 871247504605::String 的转换。用户请求回滚。
下面是我的 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 存储桶或任何其他资源使用小写或有时大写的值。如何做到这一点?
附上模板创建错误的图片。
【问题讨论】:
-
JSON 无效,能否分享完整的 cloudformatino 模板?
-
我也更新了问题和 JSON。请帮帮我。谢谢
-
您可以将用户输入的小写,即 DEV=dev
-
您不能仅使用 json/yaml 进行此转换。虽然您只能使用 json/yaml 做的就是通过将 mappings 和 Fn::FindInMap 合并到您的模板中来映射
DEV to dev, PROD to prod, etc。
标签: json amazon-web-services amazon-s3 amazon-cloudformation aws-cloudformation-custom-resource