Created
December 16, 2021 21:51
-
-
Save mickymots/6661da7c36133fe95ffd8ae812795ef1 to your computer and use it in GitHub Desktop.
lambda_auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
#// Help function to generate an IAM policy | |
def generatePolicy(principalId, effect, resource): | |
# var generatePolicy = function(principalId, effect, resource) | |
authResponse = {}; | |
authResponseprincipalId = principalId | |
if effect and resource : | |
policyDocument = {}; | |
policyDocument["Version"] = '2012-10-17'; | |
policyDocument["Statement"] = []; | |
statementOne = {}; | |
statementOne["Action"] = 'execute-api:Invoke'; | |
statementOne["Effect"] = effect; | |
statementOne["Resource"]= resource; | |
policyDocument["Statement"].append (statementOne); | |
authResponse["policyDocument"] = policyDocument; | |
# Optional output with custom properties of the String, Number or Boolean type. | |
authResponse["context"] = { | |
"stringKey": "stringval", | |
"numberKey": 123, | |
"booleanKey": True | |
}; | |
return authResponse; | |
def lambda_handler(event, context): | |
# TODO implement | |
token = "" | |
if 'authorizationToken' in event: | |
token = event["authorizationToken"] | |
if token == 'YNQXmb4oYv9rSboLGFVmC5b9zszBfZtg5wcFVoD2': | |
return generatePolicy("*", "Allow", "*") | |
else: | |
return generatePolicy("", "Deny", "*") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment