Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.handler = (event, context) => { awsServerlessExpress.proxy(server, event

[Package and create your Lambda function](http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html), then configure a simple proxy API using Amazon API Gateway and integrate it with your Lambda function.

## Quick Start/Example
## Quick Start

Want to get up and running quickly? [Check out our basic starter example](examples/basic-starter) which includes:

Expand All @@ -33,6 +33,8 @@ Want to get up and running quickly? [Check out our basic starter example](exampl
- [Serverless Application Model (SAM)](https://github.com/awslabs/serverless-application-model)/[CloudFormation](https://aws.amazon.com/cloudformation/aws-cloudformation-templates/) template
- Helper scripts to configure, deploy, and manage your application

## Examples

### Getting the API Gateway event object
This package includes middleware to easily get the event object Lambda receives from API Gateway

Expand All @@ -44,6 +46,39 @@ app.get('/', (req, res) => {
})
```

### Using resolveMode `PROMISE` with async handler

```js
// lambda.js
'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)

// note that callback the promise is always resolved
// i.e. errors still lead to a resolved promise
// The resolved promise has a a statusCode property that can be checked for error codes

exports.handler = async (event, context) => { return awsServerlessExpress.proxy(server, event, context, 'PROMISE') }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .proxy call should be suffixed with .promise I believe.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your handler is't doing any more async work why would someone use this feature?

```

### Using resolveMode `CALLBACK` with callback function

```js
// lambda.js
'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)

exports.handler = (event, context, callback) => {
// note that callback is always called with (null, responseObject)
// i.e. errors still lead to a "successful" callback.
// The responseObject has a a statusCode property that can be checked for error codes
awsServerlessExpress.proxy(server, event, context, 'CALLBACK', callback)
}
```

### Is AWS serverless right for my app?

#### Benefits
Expand Down