Kao
Kao

Reputation: 2272

API Gateway - Pass through proxy and AWS_IAM, not passing identity

I'm trying to create an API Gateway, which uses an AWS_IAM Authorizer, and using Amplify to sign in to my app using Federated Identities.

This all works fine, however I'm not getting an identity in my backend service. What I want is to be able to access the identity of the user in my backend service. Eg a header with a user-id or something like that.

I've been looking at this example: https://github.com/matsev/cloudformation-api-gateway/blob/master/cloudformation.template to try to map the $context, however it seems it doesn't work with 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

Upvotes: 2

Views: 495

Answers (1)

doorstuck
doorstuck

Reputation: 2308

You need to add a header with the cognitoIdentityId from the context. So in the integration section you need:

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

Upvotes: 3

Related Questions