dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.19k stars 795 forks source link

How to use $context in the lambda authoriser identitySource? #1243

Open aditya81070 opened 3 years ago

aditya81070 commented 3 years ago

Hello all, I am writing a lambda authoriser and want to use context.identity.sourceIp, method.request.headers.Authorization as identitySource. When I deploy the application to AWS, the authorizer is set up correctly and things are working fine.

But when I run my code locally, I get the error Serverless Offline only supports retrieving tokens from the headers (λ: auth). If I remove the context.identity.sourceIp from identitySource then it will work fine. If AWS is accepting the values it means these values are correct.

Do I need to do some extra things to make it work?

Here is the complete code.

functions:
  auth:
    handler: handlers/auth.auth
    vpc: ${self:custom.vpc}
  lambda-trigger:
    handler: handlers/lambda-trigger.lambdaTrigger
    timeout: 10
    events:
      - http:
          method: post
          path: /lambda-trigger
          cors: true
          authorizer:
            name: auth
            type: REQUEST
            identitySource: method.request.header.Authorization, context.identity.sourceIp
            resultTtlInSeconds: 0
aditya81070 commented 5 months ago

Hey team, I have reopened the issue because in the past the following configuration worked for me but after recent update, I am getting the same error:

functions:
  auth:
    handler: handlers/auth.auth
    vpc: ${self:custom.vpc}
  lambda-trigger:
    handler: handlers/lambda-trigger.lambdaTrigger
    timeout: 10
    events:
      - http:
          method: post
          path: /lambda-trigger
          cors: true
          authorizer:
            name: auth
            type: REQUEST
            identitySource: context.identity.sourceIp
            resultTtlInSeconds: 0
aditya81070 commented 5 months ago

Hey @dherault is this repository actively maintained or do we have some contributors guidelines that I am not following? There has been a long time since this is not answered.