Starter Projects For AWS Lambda Using NodeJS And Java
Today I want to show you three starter projects for AWS Lambda using CloudFormation and SAM - Serverless Application Model. If you’re new to Lambda, check out my guide on important things to consider when developing Lambda functions and the benefits of infrastructure as code for serverless applications. I always like if I have some boilerplate code and can get started quickly without copying code or project structures from an existing (and mature) project. Therefore I thought it’s good to have them in one repository. You can find them on GitHub. The projects can be used for NodeJS and Java. Also one project contains both: usage of Java and NodeJS Lambdas in one CloudFormation template.
Note: All projects contain a deploy.sh file which you can run. Each deploy file is using the AWS CLI to package and deploy the CloudFormation template using aws cloudformation package and aws cloudformation deploy, so you first have to add an existing S3 bucket (where you have access to!) to deploy.sh.
-
NodeJS Starter Project: Spins up a simple NodeJS Lambda function which is available under the Api path
/hello. Link -
Java Starter Project: Spins up a simple Java Lambda function using the
RequestStreamHandlerinterface. The project has added Jackson to parse input and output from/to a stream. Link -
NodeJS and Java Starter Project: Spins up two simple AWS Lambda functions: one for NodeJS and one for Java. The neat point is here that it’s possible to declare both AWS Lambda functions for NodeJS and Java in one CloudFormation template. You just have to use different values for
Handler,RuntimeandCodeUri. In the background, the AWS CLI packages and uploads both artifacts to S3. The functions are available under the Api path/nodeand/java. For more modern bundling approaches with AWS CDK, check out my guide on bundling Lambda functions within CDK constructs. Link
Example code how to use NodeJS and Java in one project:
# Declare other stuff...
Resources:
NodeFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs6.10
Timeout: 10
CodeUri: ./node-backend/target
Policies:
- AWSLambdaBasicExecutionRole
Events:
GetNodeResource:
Type: Api
Properties:
Path: /node
Method: get
JavaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: de.sebastianhesse.examples.JavaHelloWorldHandler
Runtime: java8
Timeout: 10
CodeUri: ./java-backend/target/target.jar
Policies:
- AWSLambdaBasicExecutionRole
Events:
GetJavaResource:
Type: Api
Properties:
Path: /java
Method: get Related Articles
Fast AWS Lambda Code Updates And Improved Lambda Logs
Speed up AWS Lambda code updates from 2.5 minutes to 15 seconds with lambda-updater. Plus, easily trace logs across multiple Lambda functions using lambdalogs tool.

Using Spring Boot On AWS Lambda: Clever or Dumb?
Should you run Spring Boot on AWS Lambda? Detailed analysis of advantages, disadvantages, cold start impact, and GraalVM alternatives for Java serverless functions.

Remove old CloudWatch log groups of Lambda functions
Automatically remove orphaned CloudWatch log groups from deleted Lambda functions. Python script using CloudFormation stack to identify and clean up old logs.

Shut down CloudFormation stack resources over night using AWS Lambda
Save AWS costs by automatically shutting down development stack resources overnight using Lambda functions and CloudFormation parameters. Reduce expenses by 50% or more.