From de7f03703f9432c0b5a4d7b42202aa88c5b9d40d Mon Sep 17 00:00:00 2001 From: Blayne Chard Date: Thu, 15 May 2025 15:09:30 +1200 Subject: [PATCH] feat: directly update the basemaps lambda function configuration --- .github/workflows/build.yml | 11 ++++++++-- scripts/update-lambda-config.sh | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 scripts/update-lambda-config.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f7234a96..9ee252c65 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -128,7 +128,10 @@ jobs: - name: Import config run: | - ./scripts/bmc.sh ./index.cjs import --config ${CONFIG_PATH} --commit + ./scripts/update-lambda-config.sh + env: + BASEMAPS_LAMBDA_ARN: ${{ secrets.BASEMAPS_LAMBDA_ARN }} + BASEMAPS_CONFIG_LOCATION: ${CONFIG_PATH} # Compare and deploy to prod deploy-prod: @@ -189,7 +192,11 @@ jobs: - name: Import config run: | - ./scripts/bmc.sh ./index.cjs import --config ${CONFIG_LOCATION_PROD} --commit + ./scripts/update-lambda-config.sh + env: + BASEMAPS_LAMBDA_ARN: ${{ secrets.BASEMAPS_LAMBDA_ARN }} + BASEMAPS_CONFIG_LOCATION: ${CONFIG_LOCATION_PROD} + smoke: permissions: diff --git a/scripts/update-lambda-config.sh b/scripts/update-lambda-config.sh new file mode 100644 index 000000000..2862973f9 --- /dev/null +++ b/scripts/update-lambda-config.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Basemaps uses environment variables to know where to load config from +# +# This script looks up the current environment variables for the lambda +# then updates the config location to the new config location +# +# Parameters: +# - $BASEMAPS_CONFIG_LOCATION - location of the new configuration file +# - $BASEMAPS_LAMBDA_ARN - ARN of the lambda to update + +if [ -z "$BASEMAPS_CONFIG_LOCATION" ]; then + echo "Error: missing config location \$BASEMAPS_CONFIG_LOCATION" + exit 1 +fi + +if [ -z "$BASEMAPS_LAMBDA_ARN" ]; then + echo "Error: missing config location \$BASEMAPS_LAMBDA_ARN" + exit 1 +fi + +# Get the Lambda function's current environment variables +existing_env_vars=$(aws lambda get-function-configuration \ + --region ap-southeast-2 \ + --function-name "$BASEMAPS_LAMBDA_ARN" \ + --query "Environment.Variables" \ + --output json) + +current_location=$(echo "$existing_env_vars" | jq ".BASEMAPS_CONFIG_PATH") +# Use jq to update the configuration path +updated_env_vars=$(echo "$existing_env_vars" | jq ".BASEMAPS_CONFIG_PATH = \"${BASEMAPS_CONFIG_LOCATION}\"") + +# Update the Lambda function with the modified environment variables +aws lambda update-function-configuration \ + --region ap-southeast-2 \ + --function-name "$BASEMAPS_LAMBDA_ARN" \ + --environment Variables="$updated_env_vars" + +echo "Updated config location from: ${current_location} to ${BASEMAPS_CONFIG_LOCATION}" \ No newline at end of file