问题描述
我正在尝试使用云形成创建 AWS S3 存储桶。
S3 存储桶名称需要小写,但我想使用参数来复合该名称。这个参数是大写的。
我开辟了一条道路。
我读过这个。
这是我的代码:
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'
我尝试了其他语法引用 here
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 ['-','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>",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 ['-',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" },},],]