{"id":20896415,"url":"https://github.com/elviswolcott/lambda-git","last_synced_at":"2026-04-20T13:34:03.824Z","repository":{"id":66059419,"uuid":"235205534","full_name":"elviswolcott/lambda-git","owner":"elviswolcott","description":"Create Lambda layers with git binaries","archived":false,"fork":false,"pushed_at":"2020-01-26T16:22:51.000Z","size":77,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T12:31:53.990Z","etag":null,"topics":["aws","git","lambda","layer"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elviswolcott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-01-20T21:49:51.000Z","updated_at":"2020-01-31T06:10:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"68bbdb9d-b8fc-4cf4-8675-738269322966","html_url":"https://github.com/elviswolcott/lambda-git","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elviswolcott%2Flambda-git","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elviswolcott%2Flambda-git/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elviswolcott%2Flambda-git/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elviswolcott%2Flambda-git/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elviswolcott","download_url":"https://codeload.github.com/elviswolcott/lambda-git/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243285598,"owners_count":20266845,"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","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","git","lambda","layer"],"created_at":"2024-11-18T10:35:31.460Z","updated_at":"2025-12-27T17:19:24.542Z","avatar_url":"https://github.com/elviswolcott.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Travis (.com) build status](https://img.shields.io/travis/com/elviswolcott/lambda-git?logo=travis)](https://travis-ci.com/elviswolcott/lambda-git)\n# `git` layer for AWS Lambda\n\n\u003e Build Lambda layers to add git to your functions\n\n# Usage\n\n\u003e Note: The binaries are built against `amazonlinux:2` and will work with `nodejs12.x`, `nodejs10.x`,`python3.8`, and `java11`. If you are using a runtime that uses Amazon Linux, modify `Dockerfile` build `FROM amazonlinux:1`. See [Runtime OS Versions](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) if you are not sure which OS your runtime uses.\n\n\u003e Warning: The layer is missing some git components that are not well suited to use in Lambda (i.e. imap-send or gui). If you need different components, `/scripts/clean-git.sh` can be modified to not remove them.\n\n1. Add the layer to your Lambda function. The [version history](VERSIONS.md) includes all of the available ARNs.\n1. Add the environment variable `GIT_EXEC_PATH` with a value of `/opt/libexec/git-core`\n1. The git binary will be available as `/opt/bin/git`.\n\nExample: Cloning a repository in NodeJS\n```js\nconst child_process = require('child_process');\n\nexports.handler = async (event) =\u003e {\n    const result = child_process.execSync('cd /tmp ; /opt/bin/git clone https://github.com/octocat/Hello-World.git').toString();\n    const response = {\n        statusCode: 200,\n        body: result,\n    };\n    return response;\n};\n```\n\nIn lambda `/tmp` is writeable and preserved as long as a function environment is reused.\nIt is recommended for your function to begin cloning any repositories into `/tmp` while it performs any additional setup. \nYou can take advantage of this by checking if the repository exists already and simply pulling new changes instead of cloning when your execution environment is reused.\n\n# Deployment\n\nWhen a new tag is published to the `master` branch, Travis builds `git` from source in a container running `amazonlinux:2`.\n\nThe `git` binary is zipped and then released as a layer using the AWS CLI.\n\nIn the future, a Lambda will run using the layer to monitor for tags on the source repository. This will the layer to be updated as soon as a new version of git is released.\n\n## Setting up your own deployments\n\nThe deploy scripts require you to be signed into the AWS CLI. \nIf your account does not have the Honk Kong and Bahrain regions enabled, the deploy script will fail unless you modify the `get_regions` function to remove them.\n\nThis policy provides the necessary permissions. \n\n```json\n{\n    \"Version\": \"2012-10-17\",\n    \"Statement\": [\n        {\n            \"Sid\": \"VisualEditor0\",\n            \"Effect\": \"Allow\",\n            \"Action\": [\n                \"lambda:PublishLayerVersion\",\n                \"lambda:AddLayerVersionPermission\"\n            ],\n            \"Resource\": \"*\"\n        },\n        {\n            \"Sid\": \"VisualEditor1\",\n            \"Effect\": \"Allow\",\n            \"Action\": \"ssm:GetParametersByPath\",\n            \"Resource\": \"arn:aws:ssm:*:*:parameter/aws/service/global-infrastructure/services/lambda/regions\"\n        }\n    ]\n}\n```\n\nYou'll want to modify the deploy script so that it doesn't attempt to commit changes to `VERSIONS.md`.\n\n# Methodology\nIt turns out getting a git binary onto Lambda isn't easy.\n\nNormally the best way to get a binary into your Lambda is by compiling with the `-static` flag to include shared libraries in the executable. \nUnfortunately, git uses NSS, and resultingly cannot be compiled with the `-static` flag.\nWhile it would also be possible to obtain git through `yum` or `yumdownloader`, it ends up being a pain to work with and Amazon often does not provide the most recent version until a few months after release.\n\nThe approach used here is to build git from source in a Docker container. To reduce size, the `clean-git` script does some housekeeping like removing components that aren't needed for use in Lambda, replacing duplicate files with a symbolic link to a single copy, identifying shared libraries and making copies. These files are then zipped and copied out of the container as the Lambda Layer.\n\nA benefit of this approach is that it is possible to modify the build process to exclude elements of git that you do not require. It can also be quickly modified to add other programs to the layer or create layers for arbitrary binaries. While it would be easier to just install through a package manager and copy everything from the container out, this approach ensures there are not unneeded libraries or other files and makes it possible to always have the latest version available.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felviswolcott%2Flambda-git","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felviswolcott%2Flambda-git","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felviswolcott%2Flambda-git/lists"}