diff --git a/.gitignore b/.gitignore index 06722d9a7..86a9ea701 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ node_modules/ # Environment files *.log +/lambdas/layers/python/ +/cdk.out/ diff --git a/Makefile b/Makefile index 38a031f77..261c1a31e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index aa180f29a..4677dd81f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lambdas/layers/create_layer_package.sh b/lambdas/layers/create_layer_package.sh index f40458cfc..cfddc7dda 100755 --- a/lambdas/layers/create_layer_package.sh +++ b/lambdas/layers/create_layer_package.sh @@ -1,6 +1,8 @@ #!/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." @@ -8,22 +10,28 @@ if test -z "$LAYER_NAME"; then 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}/ \ No newline at end of file diff --git a/lambdas/layers/domain/requirements.txt b/lambdas/layers/domain/requirements.txt new file mode 100644 index 000000000..e69de29bb