【问题标题】:Serverless version > 2.35 error in variable replacement to Cloudformation template无服务器版本 > 2.35 Cloudformation 模板的变量替换错误
【发布时间】:2021-11-05 20:54:40
【问题描述】:

你好吗?

将无服务器版本从 2.35 升级到任何新版本后,我遇到了一个非常奇怪的错误。 使用与 2.35 中部署的完全相同的 .yml,在较新的版本中会引发以下错误:

ProviderARN 必须是有效的 Cognito 用户池:

Serverless Error ----------------------------------------
 
  An error occurred: ApiGatewayCognitoAuthorizer - ProviderARNs need to be valid Cognito Userpools. Invalid ARNs-
  arn:aws:cognito-idp:${file(./src/config/dev.json):REGION}:${file(./src/config/dev.json):AWS_ACCOUNT}:userpool/${file(./src/config/dev.json):COGNITO_POOL_ID} (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: e8403d66-ec5c-4ead-9528-308baed7640f; Proxy: null).
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.22.1
     Framework Version:         2.50.0 (local)
     Plugin Version:            5.4.4
     SDK Version:               4.3.0
     Components Version:        3.17.0

深究起来,问题在于部署中生成的 CloudFormation 模板无法解析 2.35 及之前版本正确解析的变量(尤其是那些依赖于配置文件的变量),例如在我的代码中:

ApiGatewayCognitoAuthorizer:
      DependsOn:
        - ApiGatewayRestApi
      Type: AWS::ApiGateway::Authorizer
      Properties:
        Name: cognito-authorizer
        IdentitySource: method.request.header.Authorization
        ProviderARNs:
          - "arn:aws:cognito-idp:${${self:custom.config}:REGION}:${${self:custom.config}:AWS_ACCOUNT}:userpool/${${self:custom.config}:COGNITO_POOL_ID}"
        RestApiId:
          Ref: ApiGatewayRestApi
        Type: COGNITO_USER_POOLS

在其他资源、lambdas等中使用了相同的变量替换,但是错误只抛出给API Cognito Authorizer,我不明白...

感谢大家的关注和帮助:)

【问题讨论】:

  • 请不要将代码或错误消息作为图片发布。
  • 对图片感到抱歉@Marcin

标签: amazon-cloudformation amazon-cognito serverless aws-serverless


【解决方案1】:

使用https://www.serverless.com/framework/docs/environment-variables/解决,即从.env文件加载环境变量,而不是自定义.json文件。

谢谢大家。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 2019-03-24
    • 2019-02-15
    • 2022-10-13
    • 2020-07-09
    • 2021-09-13
    • 2020-08-30
    相关资源
    最近更新 更多