Packaging the Lambda
Lambda packaging used to mean a .zip file and hope. Today it is a Dockerfile or a Layer plus a buildspec. We ship a buildspec that builds the function, uploads it, and updates the Lambda configuration on every push to main.
version: 0.2
phases:
install:
runtime-versions:
python: 3.11
pre_build:
commands:
- pip install --target ./vendor -r requirements.txt
build:
commands:
- zip -r function.zip weather_api.py get-data-api.py vendor
- aws lambda update-function-code --function-name get_api_weather_data_lambda --zip-file fileb://function.zipCodeBuild handles install, build, and Lambda update. Notice the requirements.txt install into a vendored directory so the deployment package is self-contained.
Secrets and config flow through Lambda environment variables, set via Terraform or the AWS Console. The function reads WEATHER_API_KEY at runtime. Never hardcode credentials in the script. Never commit them to the repo.
For a daily extract, no. Cold start adds about a second to a 90-second invocation. Provisioned concurrency is overkill. Save your reserved capacity dollars for user-facing endpoints where latency matters.
Quiz: Quiz
Loading practice…