├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md └── make-layer /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Layer Builder 2 | 3 | 4 | If you've ever needed to build a Lambda layer 5 | quickly and easily, this tool is for you. 6 | 7 | 8 | ## Prerequisites 9 | 10 | * [Docker](https://www.docker.com/products/docker-desktop) 11 | * [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) 12 | 13 | 14 | ## Installation 15 | 16 | Copy the `make-layer` file to a location on your path, e.g. `cp make-layer /usr/local/bin/`. 17 | 18 | Download and install with a single command by copying and pasting the following into a terminal: 19 | 20 | ```bash 21 | INSTALL_LOC=/usr/local/bin/make-layer; curl https://raw.githubusercontent.com/aws-samples/aws-lambda-layer-builder/main/make-layer > $INSTALL_LOC; chmod +x $INSTALL_LOC 22 | ``` 23 | 24 | 25 | ## Usage 26 | 27 | This tool can either take a list of packages to include in the layer, 28 | or a package manifest file valid for the specified runtime. It assumes 29 | the AWS CLI is already properly configured. 30 | 31 | Run `make-layer` without parameters for full usage instructions. 32 | 33 | ### Manifest File 34 | 35 | ```bash 36 | make-layer NAME RUNTIME MANIFEST 37 | ``` 38 | 39 | * `NAME` is a valid Lambda layer name (letters, numbers, hyphens, and underscores) 40 | * `RUNTIME` is a valid Lambda runtime identifier (e.g. `nodejs14.x`, `python3.8`) 41 | * `MANIFEST` is the full path and filename of a valid manifest file. The following 42 | types are supported: 43 | * Node.js: [`package.json`](https://docs.npmjs.com/files/package.json/) 44 | * Python: [`requirements.txt`](https://pip.pypa.io/en/stable/user_guide/#requirements-files) 45 | 46 | If the manifest file is not found the parameters are presumed to be explicit package names. 47 | 48 | ### Explicit List 49 | 50 | ```bash 51 | make-layer NAME RUNTIME PACKAGE_1 [PACKAGE_2] ... 52 | ``` 53 | 54 | * `PACKAGE_1`, `PACKAGE_2`, etc. are the packages to be installed. 55 | 56 | ## To-Do 57 | 58 | * Add parameter for AWS profile to use (currently uses default, or honors AWS_PROFILE) 59 | * Add support for additional runtimes 60 | 61 | 62 | ## Contributing 63 | 64 | Pull requests are welcomed. Please review the [Contributing Guidelines](CONTRIBUTING.md) 65 | and the [Code of Conduct](CODE_OF_CONDUCT.md). 66 | 67 | 68 | ## Security 69 | 70 | See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. 71 | 72 | 73 | ## Authors 74 | 75 | * Drew Mullen (drmullen@amazon.com) 76 | * Jud Neer (judneer@amazon.com) 77 | 78 | 79 | ## License 80 | 81 | This project is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file for details. 82 | -------------------------------------------------------------------------------- /make-layer: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | 5 | usage() { 6 | echo "AWS Lambda Layer Builder" 7 | echo "------------------------" 8 | echo "make-layer NAME RUNTIME PACKAGE_1 [PACKAGE_2] ..." 9 | echo "make-layer NAME RUNTIME MANIFEST" 10 | echo "" 11 | echo "Currently supported runtimes: nodejs*, python*" 12 | } 13 | 14 | 15 | if [[ "$#" -lt 3 ]]; then 16 | usage 17 | exit 1 18 | fi 19 | 20 | name="${1}" 21 | runtime="${2}" 22 | manifest="${3}" 23 | 24 | if test -f "$manifest"; then 25 | packages="${@:4}" 26 | else 27 | manifest="" 28 | packages="${@:3}" 29 | fi 30 | 31 | 32 | output_folder="$(mktemp -d)" 33 | docker_image="public.ecr.aws/sam/build-$runtime:latest" 34 | volume_params="-v $output_folder:/layer" 35 | 36 | if [[ $runtime == node* ]]; then 37 | 38 | package_folder="nodejs/" 39 | mkdir -p "$output_folder/$package_folder" 40 | if [[ -n "$manifest" ]]; then 41 | cp "$manifest" "$output_folder/$package_folder/package.json" 42 | fi 43 | install_command="pushd $package_folder; npm install; npm install --save $packages; popd" 44 | volume_params="$volume_params -v $HOME/.npmrc:/root/.npmrc" 45 | 46 | elif [[ $runtime == python* ]]; then 47 | 48 | package_folder="python/lib/$runtime/site-packages/" 49 | if [[ -n "$manifest" ]]; then 50 | cp "$manifest" "$output_folder/requirements.txt" 51 | else 52 | touch "$output_folder/requirements.txt" 53 | fi 54 | install_command="pip install -r requirements.txt -t $package_folder $packages" 55 | volume_params="$volume_params -v $HOME/.config/pip:/root/.config/pip" 56 | 57 | else 58 | 59 | usage 60 | exit 1 61 | 62 | fi 63 | 64 | 65 | echo "Building layer" 66 | zip_command="zip -r layer.zip *" 67 | docker run --rm $volume_params -w "/layer" "$docker_image" /bin/bash -c "$install_command && $zip_command" 68 | 69 | 70 | pushd "$output_folder" 71 | echo "Uploading layer $name to AWS" 72 | aws lambda publish-layer-version --layer-name "$name" --compatible-runtimes "$runtime" --zip-file "fileb://layer.zip" 73 | echo "Upload complete" 74 | popd 75 | 76 | 77 | echo "Cleaning up" 78 | rm -rf "$output_folder" 79 | 80 | 81 | echo "All done. Enjoy your shiny new Lambda layer!" 82 | --------------------------------------------------------------------------------