You will create an application in Slack and make it work with your Serverless Application on AWS. Amazon API Gateway is a managed API service that you will use to subscribe to events from Slack. AWS Secrets Manager is a service to securely store secrets. The app will use two secrets from Slack: 1) the signing secret that enables the app to verify authenticity of events received from Slack and 2) the Bot Token that enables the app to post messages to Slack.
❗ Ensure you've completed the Code Management before beginning this module.
Each of the following sections provides an implementation overview and detailed, step-by-step instructions. The overview should provide enough context for you to complete the implementation if you're already familiar with the AWS Management Console or you want to explore the services yourself without following a walkthrough.
Create a Slack application and set up the necessary permissions and bot user. Copy the signing secret to AWS Secrets Manager. Install the app to your workspace and copy the bot token to AWS Secrets Manager. Copy the API Gateway endpoint from Lambda and use it to subscribe to Slack events - once you paste it, it should be automatically verified. Choose the events you want to subscribe to and re-install the Slack app to your Slack workspace.
✅ Step-by-step directions
-
Go to api.slack.com and log in if asked to.
-
Choose Your apps in the top right corner.
-
Choose Create New App.
-
Give your app a name and choose the development workspace that will own the app. Choose Create App.
-
In the Basic Information screen, choose Permissions.
-
Scroll down to Scopes
- Select Add an OAuth Scope
- Choose the chat:write:bot scope
- Choose the bot scope
-
In the left menu, choose Bot Users and choose Add a Bot User in the screen that opens.
-
Give your bot a Display name, a Default username, and choose Always Show My Bot as Online. Choose Add Bot User.
-
In the left menu, choose Basic Information and scroll to the App Credential section.
-
In the Singing Secret textbox, choose Show and copy the secret value.
-
Go to the AWS Secrets Manager console.
-
Find the secret named as APP_NAME-Secret and choose it.
-
Scroll down to the Secret value section and choose Retrieve secret value.
-
Choose Edit.
-
Paste the Signing secret you copied in Slack to the textbox next to Signing_Secret key. Don't save it yet and keep the tab open.
-
Go back to the Slack app configuration page.
-
In the left menu, choose Install App and choose Install App to Workspace.
-
Choose Allow in the following screen.
-
Copy the Bot User OAuth Access Token.
-
Go back to the AWS Secrets Manager console and find your secret again.
-
Paste the token you just copied to the textbox next to Bot_Token key. Choose Save.
-
Go back to the Lambda applications console and find the application you created in module 1.
-
Scroll down until you see the API Endpoint section and copy the Endpoint URL.
-
Go back to the Slack app configuration page.
-
In the left menu, choose Event Subscriptions and turn Enable Events on.
-
Paste the API Gateway endpoint you copied in the Lambda console to the Request URL textbox and add "/slackevents" to the end of it and press Tab. You should see a Verified label.
-
In Subscribe to Bot Events section, choose Add Bot User Event and select app_mention and message.im.
-
Choose Save Changes.
-
A warning message will appear at the top, requesting the app to be re-installed. Choose reinstall your app.
-
Choose Allow in the app installation screen that opens.
-
Go to the Slack app and find the bot user you've just added. Send it a message. The bot should echo the message back.
-
Add the bot to a channel and send it an @-message. The bot should respond.
🔧 You just created a Slack app to connect to your AWS account. From here you can now add business logic and easily build more sophisticated bots.
✅ Proceed to the next module, AWS Notifications, wherein you'll configure AWS to send events to your Slack bot.