具有aws导入功能的无服务器框架返回404

时间:2020-07-06 12:09:23

标签: serverless aws-serverless

我有两个共享相同自定义授权者的无服务器应用程序。突然,第二个serverless.yml文件中的导入功能停止工作。

该应用基于https://github.com/medwig/serverless-shared-authorizer

gateway.serverless


service: authorizer-stack

provider:
  name: aws
  runtime: nodejs12.x
  region: ap-south-1
  profile: xxx-dev

functions:
  authorizer:
    handler: handler.auth

  test:
    handler: handler.privateEndpoint
    events:
      - http:
          path: /api/test
          method: get
          authorizer:
            type: CUSTOM
            authorizerId:
              Ref: Authorizer

  test2:
    handler: handler.publicEndpoint
    events:
      - http:
          path: /api/test/public
          method: get

resources:
  Resources:
    AuthorizerPermission:
      Type: AWS::Lambda::Permission
      Properties:
        FunctionName:
          Fn::GetAtt: AuthorizerLambdaFunction.Arn
        Action: lambda:InvokeFunction
        Principal:
          Fn::Join: ["",["apigateway.", { Ref: "AWS::URLSuffix"}]]
    Authorizer:
      DependsOn:
        - ApiGatewayRestApi
      Type: AWS::ApiGateway::Authorizer
      Properties:
        Name: ${self:provider.stage}-Authorizer
        RestApiId: { "Ref" : "ApiGatewayRestApi" }
        Type: TOKEN
        IdentitySource: method.request.header.Authorization
        AuthorizerResultTtlInSeconds: 300
        AuthorizerUri:
          Fn::Join:
            - ''
            -
              - 'arn:aws:apigateway:'
              - Ref: "AWS::Region"
              - ':lambda:path/2015-03-31/functions/'
              - Fn::GetAtt: "AuthorizerLambdaFunction.Arn"
              - "/invocations"

  Outputs:
    AuthorizerId:
      Value:
        Ref: Authorizer
      Export:
        Name: authorizerId
    apiGatewayRestApiId:
      Value:
        Ref: ApiGatewayRestApi
      Export:
        Name: restApiId
    apiGatewayRestApiRootResourceId:
      Value:
        Fn::GetAtt:
          - ApiGatewayRestApi
          - RootResourceId
      Export:
        Name: rootResourceId


products serverless

service: products-list

provider:
  name: aws
  runtime: nodejs12.x
  region: ap-south-1
  profile: xxx-dev
  apiGateway:
    restApiId:
      Fn::ImportValue: authorizer-stack-dev-restApiId
    restApiRootResourceId:
      Fn::ImportValue: authorizer-stack-dev-rootResourceId


functions:
  get-products:
    handler: handler.getProducts
    events:
      - http:
          path: /api/products
          method: get
          authorizer:
            type: CUSTOM
            authorizerId:
              Fn::ImportValue: authorizer-stack-dev-authorizerId

我随机遇到以下错误

 An error occurred: products-list-dev - No export named authorizer-stack-dev-restApiId found.
 An error occurred: products-list-dev - No export named authorizer-stack-dev-rootResourceId found.
 An error occurred: products-list-dev - No export named authorizer-stack-dev-authorizerId found.

我在这里想念什么?

无服务器-v 框架核心:1.74.1 插件:3.6.15 SDK:2.3.1 组件:2.31.10

1 个答案:

答案 0 :(得分:1)

根据我过去配置的共享授权者,没有必要去努力。无服务器框架站点上的文档具有一个简单得多的设置来实现共享授权者,我将始终采用最简单的解决方案:https://www.serverless.com/framework/docs/providers/aws/events/apigateway#share-authorizer