【问题标题】:Seems to conflict between Serverless syntax and CloudFormation syntaxServerless 语法和 CloudFormation 语法之间似乎有冲突
【发布时间】:2018-12-06 12:46:06
【问题描述】:

下面是Serverless加载的CloudForamtion文件部分。

# resource.yml
.
.
.
{"Fn::Sub": "arn:aws:sqs:*:${AWS::AccountId}:sqs-spoon-*-${env:SERVICE}"}

# serverless.yml
.
.
resources:
  - ${file:resource.yml}

${AWS::AccountId} 是 CloudFormation 伪参数,${env:SERVICE} 是无服务器变量。

当我运行sls deploy 时,它会返回错误。

  Invalid variable reference syntax for variable AWS::AccountId. You can only reference env vars, options, & files. You can check our docs for more info.

似乎说 Serverless 将 ${AWS::AccountId} 识别为 Serverless 变量,而不是 CloudFormation 伪参数。

对吗?

如果是这样,如何让Serverless不解析Pseudo Parameter,以便稍后被CloudFormation解析?

【问题讨论】:

    标签: amazon-cloudformation serverless-framework


    【解决方案1】:

    我可以用plugin解决它。

    使用该插件,可以通过将${AWS::AccountId} 替换为#{AWS::AccountId} 来解决。

    {"Fn::Sub": "arn:aws:sqs:*:#{AWS::AccountId}:sqs-spoon-*-${env:SERVICE}"}
    

    【讨论】:

      【解决方案2】:

      您可以使用 serverless.yml 中的单个配置行来定义对本机 AWS 语法的支持,以定义 variableSyntax。详情可以在这里https://github.com/serverless/serverless/pull/3694找到。

      provider:
        name: aws
        runtime: nodejs8.10
        variableSyntax: "\${((env|self|opt|file|cf|s3)[:\(][ :a-zA-Z0-9._,\-\/\(\)]*?)}"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多