Lambda Slack



When my production app processes change state on Heroku,I want to be notified in Slack:

Other examples:

Pager-notifying events:

Heroku has webhooksfor these events but their payloads aren't in the format needed forSlack incoming webhooks.

The LambdaTest Slack Integration allows you to push a bug directly to your specified Slack channel from LambdaTest platform. Share your UI observations and input with your teammates on anytime, by capturing a screenshot in the middle of your test session through LambdaTest. You can annotate the screenshot & highlight your issue or input. Happy Team delivers dedicated software solutions and provide consultancy to a wide variety of industries. We supports customers from around the world in their business by providing them with smart. We use this to notify the security team on Slack by configuring a CloudWatch Event Rule on GuardDuty findings that triggers a Lambda serverless function written in Go called GuardDuty2Slack. This post will walk you through the process and code used to join member accounts to an organization and send GuardDuty findings as Slack notifications. Lambda Stack provides a one line installation and managed upgrade path for: PyTorch, TensorFlow, CUDA, cuDNN, and NVIDIA Drivers. It's compatible with Ubuntu 20.04 LTS, 18.04 LTS, and 16.04 LTS. No more futzing with your Linux AI software, Lambda Stack is here. Install Lambda Stack in one command. Enter your email below to join Lambda Stuttgart on Slack!

AWS Lambda is the perfect glue to transform the Heroku webhook's JSON payloadinto a useful JSON payload for Slack's incoming webhook.

Slack config

Create an incoming webhook.Copy the URL.

Lambda config

Create a Lambda function.AWS' supported runtimes include Node, Python, Ruby, and Go.You can alternatively implement a custom runtime.Here's an example in Ruby:

Paste the Slack incoming webhook URL as an environment variable,which is encrypted at rest.

Create an API Gatewayto make the Lambda function accessible in the Heroku web UI.

Heroku config

Go to:

Create a webhook with event type 'dyno'.Paste the API Gateway URL as the Payload URL.

Modify to taste

Edit and save the code in Lambda's web-based text editor.Trigger a webhook to test the function.View the auto-created CloudWatch logs for each function call.

This guide walks you through preparing and deploying a Slack app using Bolt for JavaScript, the Serverless Framework, and AWS Lambda.

When you’re finished, you’ll have this ⚡️Deploying to AWS Lambda app to run, modify, and make your own.

Set up AWS Lambda

AWS Lambda is a serverless, Function-as-a-Service (FaaS) platform that allows you to run code without managing servers. In this section, we’ll configure your local machine to access AWS Lambda.

💡 Skip this section if you have already configured a profile on your local machine to access AWS Lambda.

1. Sign up for an AWS account

If you don’t already have an account, you should sign up for AWS and follow the on-screen instructions.

💡 You may be asked for payment information during the sign up. Don’t worry, this guide only uses the free tier.

2. Create an AWS access key

Lambda Stack Anaconda

Next, you’ll need programmatic access to your AWS account to deploy onto Lambda. In the world of AWS, this requires an Access Key ID and Secret Access Key.

We recommend watching this short, step-by-step video to 🍿 create an IAM user and download the access keys.

💡 Do you already have an IAM user? Follow the official AWS guide to create access keys for existing IAM users.

3. Install the AWS CLI

The AWS tools are available as a Command Line Interface (CLI) and can be installed on macOS, Windows, or Linux.

On macOS, you can install the AWS CLI by downloading the latest package installer.

4. Configure an AWS profile

You can use the AWS CLI to configure a profile that stores your access key pair on your local machine. This profile is used by the CLI and other tools to access AWS.

The quickest way to configure your profile is to run this command and follow the prompts:

💡 Customize the region and output format best for you.

That wraps up configuring your local machine to access AWS. 👏 Next, let’s do the same with the Serverless Framework.

Set up Serverless Framework

The Serverless Framework includes tools that let you easily configure, debug, and deploy your app to AWS Lambda.

1. Install the Serverless Framework CLI

The Serverless tools are available as a Command Line Interface (CLI) and can be installed on macOS, Windows, or Linux. To install it using npm, run the following command:

💡 You can also globally install the Serverless CLI using the command npm install -g serverless.

Once the installation is complete, test the Serverless CLI by displaying the commands available to you:

You’re now set up with the Serverless tools! Let’s move on to preparing your Bolt app to run as an AWS Lambda function.

Lambda Slack

Get a Bolt Slack app

If you haven’t already built your own Bolt app, you can use our Getting Started guide or clone the template app below:

After you have a Bolt app, navigate to its directory:

Now that you have an app, let’s prepare it for AWS Lambda and the Serverless Framework.

Prepare the app

