From e5bf5d9259f05314a65a6c500bcd5c4cc52508f6 Mon Sep 17 00:00:00 2001 From: brunocalderon Date: Thu, 24 Oct 2019 21:31:28 -0300 Subject: [PATCH] Initial commit --- .github/FUNDING.yml | 1 + LICENSE | 21 ++++++++++++++++++++ README.md | 35 +++++++++++++++++++++++++++++++++ create_layer.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++ update_layer.sh | 32 ++++++++++++++++++++++++++++++ 5 files changed, 137 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 create_layer.sh create mode 100644 update_layer.sh diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..a2fa627 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +patreon: springsdigital diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0265398 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Springs Digital SpA. https://springsdigital.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d36bc3c --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# LayerizeJS +A set of bash scripts from [Springs Digital](https://springsdigital.com) to automate the creation, update and upload of Lambda Layers in Node.js + +### Installation +Simply get the files via the terminal +``` +curl 'https://raw.githubusercontent.com/springsdigital/layerizejs/master/create_layer.sh' > create_layer.sh && \ +curl 'https://raw.githubusercontent.com/springsdigital/layerizejs/master/update_layer.sh' > update_layer.sh +``` + +## Usage + +### Creating a new layer + +Use `bash create_layer.sh` to create a new layer. +The script will ask for the package name. +If the package is scoped, you will have to provide the scoped name (ex: @scope/package) + +### Updating a layer +Use `bash update_layer.sh` to update a layer. +You will need to provide the module name. If the module is scoped, provide the module name without scope (ex: ~~@scope/~~ **package**) + +> It's important to note that you previously need to have the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html) installed and configured. + +## Credits + +Thank you [contributors](https://github.com/springsdigital/layerizejs/graphs/contributors)! + +Springs Digital + +LayerizeJS is maintained by [Springs Digital](https://springsdigital.com). + +## License + +LayerizeJS is © of Springs Digital Spa. It is free software and may be redistributed under the terms specified in the [LICENSE](https://github.com/springsdigital/layerizejs/blob/master/LICENSE). diff --git a/create_layer.sh b/create_layer.sh new file mode 100644 index 0000000..5e417c9 --- /dev/null +++ b/create_layer.sh @@ -0,0 +1,48 @@ +#!/bin/bash +read -p "What's the package name?: " packagename +if [ -d "$packagename" ] + then + echo "This lambda layer already exists, use upload_layer.sh" + exit 1 +fi +echo "Creating a lambda layer package for $packagename" +mkdir "$packagename" +cd "$packagename" +mkdir nodejs +cd nodejs +npm init -y >/dev/null +printf "\033[1;32mCreated package.json ✔\033[0m\n" +echo "Is the package scoped?" +read -p "[Y/n]:" scoped +if [ $scoped = Y ] || [ $scoped = y ] || [ $scoped = Yes ] || [ $scoped = yes ] + then + echo "Provide the full package with scope. Example: @scope/package" + read -p "@scope/package: " scopedpackage + echo "This is a scoped package. Installing $scopedpackage" + npm i $scopedpackage &>/dev/null + printf "\033[1;32mInstalled $scopedpackage ✔\033[0m\n" + else + echo "This is a not scoped package. Installing $packagename" + npm i $packagename &>/dev/null + printf "\033[1;32mInstalled $packagename ✔\033[0m\n" +fi +cd .. +zip -r nodejs.zip nodejs/ >/dev/null +printf "\033[1;32mLayer created ✔\033[0m\n" +echo "Do you want to upload the layer?" +read -p "[Y/n]:" upload +if [ $upload = Y ] || [ $upload = y ] || [ $upload = Yes ] || [ $upload = yes ] + then + echo "Uploading layer" + aws lambda publish-layer-version --zip-file fileb://nodejs.zip --cli-input-json '{ + "LayerName": "'$packagename'", + "Description": "'$packagename' for nodejs", + "CompatibleRuntimes": [ + "nodejs10.x" + ] + }' >/dev/null + printf "\033[1;32mUploaded ✔\033[0m\n" + echo "The $packagename lambda layer was successfully created and uploaded" + else + echo "Goodbye" +fi diff --git a/update_layer.sh b/update_layer.sh new file mode 100644 index 0000000..9bc6b70 --- /dev/null +++ b/update_layer.sh @@ -0,0 +1,32 @@ +#!/bin/bash +read -p "What's the layer name (without lambda-layer-nodejs)?: " packagename +echo "Updating a lambda layer package for $packagename" +cd "$packagename" +cd nodejs +npm update >/dev/null +printf "\033[1;32mUpdated ✔\033[0m\n" +echo "Packing layer" +cd .. +if [ -f nodejs.zip ] + then + rm nodejs.zip >/dev/null +fi +zip -r nodejs.zip nodejs/ >/dev/null +printf "\033[1;32mPacked ✔\033[0m\n" +echo "Do you want to upload the layer?" +read -p "[Y/n]:" upload +if [ $upload = Y ] || [ $upload = y ] || [ $upload = Yes ] || [ $upload = yes ] + then + echo "Uploading layer" + aws lambda publish-layer-version --zip-file fileb://nodejs.zip --cli-input-json '{ + "LayerName": "'$packagename'", + "Description": "'$packagename' for nodejs", + "CompatibleRuntimes": [ + "nodejs10.x" + ] + }' >/dev/null + printf "\033[1;32mUploaded ✔\033[0m\n" + echo "The $packagename lambda layer was successfully updated and uploaded" + else + echo "Goodbye" +fi