-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathhandler.js
More file actions
38 lines (33 loc) · 1.32 KB
/
handler.js
File metadata and controls
38 lines (33 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { echo } = require('/opt/nodejs/lib');
module.exports.hello = async function(event, context) {
echo('This text should be printed in the Lambda');
}
module.exports.authorizerFunc = async function(event, context, callback) {
console.log('Running authorizer function', event);
var token = event.authorizationToken;
callback(null, generatePolicy('user', 'Allow', event.methodArn));
};
// Helper function to generate an IAM policy
// See https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html
var generatePolicy = function(principalId, effect, resource) {
var authResponse = {};
authResponse.principalId = principalId;
if (effect && resource) {
var policyDocument = {};
policyDocument.Version = '2012-10-17';
policyDocument.Statement = [];
var statementOne = {};
statementOne.Action = 'execute-api:Invoke';
statementOne.Effect = effect;
statementOne.Resource = resource;
policyDocument.Statement[0] = 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;
}