Archive

The Dulin Report

Browsable archive from the WordPress export.

Results (24)

Should today’s developers worry about AI code generators taking their jobs? Dec 11, 2022 Book review: Clojure for the Brave and True Oct 2, 2022 Stop Shakespearizing Sep 16, 2022 Using GNU Make with JavaScript and Node.js to build AWS Lambda functions Sep 4, 2022 Monolithic repository vs a monolith Aug 23, 2022 Scripting languages are tools for tying APIs together, not building complex systems Jun 8, 2022 Good developers can pick up new programming languages Jun 3, 2022 There is no such thing as one grand unified full-stack programming language May 27, 2022 TypeScript is a productivity problem in and of itself Apr 20, 2022 Tools of the craft Dec 18, 2021 Node.js and Lambda deployment size restrictions Mar 1, 2021 What programming language to use for a brand new project? Feb 18, 2020 Using Markov Chain Generator to create Donald Trump's state of union speech Jan 20, 2019 The religion of JavaScript Nov 26, 2018 TypeScript starts where JavaScript leaves off Aug 2, 2017 Node.js is a perfect enterprise application platform Jul 30, 2017 Copyright in the 21st century or how "IT Gurus of Atlanta" plagiarized my and other's articles Mar 21, 2017 Collaborative work in the cloud: what I learned teaching my daughter how to code Dec 10, 2016 Amazon Alexa is eating the retailers alive Jun 22, 2016 JavaScript as the language of the cloud Feb 20, 2016 What Every College Computer Science Freshman Should Know Aug 14, 2015 The Three Myths About JavaScript Simplicity Jul 10, 2015 Big Data is not all about Hadoop May 30, 2015 How We Overcomplicated Web Design Oct 8, 2014

Using GNU Make with JavaScript and Node.js to build AWS Lambda functions

September 4, 2022

GNU Make is an automation tool that produces executables and other non-source assets. It can be used to coordinate a variety of tasks, from the compilation of code to the transcoding of media files.

Make uses a file called Makefile to determine what needs to be built when it needs to be built, and how.

In the upcoming series of articles, I will show examples of using make to orchestrate builds of JavaScript apps. Today, I want to talk about using make to build Node.js-based Lambda functions.

A Node.js - based Lambda function is deployed as a zip file to AWS. It has a single main entry point, typically index.js, and it has a handler function. I won't get into the details of building Node.js Lambdas because you can find many more details in AWS Documentation.

Suppose you have a Lambda structured as follows:
./lambda
index.js
package.json
Makefile

Your goal is to rebuild the lambda.zip file only if the source files change. Your Makefile will look like this:
lambda.zip: *.js package.json
npm install
zip -r lambda.zip *.js *.json node_modules/*

If you modify any JavaScript files, or package.json, and type make, it will determine that lambda.zip is outdated and rebuild it.

What you also want to do is create a clean target:
clean: 
rm -f lambda.zip

Finally, you can add a deploy target to deploy the zip file to AWS:
deploy: lambda.zip
$(info "Run AWS Commands to deploy this Lambda")

Note how deploy target depends on lambda.zip target — if there is no zip file, there is nothing to deploy. I will leave it up to you to figure out how to deploy Node.js AWS Lambda functions

The complete Makefile now looks like this:

lambda.zip: *.js package.json
npm install
zip -r lambda.zip *.js *.json node_modules/*

clean:
rm -f lambda.zip

deploy: lambda.zip
$(info "Run AWS Commands to deploy this lambda")

Some final thoughts


You can find more documentation on make here. make is available on UNIX-like operating systems, i.e. Linux and Mac OS X, and can be installed on Windows.

In upcoming posts, I will discuss using make for Node.js Docker services and front-ends.