Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid headers passed back to API Gateway from Lambda via Serverless framework being remapped?

I'm hitting an issue when I try to respond in a Serverless Lambda function with the WWW-Authenticate challenge header.

I am setting in my response

{
    statusCode: 401,
    headers: {
        'WWW-Authenticate': 'Basic realm="My realm"',
    },
    body: "",
}

The function runs successfully but in the response I don't have a WWW-Authenticate header; instead, I have an x-amzn-Remapped-WWW-Authenticate header.

How can I have this header passed through verbatim?

I read the docs about passing custom response headers, but it seems that these need to be set in serverless.yml. Since these response headers need to be dynamic based on the request headers I don't think that will help me.

The function is the default lambda-proxy type.

like image 236
tremby Avatar asked Nov 08 '22 08:11

tremby


1 Answers

By default The Serverless Framework uses the Lambda Proxy Integration method. This does lots of the heavy lifting for you, but also gets in the way.

If you want a more transparent experience you need to use Lambda Integration, and handle the response yourself. Though you'll need to get more hands on, including CORS response headers.

integration: lambda

You can read more about the two methods here: https://serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-integration

like image 168
Matt D Avatar answered Nov 15 '22 06:11

Matt D