Skip to content

Instantly share code, notes, and snippets.

@rts-rob
Last active September 12, 2017 08:15
Show Gist options
  • Save rts-rob/7c6e2a518a52feb715112d0e3e856544 to your computer and use it in GitHub Desktop.
Save rts-rob/7c6e2a518a52feb715112d0e3e856544 to your computer and use it in GitHub Desktop.
Promisified function for validating the user agent of an AWS Lambda invocation
function validateUserAgent(event, desiredUserAgent) {
return new Promise(function(resolve, reject) {
const foundUserAgent = event.requestContext.identity.userAgent.toLowerCase();
if (foundUserAgent.startsWith(desiredUserAgent.toLowerCase())) {
resolve(querystring.parse(event.body));
} else {
reject(buildError(401, "This endpoint cannot be accessed via the current User Agent."));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment