Skip to content

Commit

Permalink
update the documentation to match with the updated example (slackapi#815
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TheManWhoStaresAtCode committed Jun 1, 2021
1 parent 1be903d commit 741f4d4
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions docs/_deployments/aws-lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,48 +110,40 @@ Now that you have an app, let's prepare it for AWS Lambda and the Serverless Fra

By default, Bolt listens for HTTP requests. In this section, we'll customize your Bolt app's [`receiver`](https://slack.dev/bolt-js/concepts#receiver) to respond to Lambda function events instead.

First, install the [Serverless Express](https://github.com/vendia/serverless-express) module to transform Express HTTP requests to Lambda function events:

```bash
npm install --save @vendia/serverless-express
```

> 💡 This guide requires version `4.x.x` or later.
Next, update the [source code that imports your modules](https://github.com/slackapi/bolt-js-getting-started-app/blob/main/app.js#L1) in `app.js` to require Bolt's Express receiver and the AWS Serverless Express module:
First, update the [source code that imports your modules](https://github.com/slackapi/bolt-js-getting-started-app/blob/main/app.js#L1) in `app.js` to require Bolt's AwsLambda receiver:

```javascript
const { App, ExpressReceiver } = require('@slack/bolt');
const serverlessExpress = require('@vendia/serverless-express');
const { App, AwsLambdaReceiver } = require('@slack/bolt');
```

Then update the [source code that initializes your Bolt app](https://github.com/slackapi/bolt-js-getting-started-app/blob/main/app.js#L3-L7) to create a custom receiver using AWS Serverless Express:
Then update the [source code that initializes your Bolt app](https://github.com/slackapi/bolt-js-getting-started-app/blob/main/app.js#L3-L7) to create a custom receiver using AwsLambdaReceiver:

```javascript
// Initialize your custom receiver
const expressReceiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
// The `processBeforeResponse` option is required for all FaaS environments.
// It allows Bolt methods (e.g. `app.message`) to handle a Slack request
// before the Bolt framework responds to the request (e.g. `ack()`). This is
// important because FaaS immediately terminate handlers after the response.
processBeforeResponse: true
const awsLambdaReceiver = new AwsLambdaReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
});

// Initializes your app with your bot token and the AWS Lambda ready receiver
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
receiver: expressReceiver
token: process.env.SLACK_BOT_TOKEN,
receiver: awsLambdaReceiver,
// The `processBeforeResponse` option is required for all FaaS environments.
// It allows Bolt methods (e.g. `app.message`) to handle a Slack request
// before the Bolt framework responds to the request (e.g. `ack()`). This is
// important because FaaS immediately terminate handlers after the response.
processBeforeResponse: true
});
```

Finally, at the bottom of your app, update the [source code that starts the HTTP server](https://github.com/slackapi/bolt-js-getting-started-app/blob/main/app.js#L40-L45) to now respond to an AWS Lambda function event:

```javascript
// Handle the Lambda function event
module.exports.handler = serverlessExpress({
app: expressReceiver.app
});
module.exports.handler = async (event, context, callback) => {
const handler = await app.start();
return handler(event, context, callback);
}
```

When you're done, your app should look similar to the ⚡️[Deploying to AWS Lambda app][deploy-aws-lambda-app/app.js].
Expand Down

0 comments on commit 741f4d4

Please sign in to comment.