AWS Lambda setup: create Lambda function to connect Snyk to Slack
AWS Lambda functions are used to connect Snyk to Slack because these functions are an inexpensive and efficient way of running code triggered by events, for example when there is a new Snyk vulnerability.
Note: If publishing the Lambda function through API Gateway, both must be configured in the same region. You can check this on the top right of the AWS Console.
Start by creating a zip file containing the code for the function and the necessary dependencies.
Save these two code blocks as package.json and index.js
package.json (modify to fit any other dependencies needed for your code, the dependencies needed are axios and crypto)
index.js
Use the following commands in your terminal: -
cd /path/to/snyk/folder
(to navigate inside the folder where you stored the two files) -npm install
(to set up a package. json file) -cd ..
(to navigate back to previous folder) -zip -r snyk.zip /path/to/snyk/folder
(to zip snyk into a file which can be uploaded to AWS Lambda)
To create an AWS Lambda function, follow these steps:
Go to the AWS Console.
Navigate to Lambda.
Click Create function.
Choose Node.js 16.x for the Runtime.
Choose X86_64 for the Architecture.
If publishing the Lambda function through API Gateway, add or create a role with the default policy AmazonAPIGatewayInvokeFullAccess to interact with the AWS API Gateway.
Verify that the AWS Console screen shows these entries:
Click Create Function and when the function is ready click Upload from .zip file and
Verify that the code you entered is displayed in the Code Source.
In the code, modify the
slackWebhookUrl
to match your Slack webhook URL.For more information on the script you have pasted, go to Configure the AWS Lambda Script.
Last updated