无服务器框架 AWS 跨账户自定义授权方

Serverless framework AWS cross-account custom authorizer

如何使用无服务器框架设置跨账户自定义授权方?如果使用 sls 框架配置的自定义授权器与需要授权的函数位于同一 AWS 帐户中,则它可以正常工作。

我现在拥有的是部署了授权者功能的组织根账号。在第二个帐户(组织成员)上,我部署了一个无服务器服务,其中部署了需要从根帐户授权的端点。

是否可以在serverless.yml中配置这样的东西,将部署在成员帐户(111111111111 是根帐号)上:

  hello:
    handler: api/hello.handler
    events:
     - http:
        path: hello
        method: get
        cors: true
        authorizer: arn:aws:lambda:eu-west-1:111111111111:function:authorizer

我试过了,但收到以下错误:

An error occurred: AuthorizerApiGatewayAuthorizer - The policy of Lambda function must explicitly authorize the method or custom authorizer with a SourceArn condition for cross account integration (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException;

...根据 AWS docs 是有道理的。这些文档解释了如何使用 API 网关控制台手动执行此操作,这正是我现在所做的(root 中的授权者,成员帐户中的授权者 - 通过 API 网关手动连接,与中所述相同文档)。

随着服务和组织成员帐户数量的增加,我需要一个更好的解决方案。

是否可以配置并使其与无服务器框架一起工作?

与许多无服务器框架一样,CloudFormation 还没有提供一个插件供您选择:

https://github.com/rschick/serverless-plugin-lambda-account-access

自定义授权人的 serverless.yml 应包括:

plugins:
  - serverless-plugin-lambda-account-access
provider:
  allowAccess:
    - 111111111111 # account id of invoking account