Reputation: 1159
I'm trying to create an AWS S3 Bucket with cloud formation.
S3 bucket name needs to be lowercase but I want to use a paramenter to compound that name. This parameter comes uppercase.
I founded a way.
I read this.
This is my code:
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
]]
But I get this error.
while parsing a flow node
expected the node content, but found '-'
in "<unicode string>", line 157, column 11:
- Name: 'String'
I tried this other syntax referered 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 ['-',
[
content-input,
'Fn::Transform':
Name: 'String'
Parameters:
InputString: !Ref Environment
Operation: Lower
]]
But I get:
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'
^
Of Course, this work perfectly.
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
]]
How is the right syntax?
Upvotes: 4
Views: 2475
Reputation: 10333
Important point to note to get the syntax right is to use Json with Yaml when using multiple Intrinsic functions.
Updated syntax below. For Environment value DEV
, this creates a bucket of name 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" },
},
},
],
]
Upvotes: 2