I have created a CloudFront CDN that points to a file in S3 and triggers a Lambda@Edge. For Lambda@Edge, I have followed this article to return the Set-Cookie header
https://stacktonic.com/article/how-to-set-a-persistent-uuid-cookie-using-cloud-front-and-lamda-edge
let cookieStringUser = cookie.serialize(cookieName, String(uuid), {
maxAge: 60 * 60 * 24 * cookieLifetime,
sameSite: 'Lax',
path: '/',
httpOnly: false,
domain: "kubernetes.docker.internal",
secure: false
});
responseHeaders['set-cookie'] = [{
key: 'set-cookie',
value: cookieStringUser
}];
I had to play around with the arguments to be able to set the cookies in the browser. If I use the CloudFront endpoint say cdf.cloudfront.net/1x1.png(1x1.png is a file in S3) directly, the browser is able to set the cookie.
When I integrate it with the front end application using Fetch:
let response = await fetch('https://cdn.cloudfront.net/1x1.png',
{
method: "GET",
credentials: "include"
});
Tried the Axios approach as well:
let response = await axios.get(`https://cdn.cloudfront.net/1x1.png`, {
withCredentials: true,
});
And return the domain kubernetes.docker.internal (To load the cookie in localhost) in the cookie , I am able to see the cookie in the response header but the browser fails to set the cookie. I have tried playing around with the parameters yet, no luck.
I have tried with access-allow-credentials header, access-allow-origin *, specifying the domains to allow origin, but nothing works.
What am I missing?