Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building Serverless Architectures

You're reading from   Building Serverless Architectures Unleash the power of AWS Lambdas for your applications

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781787129191
Length 242 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Cagatay Gurturk Cagatay Gurturk
Author Profile Icon Cagatay Gurturk
Cagatay Gurturk
Arrow right icon
View More author details
Toc

Writing the Lambda Handler class with injected dependency

The Handler class is the entrance point for our project because AWS Lambda runtime calls it first. You already know that AWS will invoke the handleRequest method for each invocation of Lambda function. To create the object, Lambda runtime uses the default constructor of the class where the Handler is. So, to inject dependencies to our class, we will use this knowledge and initiate the injection when the default constructor is called. Moreover, Lambda runtime will keep a cached copy of an object once it is initiated and shared among different invocations of your Lambda function. It means that the injection will not happen for every invocation and, although we cannot predict when a new instance of Handler class will be created, will be cached.

We can start adding a Guice injector as a static field in the Handler class:

public...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image