【问题标题】:Import AWS::ApiGateway::Authorizer serverless framework导入 AWS::ApiGateway::Authorizer 无服务器框架
【发布时间】:2020-11-08 10:56:26
【问题描述】:

我尝试构建一个 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 的返回值,以便我了解发生了什么?

我做错了什么?

提前致谢。

【问题讨论】:

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


    【解决方案1】:

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

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

    您可以尝试以下方法:

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

    【讨论】:

    • 删除 !Ref 有点用,给谷歌带来了一些新的错误,哈哈。感谢您的帮助。
    • @VictorCorte 没问题。如果您遇到新问题,您可以随时在 SO 上提出新问题:-)
    猜你喜欢
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 2019-08-04
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多