The reason behind this AWS Lambda function is to create a general-purpose function that can capture the payload of an Amazon SNS message and log it to an S3 bucket.
Amazon SNS provides a mechanism for notifying interested subscribers of messages received on a topic. One of the subscriber types are is an AWS Lambda function.
This lambda function, once deployed, expects to be invoked by an SNS topic publish event. On invoking the function, the payload of the SNS message is inspected and written out to the S3 bucket defined in the bucketName
environment variable of the function.
The flow is depicted below:
The source code is based on a NodeJS package structure and uses NPM to import libraries that facilitate certain core functions. The following are the key files needed:
- src/lambda.js: The lambda function to transform the payload
- package.json: Defines the packaging tasks and the npm modules in use
- Need to create an AWS account
- Need to setup AWS CLI with the credentials of your AWS account
- NodeJS and NPM need to be installed
The SAM template file, template.yaml
defines the lambda to be deployed. SAM will subscribe the lambda to the SNS Topic, and establish all IAM permissions to receive messages and write to the S3 bucket.
- Clone or fork this repository
- Ensure that you've followed the Requirements section above
Runnpm run build
to install dependencies, package the Lambda function and node modules in a zip and finally deploys the Lambda function to AWS using the AWS CLI.- Run
sam deploy --config-env {environment}
- environment parameters are configured in samconfig.toml
See LICENSE for further details.