【问题标题】:How to convert string to uppercase in CloudFormation template如何在 CloudFormation 模板中将字符串转换为大写
【发布时间】:2020-02-11 02:27:56
【问题描述】:

我的 CloudFormation 模板中有以下部分

 PublicSubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref VPC
      CidrBlock: 10.1.10.0/24
      AvailabilityZone: !Select [ 0, !GetAZs ]    # Get the first AZ in the list        
      Tags:
      - Key: Name
        Value: !Sub
          - ${AWS::StackName}-PUB-${SUFFIX}
          - SUFFIX: !Select [ 0, !GetAZs ]

我需要 SUFFIX 为大写,我该怎么做?

【问题讨论】:

  • 我看到了注释,但不能让它适用于我的情况。它一直说模板验证错误
  • 当我尝试链接函数时,它给出了以下错误。“..转换块中的内在函数必须只包含参数值或堆栈元数据。”

标签: amazon-web-services amazon-cloudformation


【解决方案1】:

您可以使用调用宏的transform intrinsic function 来实现。有人已经写了一堆关于字符串操作的宏,所以如果你部署了它们,你可以在没有额外编码的情况下使用它们。

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

【讨论】:

  • Transform 似乎不支持函数作为参数。它不适用于我的情况
  • 我确定我已经在工作中完成了这项工作,如果有机会我会在明天回来查看。
  • 从发布的 README 中并不清楚,但是您需要将该 Python 文件添加为转换函数,而不仅仅是使用上层函数。 CF 对此没有任何内置支持,您需要添加自己的转换函数才能做到这一点。
猜你喜欢
  • 1970-01-01
  • 2021-06-11
  • 1970-01-01
  • 1970-01-01
  • 2020-04-23
  • 2014-06-05
  • 2014-06-18
  • 2018-09-16
相关资源
最近更新 更多