gpt4 book ai didi

amazon-web-services - CloudFormation Fn::Transform 操作:较低 -> 语法错误

转载 作者:行者123 更新时间:2023-12-04 12:56:46 29 4
gpt4 key购买 nike

我正在尝试创建一个具有云形成的 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 ['-',
[
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
]]

正确的语法是怎样的?

最佳答案

要获得正确的语法,需要注意的重要一点是在使用多个 Intrinsic 函数时将 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" },
},
},
],
]

关于amazon-web-services - CloudFormation Fn::Transform 操作:较低 -> 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65774097/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com