-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_layer.sh
48 lines (48 loc) · 1.6 KB
/
create_layer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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