Lambda Slack

1. Prepare the app for AWS Lambda

By default, Bolt listens for HTTP requests. In this section, we’ll customize your Bolt app’s receiver to respond to Lambda function events instead.

First, install the Serverless Express module to transform Express HTTP requests to Lambda function events:

💡 This guide requires version 4.x.x or later.

Next, update the source code that imports your modules in app.js to require Bolt’s Express receiver and the AWS Serverless Express module:

Then update the source code that initializes your Bolt app to create a custom receiver using AWS Serverless Express:

Finally, at the bottom of your app, update the source code that starts the HTTP server to now respond to an AWS Lambda function event:

When you’re done, your app should look similar to the ⚡️Deploying to AWS Lambda app.

Lambda Slack Python

2. Add a serverless.yml

Serverless Framework projects use a serverless.yml file to configure and deploy apps.

Create a new file called serverless.yml in your app’s root directory and paste the following:

💡 SLACK_SIGNING_SECRET and SLACK_BOT_TOKEN must be enviornment variables on your local machine.You can learn how to export Slack environment variables in our Getting Started guide.

3. Install Serverless Offline

To make local development a breeze, we’ll use the serverless-offline module to emulate a deployed function.

Run the following command to install it as a development dependency:

Congratulations, you’ve just prepared your Bolt app for AWS Lambda and Serverless! Now let’s run and deploy your app.

Run the app locally

Now that your app is configured to respond to an AWS Lambda function, we’ll set up your environment to run the app locally.

Slackbot

1. Start your local servers

First, use the serverless offline command to listen for an AWS Lambda function event:

Next, use ngrok to forward Slack events to your local machine:

💡 Learn how to use ngrok to create a public URL and forward requests to your local machine.

2. Update your Request URL

Next, visit your Slack app’s settings to update your Request URL to use the ngrok web address.

💡 Your Request URL ends with /slack/events, such as https://abc123.ngrok.io/slack/events.

First, select Interativity & Shortcuts from the side and update the Request URL:

Second, select Event Subscriptions from the side and update the Request URL:

3. Test your Slack app

Now you can test your Slack app by inviting your app to a channel then saying “hello” (lower-case). Just like in the Getting Started guide, your app should respond back:

👩‍💻 hello
🤖 Hey there @Jane!

If you don’t receive a response, check your Request URL and try again.

💡 How does this work?The ngrok and Serverless commands are configured on the same port (default: 3000). When a Slack event is sent to your Request URL, it’s received on your local machine by ngrok. The request is then forwarded to Serverless Offline, which emulates an AWS Lambda function event and triggers your Bolt app’s receiver. 🛫🛬 Phew, what a trip!

Deploy the app

You can use the Serverless Framework tools to provision, package, and deploy your app onto AWS Lambda. After your app is deployed, you’ll need to update your app’s request URL to say “hello” to your app. ✨

1. Deploy the app to AWS Lambda

Now, deploy your app to AWS Lambda with the following command:

After your app is deployed, you’ll be given an endpoint which you’ll use as your app’s Request URL. Go ahead and copy this endpoint to use in the next section.

💡 The endpoint should end in /slack/events.

Lambda Slacks

2. Update your Slack app’s settings

Now we need to use your AWS Lambda endpoint as your Request URL, which is where Slack will send events and actions.With your endpoint copied, navigate to your Slack app’s configuration to update your app’s Request URLs.

First, select Interativity & Shortcuts from the side and update the Request URL:

Second, select Event Subscriptions from the side and update the Request URL:

3. Test your Slack app

Your app is now deployed and Slack is updated, so let’s try it out!

Just like the running the app locally section, open a Slack channel that your app is in and say “hello”. You app should once again respond with a greeting:

👩‍💻 hello
🤖 Hey there @Jane!

4. Deploy an update

As you continue to build your Slack app, you’ll need to deploy the updates. Let’s get a feel for this by updating your app to respond to a “goodbye” message.

Add the following code to app.js (source code on GitHub):

Deploy the update using the same command as before:

When the deploy is complete, you can open a Slack channel that your app has joined and say “goodbye” (lower-case). You should see a friendly farewell from your Slack app.

Next steps

You just deployed your first ⚡️Bolt for JavaScript app to AWS Lambda! 🚀

Now that you’ve built and deployed a basic app, here are some ideas you can explore to extend, customize, and monitor it:

  • Brush up on AWS Lambda and the Serverless Framework.
  • Extend your app with Bolt’s Basic Concepts and Serverless plugins.
  • Learn about logging in Bolt’s Advanced Concepts and how to view log messages with Serverless.
  • Get ready for primetime with AWS Lambda testing and deployment environments.