Skip to content

Commit

Permalink
Merge pull request #1 from umccr/update-build-script
Browse files Browse the repository at this point in the history
Update build script
  • Loading branch information
williamputraintan authored Mar 16, 2022
2 parents 8592c10 + 8ae740e commit 02c3eec
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ node_modules/

# Environment files
*.log
/lambdas/layers/python/
/cdk.out/
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
install:
pip install -r requirements.txt # pulls in CDKv2 `aws-cdk-lib` and `construct` libs
npm install -g aws-cdk

brew tap aws/tap
brew reinstall aws-sam-cli
build:
sam-beta-cdk build
# Build lambda Layer
for dir in $(shell find ./lambdas/layers -maxdepth 1 -mindepth 1 -type d -exec basename {} \;); do ./lambdas/layers/create_layer_package.sh $$dir; done
# Build Cdk to cdk.out
cdk synth
deploy: build
cdk deploy -a .aws-sam/build --profile ${AWS_PROFILE}
cdk deploy UmccrEventBus
cdk deploy UmccrEventBusSchemaStack
run:
sam-beta-cdk local invoke
sam local invoke
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ This is an attempt to overhaul a multiple-queues system with a unified event Bus
# Pre-requisites:
pip install -r requirements.txt # pulls in CDKv2 `aws-cdk-lib` and `construct` libs
npm install -g aws-cdk@2.0.0-rc.4
brew reinstall aws-sam-cli-beta-cdk
brew tap aws/tap
brew install aws-sam-cli
# Running and deploying:
make build
Expand Down
20 changes: 14 additions & 6 deletions lambdas/layers/create_layer_package.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
#!/bin/bash

LAYER_NAME=$1
SCRIPT_DIR=$(dirname $0)
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

if test -z "$LAYER_NAME"; then
echo "LAYER_NAME is not set! Specify the layer for which to create the Lambda package."
exit 1
fi

# spcifiy the lib directory (according to AWS Lambda guidelines)
export PKG_DIR="python"
export PKG_DIR=$SCRIPT_DIR/"python"
export LAYER_DIR=$SCRIPT_DIR/${LAYER_NAME}

# clean up any existing files
rm ${LAYER_NAME}.zip
rm -rf ${PKG_DIR}
cp -R ${LAYER_NAME}/ ${PKG_DIR}/
rm -rf ${PKG_DIR} && mkdir -p ${PKG_DIR}
cp -R ${LAYER_DIR}/ ${PKG_DIR}/

# install the python libraries (without dependencies)
docker run --rm -v $(pwd)/${PKG_DIR}:/foo -w /foo lambci/lambda:build-python3.8 pip install -r requirements.txt --no-deps -t ./
docker run \
--platform=linux/x86-64 \
--rm \
-v ${SCRIPT_PATH}/python:/foo \
-w /foo \
public.ecr.aws/sam/build-python3.8 \
pip install -r requirements.txt --no-deps -t ./

# clean the lib directory
rm -rf ${PKG_DIR}/*.dist-info
find python -type d -name __pycache__ -exec rm -rf {} +

# create the package zip
zip -r ${LAYER_NAME}.zip ./${PKG_DIR}/
zip -r ${LAYER_DIR}.zip ${PKG_DIR}/

# remove the inflated directory
rm -rf ${PKG_DIR}/
Empty file.

0 comments on commit 02c3eec

Please sign in to comment.