Keeping track of updates in your AWS Lambda function seems like an easy task, but it is actually time-consuming. Leaving your Lambda function unattended after deployment may incur risks in missing crucial updates that may affect its overall performance and functionality. And most of the time, you also do development tasks which might limit your attention to these Lambda functions. That’s why you must be informed whenever an update is made to your Lambda function. Whether done by yourself or by your teammates and collaborators, being informed of these changes will help you maintain its efficiency, especially when diagnosing issues that may arise. Provided in this article is an easy solution to automate Lambda function update notifications through Slack. This will help you set up real-time alerts to ensure every modification in your function is visible to you and your team.
Step-by-step Guide
1. Create the Lambda function that will send notifications to Slack
Set the following configurations:
- Function name: SlackNotifLambdaUpdate (feel free to change this)
- Runtime: Python 3.13
Here’s the code that will be used to send notifications to Slack. Feel free to modify it based on your own preference
2. Create an EventBridge rule to detect update on Lambda function
- Go to Amazon EventBridge -> Rules.
- Click Create rule and enter a name (e.g., MonitorLambdaCodeChanges).
- Under Define pattern, select Event pattern and use the Custom pattern option.
- Copy and paste the following event pattern below:
{ "source": ["aws.lambda"], "detail-type": ["AWS API Call via CloudTrail"], "detail": { "eventSource": ["lambda.amazonaws.com"], "eventName": ["UpdateFunctionCode"], "requestParameters": { "functionName": ["ARN of Lambda function to be monitored"] } } }
- Add a target then select the Lambda function created above.
3. Set the following configurations for the Lambda function
- Add the following environmental variable:
SLACK_WEBHOOK_URL
– <your-slack-webhook-URL>
- Add ‘requests’ layer
- Make sure you downloaded first the
requests
layer from your local library
- Make sure you downloaded first the
- Add permission to invoke EventBridge rule
- Service: EventBridge (CloudWatch Events)
- Statement ID: invoke-eventbridgerule
- Principal: events.amazonaws.com
- Source ARN: <ARN of created EventBridge rule>
- Action: lambda:InvokeFunction
- Click Save
Expected Output:
After completing the steps above, let’s test if Slack sends a notification whenever we update the monitored Lambda function.Good job! Since Slack sends a notification displaying the Lambda function name and the user who edited it, you and your team will always stay informed about any changes and who made them. This will help identify potential issues and improve its reliability. With the proper integration of these AWS services and Slack, monitoring your deployed projects is now easier to achieve, giving you time to focus on more important tasks.