(See accompanying blog post at http://mikestokes.co/aws/2015/03/12/easy-testing-of-amazon-lambda-micro-services/
Boilerplate for AWS Lambda function trigger by any supported S3 event (e.g. file update or upload (put/post)). This repository also includes a test harness to help debug the Lambda function locally.
- Clone this repository.
- Run
npm install
from the command line to install the Node dependencies (described in package.json). - Edit the function in s3-event.js (you may also want to rename the file to something more meaningful for your micro-service - if you do, also update the "require" within the test.js file).
One of the benefits of this boilerplate is to test locally. To do this once you've made your changes, simply run:
> node test.js
Once you're happy, deploy to AWS Lambda (it's free in most cases):
- Zip CONTENTS of this folder (not the folder - just the contents).
- From AWS, create a new AWS Lambda function with a event source e.g S3, DynamoDB, Kinesis.
- From AWS, go to the Lambda function you just created and click the Edit/Test button.
- Click the Upload button and choose the Zip file you just created.
- If you want to adjust the RAM for the Lambda function, click "Change advanced settings" and adjust the Memory setting.
- If you want to adjust the Timeout for the Lambda function, click "Change advanced settings" and adjust the Timeout(s) setting.
- The AWS Lambda configuration for "File name" should be the same as your main file containing the Lambda function in the Zip.
- The AWS Lambda configuration for "Handler name" should be the same as yourentry point function in the file "File name" above e.g. if the file exports "exports.myFunction" then the "Handler name" should be myFunction.
- Save your changes.