This demonstrates how to deploy a NodeJS function running on AWS Lambda using the Serverless Framework. The deployed function will accept a JSON payload as a POST request and send an alert to a Slack channel if the payload matches the desired criteria.
- Create an AWS account
- Create an IAM user for deploying with serverless
- Run
npm deploy
to push the code to Lambda - In AWS, add API Gateway as a trigger for your Lambda function
- In your API Gateway, update the function route to POST
- Enable IAM authorisation for your API to control access
- Setup Slack (see below)
- Add your Slack webhook URL as an environment variable to your Lambda function
Before we can send alerts to Slack, we need to set up an incoming webhook integration in Slack. To do this, follow the steps below:
- Go to https://api.slack.com/apps and create a new app.
- Under the "Features" tab, click on "Incoming Webhooks" and turn it on.
- Click on "Add New Webhook to Workspace" and select the channel you want to post alerts to.
- Copy the webhook URL.
You can run the tests for this function locally:
npm run test