| 6 | |
| 7 | // Policy helper function |
| 8 | const generatePolicy = (principalId, effect, resource) => { |
| 9 | const authResponse = {}; |
| 10 | authResponse.principalId = principalId; |
| 11 | if (effect && resource) { |
| 12 | const policyDocument = {}; |
| 13 | policyDocument.Version = '2012-10-17'; |
| 14 | policyDocument.Statement = []; |
| 15 | const statementOne = {}; |
| 16 | statementOne.Action = 'execute-api:Invoke'; |
| 17 | statementOne.Effect = effect; |
| 18 | statementOne.Resource = resource; |
| 19 | policyDocument.Statement[0] = statementOne; |
| 20 | authResponse.policyDocument = policyDocument; |
| 21 | } |
| 22 | return authResponse; |
| 23 | }; |
| 24 | |
| 25 | // Reusable Authorizer function, set on `authorizer` field in serverless.yml |
| 26 | module.exports.auth = (event, context, callback) => { |