导入 AWS::ApiGateway::Authorizer 无服务器框架

Import AWS::ApiGateway::Authorizer serverless framework

我正在尝试构建一个 jenkins 管道,它将部署一些常见的 AWS 资源,然后部署特定的服务资源。

这里是公共资源部分,正在部署成功。

resources:
  Resources:
    GoatfolioUserPool:
      Type: 'AWS::Cognito::UserPool'
      Properties:
        AccountRecoverySetting:
          RecoveryMechanisms:
            - Name: verified_email
              Priority: 1
        AutoVerifiedAttributes:
          - email
        EmailVerificationSubject: "GOATFOLIO - Verifique seu e-mail"
        Policies:
          PasswordPolicy:
            MinimumLength: 6
            RequireLowercase: true
            RequireNumbers: true
            RequireSymbols: true
            RequireUppercase: true
            TemporaryPasswordValidityDays: 1
        Schema:
          - AttributeDataType: String
            Name: email
            Required: true
          - AttributeDataType: String
            Name: given_name
            Required: true
        AliasAttributes:
          - email
        UsernameConfiguration:
          CaseSensitive: false
        UserPoolName: "goatfolio"

    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
          Properties:
        Name: ApiGatewayRestApi

    ApiGatewayAuthorizer:
      Type: AWS::ApiGateway::Authorizer
      Properties:
        AuthorizerResultTtlInSeconds: 10
        IdentitySource: method.request.header.Authorization
        Name: GoatCognitoAuthorizer
        RestApiId:
          Ref: ApiGatewayRestApi
        Type: COGNITO_USER_POOLS
        ProviderARNs:
          - {"Fn::Join": ["", ["arn:aws:cognito-idp:", {Ref: "AWS::Region"}, ":", {Ref: "AWS::AccountId"}, ":userpool/goatfolio", Ref: GoatfolioUserPool]]}

  Outputs:
    ApiGatewayAuthorizerOutput:
      Value:
        Ref: ApiGatewayAuthorizer
      Export:
        Name: ${self:provider.stage}-ApiGatewayAuthorizerOutput

具体部分:

functions:
  getConsolidated:
    handler: handlers.consolidate_investments_handler
    events:
      - http:
          path: portfolio/
          method: get
          authorizer:
            type: COGNITO_USER_POOLS
            authorizerId:
              Ref: {'Fn::ImportValue': '${self:provider.stage}-ApiGatewayAuthorizerOutput'}

我正在尝试使用此 ImportValue,但出现此错误:

Error: The CloudFormation template is invalid: Template error: every Ref object must have a single String value.

我也尝试过一些其他的东西,但没有成功。

有一种方法可以打印 ImportValue 的 return 以便我了解发生了什么?

我做错了什么?

提前致谢。

您可以在堆栈的控制台、Outputs 选项卡或 CloudFormation 控制台的 Exports 菜单中查看 '${self:provider.stage}-ApiGatewayAuthorizerOutput' 的导出值。

!Ref 在您的上下文中无法使用,因为导入的值来自其他堆栈。如果只想使用导入值,则不需要 !Ref.

您可以尝试以下方法:

    authorizerId: {'Fn::ImportValue': '${self:provider.stage}-ApiGatewayAuthorizerOutput'}