AWS Lambda — Sending Slack notification
In this article, we are talking about Incoming Webhooks with AWS Lambda. How we can send the slack message from AWS Lambda using Incoming Webhooks.
What is the incoming Webhook?
Incoming Webhooks are a simple way to post messages from apps into Slack. Creating an Incoming Webhook gives you a unique URL to which you send a JSON payload with the message text and some options. You can use all the usual formatting and layout blocks with Incoming Webhooks to make the messages stand out.
Let's move on Slack and start our exercise.
Install Incoming WebHooks plugin into your slack.
Goto App Directory > Search `Incoming WebHooks`.
Click on `Incoming WebHooks`, It will display like belove
Click on `Add to Slack`.
Configure Incoming WebHooks in the specific slack channel.
- Add Slack Channel name to get notification
- Copy Webhook URL
- Enter the Description of your WebHook.
- Enter the Name of your WebHook If you want any customize name default it will be `incoming-webhook`.
- If you want any custom icon to add that in Customize Icon section.
Click on Save Setting.
Once you setup Incoming WebHooks into any slack channel it will send notification like belove.
Now we successfully add our Incoming WebHooks plugin in the slack channel 🎊 🎉🤖🎊 🎉
Now let's move on AWS console
- In the Lambda console, choose to Create function.
- Choose Author from scratch.
- Under Basic information, add the following:
- For Function name, enter a name that identifies it as the function used to Stop your EC2 instances. For example, “StartEC2Instances”.
- For Runtime, choose
- Under Permissions, expand Choose or create an execution role.
- Under the Execution role, choose to use an existing role.
- Under the Existing role, choose the IAM role that you created.
- Choose to Create a function.
- Copy this code, and then under Function code, paste it into the editor panel in the code editor (lambda_function).
If you select
Pythonas a runtime environment, you can use this code.
If you select
Node.jsas a runtime environment, You can use this code.
🎊 🎉🤖🎊 🎉
We have successfully created lambda functions, Now Click on
Test. It will execute our lambda function and start an EC2 instance as well as Send Slack notification.
Thank you for reading, if you have anything to add please send a response or add a note!