Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.

Commit 4fb306a

Browse files
authored
lambda / s3 upload fix (#15)
* copy the zip to S3 when deploying a lambda via S3
1 parent a45f927 commit 4fb306a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

bin/deployables

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -629,21 +629,21 @@ function _lambda_init_zip_vars () {
629629
DEPLOY_LAMBDA_ZIP_FULLPATH="${DEPLOY_LAMBDA_ZIP_DIR}/${DEPLOY_LAMBDA_ZIP_FILENAME}"
630630
fi
631631

632-
if [[ -z "${DEPLOY_DEBUG}" ]] ; then
633-
DEPLOY_LAMBDA_ZIP_QUIET="-q"
634-
else
635-
DEPLOY_LAMBDA_ZIP_QUIET=""
636-
fi
637-
638632
}
639633

640634
function lambda_package_zip () {
641635

642636
_lambda_init_zip_vars
643637

644-
DEPLOY_LAMBDA_SOURCE_DIR="${DEPLOY_LAMBDA_SOURCE_DIR:-.}"
638+
if [[ -z "${DEPLOY_DEBUG}" ]] ; then
639+
DEPLOY_LAMBDA_ZIP_QUIET="-q"
640+
else
641+
DEPLOY_LAMBDA_ZIP_QUIET=""
642+
fi
645643

646644
# zip into deploy package
645+
DEPLOY_LAMBDA_SOURCE_DIR="${DEPLOY_LAMBDA_SOURCE_DIR:-.}"
646+
647647
pushd "${DEPLOY_LAMBDA_SOURCE_DIR:-.}"
648648
zip ${DEPLOY_LAMBDA_ZIP_QUIET} -r ${DEPLOY_LAMBDA_ZIP_FULLPATH} . -x "*.git*"
649649
popd
@@ -666,10 +666,12 @@ function lambda_copy_zip_to_s3 () {
666666
exit 1
667667
fi
668668

669+
s3_cp_opts="--acl=bucket-owner-full-control --only-show-errors"
670+
669671
# copy to version-specific or commit-hash key
670672
if [[ ! -z "${DEPLOY_LAMBDA_ZIP_VERSION}" ]] ; then
671673
aws --profile "${DEPLOY_AWS_PROFILE}" \
672-
s3 cp \
674+
s3 cp ${s3_cp_opts} \
673675
${DEPLOY_LAMBDA_ZIP_FULLPATH} \
674676
s3://${DEPLOY_LAMBDA_S3_BUCKET}/${DEPLOY_LAMBDA_FUNCTION_NAME}/archive/${DEPLOY_LAMBDA_FUNCTION_NAME}-${DEPLOY_LAMBDA_ZIP_VERSION}.zip
675677

@@ -680,7 +682,7 @@ function lambda_copy_zip_to_s3 () {
680682

681683
elif [[ ! -z "${DEPLOY_SHA1}" ]] ; then
682684
aws --profile "${DEPLOY_AWS_PROFILE}" \
683-
s3 cp \
685+
s3 cp ${s3_cp_opts} \
684686
${DEPLOY_LAMBDA_ZIP_FULLPATH} \
685687
s3://${DEPLOY_LAMBDA_S3_BUCKET}/${DEPLOY_LAMBDA_FUNCTION_NAME}/archive/${DEPLOY_LAMBDA_FUNCTION_NAME}-${DEPLOY_SHA1}.zip
686688

@@ -692,7 +694,7 @@ function lambda_copy_zip_to_s3 () {
692694

693695
# copy to latest key
694696
aws --profile "${DEPLOY_AWS_PROFILE}" \
695-
s3 cp \
697+
s3 cp ${s3_cp_opts} \
696698
${DEPLOY_LAMBDA_ZIP_FULLPATH} \
697699
s3://${DEPLOY_LAMBDA_S3_BUCKET}/${DEPLOY_LAMBDA_FUNCTION_NAME}/${DEPLOY_LAMBDA_FUNCTION_NAME}.zip
698700

@@ -817,7 +819,7 @@ function lambda_deploy () {
817819
# setup aws
818820
aws_configure
819821

820-
# zip the
822+
# use an existing zip, or make a new one
821823
if [[ ! -z "${DEPLOY_LAMBDA_ZIP_FULLPATH}" ]] && [[ -f "${DEPLOY_LAMBDA_ZIP_FULLPATH}" ]] ; then
822824
echo "Skipping ... Zip already exists at ${DEPLOY_LAMBDA_ZIP_FULLPATH}"
823825
else
@@ -831,6 +833,9 @@ function lambda_deploy () {
831833
if [[ ! -z "${DEPLOY_LAMBDA_S3_BUCKET}" ]] ; then
832834
echo "Info: Deploying lambda via S3; DEPLOY_LAMBDA_S3_BUCKET: ${DEPLOY_LAMBDA_S3_BUCKET}"
833835

836+
# copy the zip to S3
837+
lambda_copy_zip_to_s3
838+
834839
lambda_code_parameters=$( echo \
835840
--s3-bucket "${DEPLOY_LAMBDA_S3_BUCKET}" \
836841
--s3-key "${DEPLOY_LAMBDA_FUNCTION_NAME}/${DEPLOY_LAMBDA_FUNCTION_NAME}.zip"

0 commit comments

Comments
 (0)