Skip to content

Commit

Permalink
prmdr-786 - Improve Lambda Edge deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
RioKnightleyNHS authored Sep 10, 2024
1 parent f50262b commit 6db52f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/base-lambdas-edge-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

- name: Create release package for Lambda ${{ inputs.lambda_aws_name }}
run: |
make lambda_name=${{ inputs.lambda_handler_name}} zip
make lambda_name=${{ inputs.lambda_handler_name}} edge_zip
- name: Upload Lambda Function to ${{ inputs.lambda_aws_name }}
uses: appleboy/lambda-action@master
Expand Down
29 changes: 15 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ LAMBDAS_BUILD_PATH=build/lambdas
LAMBDA_LAYERS_BUILD_PATH=build/lambda_layers
LAMBDA_LAYER_PYTHON_PATH=python/lib/python$(PYTHON_VERSION)/site-packages

ZIP_BASE_PATH = ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
ZIP_COMMON_FILES = lambdas/utils lambdas/models lambdas/services lambdas/repositories lambdas/enums

default: help

clean: clean-build clean-py clean-test
Expand Down Expand Up @@ -83,22 +86,20 @@ edge_env:
./lambdas/venv/bin/pip3 install -r $(GITHUB_REQUIREMENTS)
./lambdas/venv/bin/pip3 install -r $(EDGE_REQUIREMENTS)


zip:
echo $(LAMBDAS_BUILD_PATH)/$(lambda_name)
rm -rf ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)|| true
mkdir -p ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)
mkdir -p ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp/handlers
cp -r lambdas/handlers/$(lambda_name).py ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp/handlers
cp -r lambdas/utils ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
cp -r lambdas/models ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
cp -r lambdas/services ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
cp -r lambdas/repositories ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
cp -r lambdas/enums ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
cp -r lambdas/venv/lib/python*/site-packages/* ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
cd ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp ; zip -r ../$(lambda_name).zip .
rm -rf ./$(LAMBDAS_BUILD_PATH)/$(lambda_name)/tmp
cd ../..
rm -rf ./$(LAMBDAS_BUILD_PATH)/$(lambda_name) || true
mkdir -p $(ZIP_BASE_PATH)/handlers
cp lambdas/handlers/$(lambda_name).py $(ZIP_BASE_PATH)/handlers
cp -r $(ZIP_COMMON_FILES) $(ZIP_BASE_PATH)
cd $(ZIP_BASE_PATH) ; zip -r ../$(lambda_name).zip .
rm -rf $(ZIP_BASE_PATH)

edge_zip: zip
mkdir -p $(ZIP_BASE_PATH)/python
cp -r lambdas/venv/lib/python*/site-packages/* $(ZIP_BASE_PATH)
cd $(ZIP_BASE_PATH) ; zip -r ../$(lambda_name).zip .
rm -rf $(ZIP_BASE_PATH)

lambda_layer_zip:
rm -rf ./$(LAMBDA_LAYERS_BUILD_PATH)/$(layer_name) || true
Expand Down
15 changes: 8 additions & 7 deletions lambdas/services/base/dynamo_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,23 @@ def update_item(
updated_field_names = list(updated_fields.keys())
update_expression = create_update_expression(updated_field_names)
_, expression_attribute_names = create_expressions(updated_field_names)
expression_attribute_values = create_expression_attribute_values(updated_fields)

generated_expression_attribute_values = create_expression_attribute_values(
updated_fields
)

if expression_attribute_values:
generated_expression_attribute_values.update(expression_attribute_values)

update_item_args = {
"Key": {"ID": key},
"UpdateExpression": update_expression,
"ExpressionAttributeNames": expression_attribute_names,
"ExpressionAttributeValues": expression_attribute_values,
"ExpressionAttributeValues": generated_expression_attribute_values,
}

if condition_expression:
update_item_args["ConditionExpression"] = condition_expression
if expression_attribute_values:
expression_attribute_values.update(expression_attribute_values)
update_item_args["ExpressionAttributeValues"] = (
expression_attribute_values
)

table.update_item(**update_item_args)

Expand Down

0 comments on commit 6db52f7

Please sign in to comment.