API 网关 - 通过代理和AWS_IAM传递,而不是传递标识



我正在尝试创建一个 API 网关,该网关使用AWS_IAM授权方,并使用 Amplify 使用联合身份登录我的应用程序。

这一切都工作正常,但是我没有在我的后端服务中获得身份。我想要的是能够在后端服务中访问用户的身份。例如,带有用户ID或类似内容的标头。

我一直在看这个例子:https://github.com/matsev/cloudformation-api-gateway/blob/master/cloudformation.template 尝试映射$context,但它似乎不适用于HTTP_PROXY?

  RefreshProxy:
    Type: AWS::ApiGateway::Resource
    Properties:
      ParentId:
        Ref: SomeOtherHandler
      PathPart: '{proxy+}'
      RestApiId:
        Ref: ApiGatewayRestApi
  RefreshProxyMethod:
    Type: AWS::ApiGateway::Method
    Properties:
      ResourceId:
        Ref: RefreshProxy
      RestApiId:
        Ref: ApiGatewayRestApi
      AuthorizationType: AWS_IAM
      HttpMethod: POST
      RequestParameters:
        method.request.path.proxy: true
      Integration:
        IntegrationHttpMethod: POST
        Type: HTTP_PROXY
        Uri: url/{proxy}
        IntegrationResponses:
          - StatusCode: 200
        RequestParameters:
          integration.request.path.proxy: method.request.path.proxy
          integration.request.header.Accept-Encoding: "'identity'"
        PassthroughBehavior: WHEN_NO_MATCH

您需要从上下文中添加一个带有 cognitoIdentityId 的标头。因此,在集成部分中,您需要:

integration.request.header.Identity: context.identity.cognitoIdentityId

最新更新