From 897879ad69446eb107a19531d4a91709ea7766a2 Mon Sep 17 00:00:00 2001 From: Kavindu Dodanduwa Date: Wed, 7 May 2025 10:07:00 -0700 Subject: [PATCH 1/3] add make cmds to package and clean zip Signed-off-by: Kavindu Dodanduwa --- .gitignore | 1 + Makefile | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/.gitignore b/.gitignore index 86d21a4e..38c90033 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.egg *.db *.pid +*.zip .coverage* .DS_Store .idea diff --git a/Makefile b/Makefile index c7385c3a..c6d5e78f 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,18 @@ isort: ## Run isort in the project on the host mypy: ## Run mypy in the project on the host tests/scripts/${SCRIPTS_BASE_DIR}mypy.sh +package: + mkdir deps && \ + pip install --target=./deps -r requirements.txt && \ + cd ./deps && \ + zip -r ../local_esf.zip . && \ + cd .. && \ + zip -r local_esf.zip main_aws.py handlers share storage shippers && \ + rm -r ./deps + +clean: + rm -f local_esf.zip + docker-test: ## Run all tests on docker docker-test: SCRIPTS_BASE_DIR=docker/ docker-test: test From 9ecdce9f275a78fb233b08122d588a81900f6321 Mon Sep 17 00:00:00 2001 From: Kavindu Dodanduwa Date: Wed, 7 May 2025 13:55:33 -0700 Subject: [PATCH 2/3] build with x86_64 deps and bump es apm to support python 12 Signed-off-by: Kavindu Dodanduwa --- Makefile | 7 ++++--- requirements.txt | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c6d5e78f..650376b0 100644 --- a/Makefile +++ b/Makefile @@ -36,16 +36,17 @@ isort: ## Run isort in the project on the host mypy: ## Run mypy in the project on the host tests/scripts/${SCRIPTS_BASE_DIR}mypy.sh -package: +package: ## Package lambda by installing python dependencies matching x86_64 mkdir deps && \ - pip install --target=./deps -r requirements.txt && \ + pip install --target=./deps --platform manylinux2014_x86_64 --implementation cp --python-version 3.12 --only-binary=:all: --upgrade -r requirements.txt && \ cd ./deps && \ zip -r ../local_esf.zip . && \ cd .. && \ zip -r local_esf.zip main_aws.py handlers share storage shippers && \ rm -r ./deps -clean: +clean: ## cleanup any leftover resources + rm -f -r ./deps rm -f local_esf.zip docker-test: ## Run all tests on docker diff --git a/requirements.txt b/requirements.txt index 4f7a5b30..db20023f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -elastic-apm==6.19.0 +elastic-apm==6.23.0 boto3==1.37.36 ecs_logging==2.1.0 elasticsearch==7.17.12 From 5d8c56b9bb2e2c7420a492d47093d49825d51773 Mon Sep 17 00:00:00 2001 From: Kavindu Dodanduwa Date: Thu, 8 May 2025 10:29:16 -0700 Subject: [PATCH 3/3] document build options Signed-off-by: Kavindu Dodanduwa --- dev-corner/how-to-test-locally/README.md | 36 ++++++++++++++++++------ 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/dev-corner/how-to-test-locally/README.md b/dev-corner/how-to-test-locally/README.md index f693886d..8eceb343 100644 --- a/dev-corner/how-to-test-locally/README.md +++ b/dev-corner/how-to-test-locally/README.md @@ -1,17 +1,38 @@ -This is just an example of how to build and run ESF locally. +This document contains details about how to build ESF Lambda locally. +Once built, the Lambda can be deployed to validate functionality. -## Requirements +## Building lambda + +To build the Lambda, you may use one of the options below, + +### Using Makefile + +To build, + +```shell +make package +``` + +This will generate a Lambda zip named `local_esf.zip`. + +To clean up any leftover resources, + +```shell +make clean +``` + +### Using Task file + +#### Requirements - [Terraform](https://www.terraform.io/) - (Optional) [Taskfile](https://taskfile.dev/installation/) -## Steps +#### Building **Important note**: ESF dependencies have been tested on architecture `x86_64`. Make sure to use it as well. -### Step 1: Build your dependencies zip file - You can build your own, or you can choose to run: ```bash task @@ -24,13 +45,12 @@ You can update the task variables in the `.env` file: - The name of the zip file, `FILENAME`. -### Step 2: Run ESF terraform +## Deploying Lambda -Use the code in [ESF terraform repository](https://github.com/elastic/terraform-elastic-esf). +Once Lambda zip is ready, you should use the code in [ESF terraform repository](https://github.com/elastic/terraform-elastic-esf). > **NOTE**: ESF lambda function is using architecture `x86_64`. - Place your `local_esf.zip` (or `` if you changed the value) in the same directory as ESF terraform. Go to `esf.tf` file and edit: