Easy in 5 Minutes: Notify Slack of EC2 Events with AWS Lambda
Previously I created a script to check for AWS EC2 maintenance notification events.
On top of that, I made it stop and start the target instances.

I set this up to send Slack notifications via AWS Lambda
so that I can find out every morning which events require maintenance.
Prerequisites
1 | $ pip install lambda-uploader awscli |
Cloning the Project
1 | macOS%$ git clone https://github.com/kenzo0107/AWSEC2Events2Slack |
Editing the Information to Match Each Environment
- lambda.json
1 | { |
| Item | Explain |
|---|---|
| role | Attach a policy that holds permission to describe EC2 resources |
| variables | Slack destination information for notifications |
Uploading the Source to AWS Lambda
1 | macOS%$ lambda-uploader --profile <profile> |
Checking Lambda in the AWS Console
You can see that it has been registered.

Running a Test
I was able to make it fetch events and notify Slack.

Configuring the Trigger
I set up a cron with a CloudWatch schedule expression so that it is delivered every morning.

Overall Impressions
Uploading with lambda-uploader makes the flow of
develop locally → test → deploy
and version management nice and clear.
However, one thing that bothers me is that after uploading, the source is not visible in the console.
Specifically, the following message
The deployment package of the Lambda function “AWSEvent2Slack” is too large to enable inline code editing. However, you can still invoke your function right now.
is displayed in the console.
I used to write a shell script that bundled everything into a zip and uploaded it,
and back then I could see the source.
Since I verify the behavior locally, there is no problem for now even if it is not visible in the console.
That’s all.
I hope this is helpful.

