Skip to content

Instantly share code, notes, and snippets.

@mrcnc
Last active July 3, 2018 19:53
Show Gist options
  • Save mrcnc/0c5fa1cc021c70db429bda3447455e65 to your computer and use it in GitHub Desktop.
Save mrcnc/0c5fa1cc021c70db429bda3447455e65 to your computer and use it in GitHub Desktop.
simple lambda that sets a tracking cookie
'use strict';
// based on this blog post: https://aws.amazon.com/blogs/compute/simply-serverless-using-aws-lambda-to-expose-custom-cookies-with-api-gateway/
exports.handler = (event, context) => {
let cookieKey = process.env.KEY || "wid";
let cookieId = Math.random().toString(36).substring(6);
let domain = process.env.DOMAIN || "127.0.0.1:3000";
let expires = "Fri, 31 Dec 9999 23:59:59 GMT";
let cookieString = `${cookieKey}=${cookieId}; domain=${domain}; expires=${expires};`;
context.done(null, {"Cookie": cookieString});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment