AWS Lambda: how to share code in a monorepo by@theburningmonk

AWS Lambda: how to share code in a monorepo

June 30th 2019 4,168 reads
Read on Terminal Reader
Open TLDR
react to story with heart
react to story with light
react to story with boat
react to story with money
Yan Cui is an AWS Serverless Hero and author of Production-Ready Serverless. He has run production workload at scale in AWS for nearly 10 years. Check out his new course, Complete Guide to AWS Step Functions: How to use Step Functions effectively in a monorepo. Get 40% off the face price with the code ytcui. Get your copy here. You can also get your copy of the book here. It's also available on Amazon.com and Lumigo.com.
image
Yan Cui HackerNoon profile picture

Yan Cui

AWS Serverless Hero. Independent Consultant. Developer Advocate at Lumigo.

twitter social icon

A while back, a client asked me “how can I share business logic between services in a Node.js monorepo?”. So here it is!

Encapsulate the shared business logic into modules, and put them in a separate folder.

image

In the Lambda handler functions, reference the shared modules using relative paths.

image

Use webpack to resolve and bundle them into the deployment package. If you use the Serverless framework, then check out the serverless-webpackplugin. For example:

image

Deploy every service on every commit.You can do this with a simple script like the following.

image

To see how everything fits together, check out this demo repo. It has CI/CD set up already through drone.io and you can see a recent deployment of all the services in the monorepo here.

But wait! How do I choose between having a monorepo vs a repo per service?

Don’t worry, I’ve got you covered for that too ;-) You can read about my thoughts on the two approaches here.

Hi, my name is Yan Cui. I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.

You can contact me via EmailTwitter and LinkedIn.

Check out my new course, Complete Guide to AWS Step Functions.

In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, design patterns and best practices.

Get your copy here.

image

Come learn about operational BEST PRACTICES for AWS Lambda: CI/CD, testing & debugging functions locally, logging, monitoring, distributed tracing, canary deployments, config management, authentication & authorization, VPC, security, error handling, and more.

You can also get 40% off the face price with the code ytcui.

Get your copy here.

Originally published at https://theburningmonk.com on June 29, 2019.

react to story with heart
react to story with light
react to story with boat
react to story with money
L O A D I N G
. . . comments & more!