This simple guide shows a step-by-step process for deploying a simple Node.js microservice to AWS Lambda using Claudia.js.
- AWS account with access to IAM and Lambda
- Node.js 6
If you’re completely new to using AWS from Node.js, check out Installing and configuring Claudia.js for information on how to set up access credentials.
Deploying your first AWS Lambda function
Create a new NPM project, and just give it a descriptive name (eg claudia-test):
Install Claudia.js as a global NPM utility:
lambda.js. For detailed information on the Lambda API, check out the Node.js Lambda Programming Model on AWS.
Send this function to AWS using Claudia. You will need to specify the main method for the Lambda to execute (in the Lambda terminology, that’s the
handler). The syntax is
module.method. Because the main micro-service module is
lambda.js, and the method is
handler, this argument should be
lambda.handler. (Note that you need to use the module name, not the file name).
When the deployment completes, Claudia will save a new file
claudia.json in your project directory, with the function details, so you can invoke and update it easily.
You can now invoke the Lambda function directly from the console:
You should the following response:
This means that the function was deployed to AWS, and is now ready to process events. For something more serious, you can connect this Lambda to various event sources, such as S3 file systems, SNS queues, CloudWatch log events, DynamoDB streams and so on.
For some nice examples of processing various event types, see the Claudia Example Projects
Updating an existing Lambda function
Let’s make something a bit more dynamic. We’ll send it a name, and expect a greeting in return. We’ll also log the request using CloudWatch. Modify the
Send the new version up to AWS:
Now create a test event with the request data, for example in a file called
Now invoke the Lambda function with the test event:
The response should come out with the name from the event:
You can now check out your logs using AWS Web Console or the AWS command-line tools:
Logging events is a good way to discover the right structure when you connect it to a new event source.
Claudia has lots of options to customise deployments. Check out Including/Excluding files from deployment for information on how to control which files get sent to AWS, and the Command Line Reference for information on the various options you can use when deploying your function.
For other tasks, see the list of Tutorials and Guides