Skip to content

feat: directly update the basemaps lambda function configuration #1086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice and easy for update the environment variables. Just wondering if we want to wrap this into a cli?
And also we might still want to compare and comment changes for between old config and new config in the PR for preview changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was duplicated in two places is why I made it a bash shell, we could write a full cli for it, but figured it wasn't really worth it to wrap 2 aws sdk calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comparison between the config diffs, is also already handled futher up the script this is just the deployment phase

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to update the import cli to compare cli, which is download production config from v1/version and do diffs between Pull request config. So we still got the diffs.

env:
BASEMAPS_LAMBDA_ARN: ${{ secrets.BASEMAPS_LAMBDA_ARN }}
BASEMAPS_CONFIG_LOCATION: ${CONFIG_LOCATION_PROD}


smoke:
permissions:
Expand Down
39 changes: 39 additions & 0 deletions scripts/update-lambda-config.sh
Original file line number Diff line number Diff line change
@@ -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}"