JavaScript code for an AWS Lambda function which is receives Square webhook event notifications and saves them to an AWS SQS.
Flow:
API Gateway > Lambda function > SQS
- The AWS HTTP API Gateway is what is used for the Square webhook notification URL
- The gateway simply passes the request to the Lambda function through integration
- Also using AWS Parameter Store to store the Square SIGNATURE_KEY and thus needed to use the extension "AWS Parameters and Secrets Lambda Extension"
- Due to using Square SDK which is not available directly in AWS, need to zip up Square SDK with the JavaScript code and upload it to the AWS Lambda function
This Lambda function has a few uses:
- Receive the POST request (event) from the API gateway which was sent by Square
- Verify and Validate the Square Event Notification
- Get the Queue URL for an existing SQS and then send the request (event) body to the queue to be processed separately
- Send a response to the API gateway and thus to Square
to use clone, modify lambdaSquareDeploy.js as needed, and then run the following commands:
npm run build
npm run package
then you can push the new ZIP to an existing Lambda function using AWS CLI like so:
aws --profile <YOUR_PROFILE> lambda update-function-code --function-name <YOUR_FUNCTION> --zip-file fileb://lambdaSquareDeploy.zip
or can manually upload the lambdaSquareDeploy.zip through the AWS console.