Last active
August 18, 2021 05:51
-
-
Save Jehong-Ahn/1f434426e8972dda05ce6ff2ac4834b7 to your computer and use it in GitHub Desktop.
Publish AWS Lambda Layer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
packages=$1 | |
select="select(.key==\"${1// /\" or .key==\"}\")" | |
esc1=${1// /__} | |
esc2=${esc1//[\/]/-} | |
esc3=${esc2//[^a-zA-Z0-9-_]/} | |
name=${esc3:0:64} | |
tmp=tmp-layer | |
rm -rf $tmp | |
mkdir $tmp && cd $_ | |
npm init -y && npm install --save $packages | |
mkdir nodejs && mv node_modules $_ | |
zip -r $name.zip $_ | |
desc=$(jq -r ".dependencies | to_entries[] | $select | \"\(.key):\(.value.version)\"" package-lock.json) | |
layer=`aws lambda publish-layer-version\ | |
--layer-name $name\ | |
--description "${desc//$'\n'/ }"\ | |
--compatible-runtimes nodejs | |
--zip-file fileb://$name.zip | |
` | |
echo $layer | jq . | |
version=`echo $layer | jq -r '.Version'` | |
cd .. && rm -rf $tmp | |
open https://console.aws.amazon.com/lambda/home#/layers/$name/versions/$version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generate a zip file with several packages (space-sapareted).
Auto-generated description with npm package names and versions.