【问题标题】:how to replace character in a string variable using CloudFormation如何使用 CloudFormation 替换字符串变量中的字符
【发布时间】:2021-10-27 00:43:39
【问题描述】:

在使用 CloudFormation 语法的 serverless.yml 脚本中,我使用 appName 变量为我的应用程序定义了一个名称:

custom:
  appName: my-app-name

在脚本下面的某个地方,我使用这个appName 变量来组装url 路径字符串,例如:

  myEndpoint:
    events:
      - http:
          path: /${{self:custom.appName}}/index

这将导致path 成为/my-app-name/index

但我想将 - 字符替换为 _ 破折号。

最干净的方法是什么?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation serverless


    【解决方案1】:

    使用普通的 CloudFormation 无法做到这一点。您必须使用macros,但也可以使用自定义资源。具体来说,您可以使用 Replace 宏开发我的 AWS 并在 aws-cloudformation / aws-cloudformation-macros 上提供。您还可以开发自己的宏,或者修改 AWS 提供的宏,因为它是开源的。

    【讨论】:

      猜你喜欢
      • 2020-07-09
      • 2011-10-23
      • 1970-01-01
      • 1970-01-01
      • 2020-03-30
      • 2017-06-21
      • 2011-09-29
      • 2014-12-11
      • 2013-02-16
      相关资源
      最近更新 更多