{"id":24835766,"url":"https://github.com/tobilg/nodejs-lambda-layer-builder","last_synced_at":"2025-10-15T22:11:37.178Z","repository":{"id":86825930,"uuid":"253241687","full_name":"tobilg/nodejs-lambda-layer-builder","owner":"tobilg","description":"Build custom AWS Lambda layers for Node","archived":false,"fork":false,"pushed_at":"2020-04-08T10:20:48.000Z","size":14,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T04:24:59.900Z","etag":null,"topics":["aws","aws-lambda-node","lambda","lambda-layers","nodejs"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tobilg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-05T13:29:35.000Z","updated_at":"2023-06-28T15:49:00.000Z","dependencies_parsed_at":"2023-07-16T14:16:42.390Z","dependency_job_id":null,"html_url":"https://github.com/tobilg/nodejs-lambda-layer-builder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tobilg/nodejs-lambda-layer-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobilg%2Fnodejs-lambda-layer-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobilg%2Fnodejs-lambda-layer-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobilg%2Fnodejs-lambda-layer-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobilg%2Fnodejs-lambda-layer-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tobilg","download_url":"https://codeload.github.com/tobilg/nodejs-lambda-layer-builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobilg%2Fnodejs-lambda-layer-builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018780,"owners_count":26086452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-lambda-node","lambda","lambda-layers","nodejs"],"created_at":"2025-01-31T04:51:42.827Z","updated_at":"2025-10-14T10:30:30.844Z","avatar_url":"https://github.com/tobilg.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nodejs-lambda-layer-builder\n\nCreates an AWS Lambda Layers structure that is **optimized** for: [Lambda Layer directory structure](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path), compiled library compatibility, and minimal file size.\n\n**Note: This script requires Docker and uses a container to mimic the Lambda environment. If you also want to use the publish.sh script, make sure you have the AWS CLI and jq installed as well**\n\n## Features\n\n- Builds either a zip file or a raw directory strucutre (e.g. if you want to use frameworks like Serverless for packaging) containing Node dependencies and places the libraries into the proper directory structure for lambda layers\n- Ensures compiled libraries are compatible with Lambda environment by using the [lambci/lambda](https://hub.docker.com/r/lambci/lambda) Docker container that mimics the lambda runtime environment\n- Allows specifying AWS Lambda supported Node versions: 8.10, 10.x and 12.x\n- Automatically searches for `package.json` file in several locations:\n  - Same directory as script\n  - Parent directory or script (useful when used as submodule)\n  - Function sub-directory of the parent directory\n\n## Installation\n\nThis function can be **cloned** for standalone use, into a parent repo or added as a **submodule**.\n\nClone for standalone use or within a repo:\n\n``` bash\n# If installing into an exisiting repo, navigate to repo dir\ngit clone --depth 1 https://github.com/tobilg/nodejs-lambda-layer-builder _build_layer\n```\n\nAlternatively, add as a submodule:\n\n``` bash\ncd {repo root}\ngit submodule add https://github.com/tobilg/nodejs-lambda-layer-builder _build_layer\n# Update submodule\ngit submodule update --init --recursive --remote\n```\n\n## Usage\n\n### Building the layer\n\n```text\n$ ./build.sh -h\nAWS Lambda Layer Builder for Node libraries\n\nUsage: build.sh [-l NODEJS_RUNTIME_VERSION] [-n NAME] [-r] [-h] [-v]\n  -l NODEJS_RUNTIME_VERSION     : Node runtime version to use: 8.10, 10.x, 12.x (default 10.x)\n  -n NAME                       : Name of the layer\n  -r                            : Raw mode, don't zip layer contents\n  -h                            : Help\n  -v                            : Display build.sh version\n```\n\n- Run the builder with the command `./build.sh` or `_build_layer/build.sh` if installed in sub-dir\n- It uses the first package.json file found in these locations (in order):\n  - Same directory as script\n  - Parent directory of script (useful when used as submodule)\n  - Function sub-directory of the parent directory (useful when used as submodule)\n- Optionally specify the Node runtime Version\n  - `-l NODEJS_RUNTIME_VERSION`: Node runtime version to use: 8.10, 10.x, 12.x (default `10.x`)\n  - `-n NAME`: Name of the layer\n\n### Publishing the layer\n\nYou can use the included `publish.sh` script to publish your newly built layer.\n\n```text\n$  ./publish.sh -h\nAWS Lambda Layer Publisher\n\nUsage: publish.sh [-l NODEJS_RUNTIME_VERSION] [-n NAME] [-b BUCKET_NAME] [-c] [-h] [-v]\n  -l NODEJS_RUNTIME_VERSION     : Node runtime version to use: 8.10, 10.x, 12.x (default 10.x)\n  -n NAME                       : Name of the layer\n  -b BUCKET_NAME                : Name of the S3 bucket to use for uploading the layer contents\n  -c                            : Create S3 Bucket for layer upload\n  -h                            : Help\n  -v                            : Display publish.sh version\n```\n\n- Run the publisher with the command `./publish.sh` or `_build_layer/publish.sh` if installed in sub-dir\n- Optionally specify the following flags\n  - `-l NODEJS_RUNTIME_VERSION`: Node runtime version to use: 8.10, 10.x, 12.x (default `10.x`)\n  - `-n NAME`: Name of the layer (should fit to what you used with `build.sh`)\n  - `-b BUCKET_NAME`: Name of the S3 bucket to use for uploading the layer contents\n  - `-c`: Flag for creating a S3 bucket for uploading the layer's contents (default name: `layer-uploads-$AWS_ACCOUNT_ID`)\n\n### How to create a Lambda layer for Node\n\nFor example, we would like to build a Node Lambda layer for the [sharp](https://www.npmjs.com/package/sharp) image processing module. This module needs some OS-specific (meaning: Amazon Linux) libraries, which means you can't just zip your `node_modules` directory on a Mac or Windows machine.\n\nFirst step is to create a `package.json` in the same folder you cloned or checked out this repo. \n\n```javascript\n{\n    \"name\": \"sharp-layer\",\n    \"description\": \"Dependencies for building the sharp layer\",\n    \"version\": \"0.1.0\",\n    \"license\": \"MIT\",\n    \"dependencies\": {\n      \"sharp\": \"0.25.2\"\n    }\n}\n```\n\nSecond step is to run the `build.sh` script with the proper parameters:\n\n```bash\n$ ./build.sh -n sharp\n```\n\nThis will create a zip file named `sharp_node10.x.zip`.\n\nThird step is to publish the newly created layer contents to AWS via the `publish.sh` script:\n\n```bash\n$ ./publish.sh -n sharp -c\n```\n\nThis will create a new S3 bucket named `layer-uploads-$AWS_ACCOUNT_ID`, upload the zip file created in step two, and trigger the layer publishing. The output will be something like \n\n```text\nCreating S3 bucket\nLayer file sharp_node10.x.zip found\nUploading layer file to S3\nPublishing layer\nPublish successful\nLayer ARN: arn:aws:lambda:us-east-1:$AWS_ACCOUNT_ID:layer:sharp-lambda-layer:1\n```\n\nwhere `$AWS_ACCOUNT_ID` is your AWS account id.\n\n### Custom cleaning logic\n\nYou can edit the `_clean.sh` file if you want to add custom cleaning logic for the build of the Lambda layer. The above part of the file must stay intact:\n\n```bash\n#!/usr/bin/env bash\n# Change to working directory\ncd $1\n# ----- DON'T CHANGE THE ABOVE -----\n\n# Cleaning statements\n# ----- CHANGE HERE -----\nrm test.xt\n```\n\nThe `_make.sh` script will then execute the commands after the Python packages have been installed.\n\n## Uninstall\n\nIf installed as submodule and need to be removed:\n\n```bash\n# Remove the submodule entry from .git/config\ngit submodule deinit -f $submodulepath\n# Remove the submodule directory from the superproject's .git/modules directory\nrm -rf .git/modules/$submodulepath\n# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule\ngit rm -f $submodulepath\n# remove entry in submodules file\ngit config -f .git/config --remove-section submodule.$submodulepath\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobilg%2Fnodejs-lambda-layer-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftobilg%2Fnodejs-lambda-layer-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobilg%2Fnodejs-lambda-layer-builder/lists"}