AWS Amplify is a set of purpose-built tools and features that lets front-end web and mobile developers quickly and easily build full-stack applications on AWS, with the flexibility to leverage the breadth of AWS services as your use cases evolve.
At our company, we use AWS Amplify for hosting our frontend (React) apps. Although it's an amazing service and we love it, it lacks one important feature: integration with AWS Chat Bot (for sending pipeline notification to slack). It however allows you to send notifications to email addresses (which is not ideal, at least for us).
But there's a robust workaround for this problem, let me share that with you.
From AWS web console, go to AWS Amplify
Select the app against which you want to enable slack notifications
Select "Notifications" from the left sidebar
Enter an email address that you use and then click save
Now you need to create a lambda function that will receive messages from the AWS SNS topic (created by AWS Amplify) and forward that to slack
From AWS Console, go to AWS Lambda
Give a name to your function, choose runtime as node 14.x, and click create
Add the following code to your function
// deps in lambda are added as layers
const fetch = require('node-fetch')
// this should be your webhook URL (doc: https://api.slack.com/messaging/webhooks)
const integrationURL = ''
exports.handler = async (event) => {
const message = event.Records[0].Sns.Message
return await fetch(integrationURL, {
method: 'POST',
body: JSON.stringify({
attachments: [{
title: `AWS Amplifyy Notification!`,
text: message,
}]
}),
headers: { 'Content-Type': 'application/json' },
})
.then((data) => console.log('sent!'))
.catch((e) => console.error(e.response.data))
}
Or grab it from github gist
The code uses the node-fetch
package to make HTTP post request, you will need to add a dependency layer to your lambda function for it to work
To get integration URL
you will need to create the slack app and enable incoming webhooks, check out the official tutorial.
Save your changes and click the "Deploy" button
Next, add a trigger to your AWS Lambda function
Select "SNS" as the trigger, and then select the SNS Topic that would be created by AWS Amplify (when you added email earlier to enable notifications)
To test things out, go back to AWS Amplify and from being within the project, click "Redeploy this version"
You should receive a notification in your slack
The email you added earlier is no longer needed (we only did that to expose SNS Topic) and you could remove it by visiting AWS Amplify->notifications.
Let's connect:
Linkedin: https://www.linkedin.com/in/mubbashir10/
Twitter: https://twitter.com/mubbashir100
Top comments (4)
If you find this post, there is an easier solution in I posted in one of the github issues:
This solution is build using:
Then with AWS Chatbot you can create custom actions to inspect your deployments straight from slack.
Based on what are you creating SNS? Shouldn't you create a web-hook trigger within the build settings of Amplify?
Do you know how to get the custom domain?
Custom domain for AWS Ampliffy? You could do that from domain management (It will setup SSL and provide you with a CNAME record pointing to a cloudfrotn distribution)