| 12 | |
| 13 | // Generate policy to allow this user on this API: |
| 14 | const generatePolicy = (principalId, effect, resource) => { |
| 15 | const authResponse = {}; |
| 16 | authResponse.principalId = principalId; |
| 17 | if (effect && resource) { |
| 18 | const policyDocument = {}; |
| 19 | policyDocument.Version = '2012-10-17'; |
| 20 | policyDocument.Statement = []; |
| 21 | const statementOne = {}; |
| 22 | statementOne.Action = 'execute-api:Invoke'; |
| 23 | statementOne.Effect = effect; |
| 24 | statementOne.Resource = resource; |
| 25 | policyDocument.Statement[0] = statementOne; |
| 26 | authResponse.policyDocument = policyDocument; |
| 27 | } |
| 28 | return authResponse; |
| 29 | }; |
| 30 | |
| 31 | // Reusable Authorizer function, set on `authorizer` field in serverless.yml |
| 32 | module.exports.authorize = (event, context, cb) => { |