微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CloudFormation Fn::Transform 操作:下层 -> 语法错误

如何解决CloudFormation Fn::Transform 操作:下层 -> 语法错误

我正在尝试使用云形成创建 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" },},],]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。