Skip to content

Instantly share code, notes, and snippets.

@Jehong-Ahn
Last active August 18, 2021 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jehong-Ahn/1f434426e8972dda05ce6ff2ac4834b7 to your computer and use it in GitHub Desktop.
Save Jehong-Ahn/1f434426e8972dda05ce6ff2ac4834b7 to your computer and use it in GitHub Desktop.
Publish AWS Lambda Layer
#!/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
@Jehong-Ahn
Copy link
Author

Generate a zip file with several packages (space-sapareted).
Auto-generated description with npm package names and versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment