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..650376b0 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,19 @@ 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 lambda by installing python dependencies matching x86_64 + mkdir deps && \ + 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: ## cleanup any leftover resources + rm -f -r ./deps + rm -f local_esf.zip + docker-test: ## Run all tests on docker docker-test: SCRIPTS_BASE_DIR=docker/ docker-test: test 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: