Skip to content

Instantly share code, notes, and snippets.

@alexishida
Created October 26, 2021 22:58
Show Gist options
  • Select an option

  • Save alexishida/622c56fb0deaa330ca0174074aae0f20 to your computer and use it in GitHub Desktop.

Select an option

Save alexishida/622c56fb0deaa330ca0174074aae0f20 to your computer and use it in GitHub Desktop.
API Gateway Lambda Authorizer
// https://medium.com/swlh/how-to-protect-apis-with-jwt-and-api-gateway-lambda-authorizer-1110ff035df1
exports.handler = async (event) => {
if(event.authorizationToken === "OK"){
return allowPolicy(event.methodArn);
}
return denyAllPolicy();
function denyAllPolicy(){
return {
"principalId": "*",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "*",
"Effect": "Deny",
"Resource": "*"
}
]
}
}
}
function allowPolicy(methodArn){
return {
"principalId": "apigateway.amazonaws.com",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": methodArn
}
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment