Skip to content

Commit

Permalink
[NRL-793] Fixed up shellcheck reports in new pull-lambda-code-for-sta…
Browse files Browse the repository at this point in the history
…ck.sh
  • Loading branch information
mattdean3-nhs committed Sep 17, 2024
1 parent f27eeaa commit 50353af
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions scripts/pull-lambda-code-for-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,38 @@
# Pull down all the lambda code for the named stack
set -o errexit -o nounset -o pipefail

: ${DIST_DIR:="./dist"}
: "${DIST_DIR:="./dist"}"

if [ $# -ne 1 ]
then
echo "Error: stack-name argument is missing" 1>&2
echo "Usage: $0 <stack-name>" 1>&2
exit 1
fi

stack_name="$1"

function pull_lambda_code(){
local api_name="$1"
local endpoint_name="$2"
local lambda_name="nhsd-nrlf--${stack_name}--api--${api_name}--${endpoint_name}"

lambda_name="nhsd-nrlf--${stack_name}--api--${api_name}--${endpoint_name}"

echo -n "- Downloading code for lambda ${lambda_name}.... "
code_url="$(aws lambda get-function --function-name ${lambda_name} | jq -r .Code.Location)"
code_url="$(aws lambda get-function --function-name "${lambda_name}" | jq -r .Code.Location)"
curl "${code_url}" 2>/dev/null > "${DIST_DIR}/${api_name}-${endpoint_name}.zip"
echo ""
}

function pull_layer_code(){
local name="$1"
local layer_name="nhsd-nrlf--${stack_name}--${name}"
local layer_version="$(aws lambda list-layer-versions --layer-name ${layer_name} | jq -r '.LayerVersions[0].Version')"
local layer_pkg_name="$(echo ${name} | tr '-' '_').zip"

echo -n "- Downloading code for layer ${layer_name} version ${layer_version}...."
code_url="$(aws lambda get-layer-version --layer-name ${layer_name} --version-number ${layer_version} | jq -r .Content.Location)"
layer_name="nhsd-nrlf--${stack_name}--${name}"
layer_pkg_name="$(echo "${name}" | tr '-' '_').zip"
layer_version="$(aws lambda list-layer-versions --layer-name "${layer_name}" | jq -r '.LayerVersions[0].Version')"

echo -n "- Downloading code for layer ${layer_name} version ${layer_version}.... "
code_url="$(aws lambda get-layer-version --layer-name "${layer_name}" --version-number "${layer_version}" | jq -r .Content.Location)"
curl "${code_url}" 2>/dev/null > "${DIST_DIR}/${layer_pkg_name}"
echo ""
}
Expand All @@ -33,23 +42,27 @@ mkdir -p "${DIST_DIR}"

echo
echo "Pulling code for consumer API lambdas...."
for endpoint_name in $(ls api/consumer)
for endpoint_path in api/consumer/*
do
if [ ! -d "api/consumer/${endpoint_name}" ]; then
if [ ! -d "${endpoint_path}" ]
then
continue
fi

endpoint_name="$(basename "${endpoint_path}")"
pull_lambda_code "consumer" "${endpoint_name}"
done

echo
echo "Pulling code for producer API lambdas...."
for endpoint_name in $(ls api/producer)
for endpoint_path in api/producer/*
do
if [ ! -d "api/producer/${endpoint_name}" ]; then
if [ ! -d "${endpoint_path}" ]
then
continue
fi

endpoint_name="$(basename "${endpoint_path}")"
pull_lambda_code "producer" "${endpoint_name}"
done

Expand Down

0 comments on commit 50353af

Please sign in to comment.