Working repository for deomsontrating how python functions in a Docker container may be exposed as a AWS Lambda function.
Customer has requested assistance with streamlining and optimizing their use of local containers as a part of their workflow(s) building AWS lambda functions. The primary goal is to try to develop locally with lambdas while minimizing dependence on use of AWS services during local development. Ideally, the solution will allow for a consistent development experience using Docker locally, yet still able to run AWS Lambda functions in the cloud.
Initial set of working requirements are as follows:
- single Dockerfile - using ARGs to specify function name
- at least 3 functions in subdirs
- single requirements file
- Boto3
- datadog_lambda
- pydantic
- local builds must be able to use AWS creds (docker run -v ~/.aws:/root/.aws -e AWS_PROFILE=stage start_fulfillment_workflow)
- perhaps a script to automate build of AWS creds in image in a shared directory that is copied into the image upon build (this would match current use case)
- saml2aws login --skip-prompt --profile=stage --duo-mfa-option "Duo Push" --role="arn:aws:iam::ACCOUNT_ID:role/acquisition-rw"
- eval "$(saml2aws script --shell=bash --skip-prompt --profile=stage)"
- perhaps a script to automate build of AWS creds in image in a shared directory that is copied into the image upon build (this would match current use case)
- successful build and push from GHA
- successful run in AWS as lambda function (we need to make sure it does what it's supposed to!)
- is there a way to use the DD UI for this instead? (make it easier for other devs)
- code (function) executes w/o error
- output to console log is fine
- hot reload would be nice to have - specifically for function code
- optionally, use IDE integration (Jetbrains?) for above instead of Docker Desktop
Use Docker compose to test locally - the provided "compose.yaml" file will automatically configure the application for local testing using only the "dev" stage from the Dockerfile.
Use the following commands to build and run a container locally with Docker compose:
docker compose build --build-arg LAMBDA_NAME=lambda1 (or lambda2, etc)
docker compose up -dThen you may test your running container locally using the following:
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"length": 6,"width": 7}'