I have a Lambda function running NodeJS 16x.
In the response I’m adding a cookie in the response headers as follows :
function GetResponse() {
const content = GetSomeHTML();
const cookieName = 'MyCookie';
const cookieValue = 'cookieValue123';
const maxAge = 2 * 60 * 60; // 2 hours in seconds
// Construct the Set-Cookie header
const setCookieHeader = cookieName+'='+cookieValue+ '; Max-Age=' + maxAge + '; Path=/; HttpOnly';
const response = {
status: '307',
statusDescription: 'OK',
headers: {
'content-type': [{
key: 'Content-Type',
value: 'text/html'},
{
key:'Set-Cookie',
value:setCookieHeader
}]
},
body: content,
};
return response;
}
When running the function, I’m getting the error :
The Lambda function returned an invalid entry in the headers object: The name of the header must be in lowercase and must match the value of key except for case.
Does anyone know how to solve that please ?
Thanks.
2
Answers
The headers object seems misconstructed. I would have kept it simple with:
but if you want to follow your structure:
Header names are case-insensitive, so
content-type
is the same asContent-Type
You can change you response like this