Build Lambda function with Makefile


Add a Metadata property to the function that you want to build in a custom way:

Type: AWS::Serverless::Function
BuildMethod: makefile

Inside the Makefile add a command named as the function resource is prefixed by "build-":

npm ci
NITRO_PRESET=node npx nuxt build
cp -r .output/ $(ARTIFACTS_DIR)/.output/
cp lambda.js $(ARTIFACTS_DIR)/lambda.js

The ARTIFACTS_DIR directory is managed by SAM, the code will be moved to a temporary position (under /tmp or inside a docker container), Make file command will be executed. SAM expect you copy release files into ARTIFACTS_DIR, then compressed as ZIP archive and used as Lambda source code artifact.

Originally written on Mar 2, 2023.