From 3f7c25c64a21be4e1bb722599e7daeaa9d9cdb43 Mon Sep 17 00:00:00 2001 From: Takagi Kensuke Date: Wed, 17 Feb 2021 07:10:33 +0900 Subject: [PATCH] [#800] Updates docs and examples about deploying to AWS Lambda * [examples] Update to follow deprecation of deps * [docs] Update to follow deprecation of deps --- docs/_deployments/aws-lambda.md | 20 ++++++++------------ examples/deploy-aws-lambda/app.js | 14 +++++--------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/docs/_deployments/aws-lambda.md b/docs/_deployments/aws-lambda.md index a17acabb5..dd1ad3848 100644 --- a/docs/_deployments/aws-lambda.md +++ b/docs/_deployments/aws-lambda.md @@ -110,17 +110,17 @@ 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 official [AWS Serverless Express](https://github.com/awslabs/aws-serverless-express) module to transform Express HTTP requests to Lambda function events: +First, install the [Serverless Express](https://github.com/vendia/serverless-express) module to transform Express HTTP requests to Lambda function events: ```bash -npm install aws-serverless-express +npm install @vendia/serverless-express ``` 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: ```javascript const { App, ExpressReceiver } = require('@slack/bolt'); -const awsServerlessExpress = require('aws-serverless-express'); +const serverlessExpress = require('@vendia/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 AWS Serverless Express: @@ -141,19 +141,15 @@ const app = new App({ token: process.env.SLACK_BOT_TOKEN, receiver: expressReceiver }); - -// Initialize your AWSServerlessExpress server using Bolt's ExpressReceiver -const server = awsServerlessExpress.createServer(expressReceiver.app); ``` 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 = (event, context) => { - console.log('⚡️ Bolt app is running!'); - awsServerlessExpress.proxy(server, event, context); -}; +module.exports.handler = serverlessExpress({ + app: expressReceiver.app +}); ``` When you're done, your app should look similar to the ⚡️[Deploying to AWS Lambda app][deploy-aws-lambda-app/app.js]. @@ -187,7 +183,7 @@ plugins: > 💡 `SLACK_SIGNING_SECRET` and `SLACK_BOT_TOKEN` must be enviornment variables on your local machine. > You can [learn how to export Slack environment variables](/bolt-js/tutorial/getting-started#setting-up-your-local-project) in our Getting Started guide. -**3. Install Serverless Offline** +**3. Install Serverless Offline** To make local development a breeze, we'll use the `serverless-offline` module to emulate a deployed function. @@ -329,7 +325,7 @@ Now that you've built and deployed a basic app, here are some ideas you can expl [aws-cli-configure]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-config [aws-cli-install]: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html -[aws-cli-output-format]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-format +[aws-cli-output-format]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-format [aws-cli-region]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-region [aws-iam-user]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html#cli-configure-quickstart-creds [aws-lambda]: https://aws.amazon.com/lambda/ diff --git a/examples/deploy-aws-lambda/app.js b/examples/deploy-aws-lambda/app.js index a4329a0ef..19b4cbff6 100644 --- a/examples/deploy-aws-lambda/app.js +++ b/examples/deploy-aws-lambda/app.js @@ -1,5 +1,5 @@ const { App, ExpressReceiver } = require('@slack/bolt'); -const awsServerlessExpress = require('aws-serverless-express'); +const serverlessExpress = require('@vendia/serverless-express'); // Initialize your custom receiver const expressReceiver = new ExpressReceiver({ @@ -17,9 +17,6 @@ const app = new App({ receiver: expressReceiver }); -// Initialize your AWSServerlessExpress server using Bolt's ExpressReceiver -const server = awsServerlessExpress.createServer(expressReceiver.app); - // Listens to incoming messages that contain "hello" app.message('hello', async ({ message, say }) => { // say() sends a message to the channel where the event was triggered @@ -52,7 +49,7 @@ app.action('button_click', async ({ body, ack, say }) => { // Acknowledge the action after say() to exit the Lambda process await ack(); }); - + // Listens to incoming messages that contain "goodbye" app.message('goodbye', async ({ message, say }) => { // say() sends a message to the channel where the event was triggered @@ -60,7 +57,6 @@ app.message('goodbye', async ({ message, say }) => { }); // Handle the Lambda function event -module.exports.handler = (event, context) => { - console.log('⚡️ Bolt app is running!'); - awsServerlessExpress.proxy(server, event, context); -}; \ No newline at end of file +module.exports.handler = serverlessExpress({ + app: expressReceiver.app +});