CloudFormation Fn::Transform Operation: Lower语言 - >语法错误



我正在尝试创建一个具有云形成的AWS S3 Bucket。

S3桶名需要小写,但我想使用一个参数来复合该名称。

我找到了一条路。

我读过这个。

  • https://github.com/awslabs/aws-cloudformation-templates/tree/master/aws/services/CloudFormation/MacrosExamples/StringFunctions

这是我的代码:

Parameters:
# Global
ServiceName:
Type: String
Description: 'Service Name'
Default: content-input

Environment:
Type: String
Description: 'Environment Name'
Resources:
S3Bucket: 
Type: AWS::S3::Bucket
Properties:
BucketName: !Join ['-',
[ 
content-input,
'Fn::Transform':
- Name: 'String'
Parameters: 
InputString: !Ref Environment
Operation: Lower
]]

但是我得到了这个错误。

while parsing a flow node
expected the node content, but found '-'
in "<unicode string>", line 157, column 11:
- Name: 'String'

我尝试了这里引用的其他语法

Parameters:
# Global
ServiceName:
Type: String
Description: 'Service Name'
Default: content-input

Environment:
Type: String
Description: 'Environment Name'
Resources:
S3Bucket: 
Type: AWS::S3::Bucket
Properties:
BucketName: !Join ['-',
[ 
content-input,
'Fn::Transform':
Name: 'String'
Parameters: 
InputString: !Ref Environment
Operation: Lower
]]

但是我得到:

while parsing a flow sequence
in "<unicode string>", line 154, column 7:
[
^
expected ',' or ']', but got ':'
in "<unicode string>", line 157, column 15:
Name: 'String'
^

当然,这工作完美。

Parameters:
# Global
ServiceName:
Type: String
Description: 'Service Name'
Default: content-input

Environment:
Type: String
Description: 'Environment Name'
Resources:
S3Bucket: 
Type: AWS::S3::Bucket
Properties:
BucketName: !Join ['-',
[ 
content-input,
mytext
]]

如何是正确的语法?

要获得正确的语法,需要注意的重要一点是在使用多个内部函数时使用Json和Yaml。下面更新了语法。对于环境值DEV,这将创建名称为content-input-dev

的桶
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
ServiceName:
Type: String
Description: "Service Name"
Default: content-input
Environment:
Type: String
Description: "Environment Name"
Resources:
S3Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
!Join [
"-",
[
!Ref ServiceName,
{
"Fn::Transform":
{
"Name": "String",
"Parameters":
{ "InputString": !Ref Environment, "Operation": "Lower" },
},
},
],
]

最新更新