-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-layer.sh
More file actions
executable file
·51 lines (38 loc) · 1.08 KB
/
Copy pathpublish-layer.sh
File metadata and controls
executable file
·51 lines (38 loc) · 1.08 KB
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
49
50
51
#!/bin/bash
SCRIPT_DIR=$(dirname "$0")
SCRIPT_NAME=$(basename "$0")
DOCKERFILE="./dockerfile"
LAYER_NAME=$(cat ${DOCKERFILE} | grep "^ARG LAYER_NAME=" | sed -r 's#.*=(.*)#\1#')
ZIP_FILE_NAME="${LAYER_NAME}.zip"
ZIP_FILE_LOC="./layers/${ZIP_FILE_NAME}"
main() {
local s3_bucket="$1"
if [ ! -f "${ZIP_FILE_LOC}" ]; then
echo "Missing ${ZIP_FILE_LOC} lambda layer. Run create-lambda-layer.sh first"
return 1
fi
if [ -z $s3_bucket ]; then
log "${SCRIPT_NAME}: missing s3_bucket name"
return 1
fi
publish_layer "${s3_bucket}"
}
log() {
output="$@"
echo "${output}" >&2
}
publish_layer() {
local s3_bucket="$1"
local s3url="s3://${s3_bucket}/"
log "copying ${ZIP_FILE_LOC} to ${s3url} ..."
aws s3 cp "${ZIP_FILE_LOC}" "${s3url}" >&2 && \
log "publishing ${LAYER_NAME} ..." && \
local output=$(aws lambda publish-layer-version \
--layer-name ${LAYER_NAME} \
--content S3Bucket=${s3_bucket},S3Key=${ZIP_FILE_NAME} \
--compatible-runtimes nodejs10.x)
log "${output}"
local version=$(echo "$output" | jq '.Version')
echo "$version"
}
main "$@"