Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.0.6 #3

Merged
merged 3 commits into from
Apr 26, 2018
Merged

0.0.6 #3

merged 3 commits into from
Apr 26, 2018

Conversation

igorkosta
Copy link
Owner

@igorkosta igorkosta commented Apr 26, 2018

Introducing createHandler - hopefully a better way to create handlers for you lambda.

createHandler function takes a function you want to run and an optional
options array and returns a handler function for your λ, e.g.

const createHandler = require('shawerma').createHandler;

createHandler(f, options)

f(event) => result || Promise<result>

options : { timeout, onSuccess, onError }

timeout defaults to 5 seconds.

The optional onSuccess function is called (with the result from f) after f has returned a result and before the result is returned to API Gateway.

The optional onError function is called (with the error object) before the error is returned to API Gateway.

const createHandler = require('shawerma').createHandler;
const listAll = require('./listAll')

const options = {
  timeout: 9000
}

// options is an optional parameter :)
module.exports.handler = createHandler(listAll, options)

IMPORTANT: whenever you create your handler with the help of createHandler it will check whether a user calling your function is authenticated (`event.reque

Those checks are not optional yet - they will be in the future.

if (event.headers.origin !== process.env.ORIGIN) {
  let response = HttpError(403, `Wrong Origin`)
  return cb(null, response)
}

if (!event.requestContext.authorizer) {
  let result = HttpError(401, `Not authorized`)
  return cb(null, result)
}

@igorkosta igorkosta merged commit 144122d into master Apr 26, 2018
@igorkosta igorkosta deleted the 0.0.6 branch July 20, 2018 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant