Skip to content

Commit

Permalink
[NRL-793] WIP workflow for building permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdean3-nhs committed Sep 17, 2024
1 parent c72606e commit a80f2b3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions scripts/pull-lambda-code-for-stack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# Pull down all the lambda code for the named stack
set -o errexit -o nounset -o pipefail

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

stack_name="$1"

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

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

function pull_layer_code(){
local name="$1"
local layer_name="nhds-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 ${layer_name} | tr '-' '_').zip"

echo "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}" > "${DIST_DIR}/${layer_pkg_name}"
}

mkdir -p "${DIST_DIR}"

echo "Pulling code for consumer API lambdas...."
for endpoint_name in $(ls api/consumer)
do
pull_lambda_code "consumer" "${endpoint_name}"
done

echo "Pulling code for producer API lambdas...."
for endpoint_name in $(ls api/producer)
do
pull_lambda_code "producer" "${endpoint_name}"
done

echo "Pulling code for layers...."
for layer_name in nrlf dependency-layer nrlf-permissions
do
pull_layer_code "${layer_name}"
done

0 comments on commit a80f2b3

Please sign in to comment.