This project is designed for educational purposes to demonstrate AWS Lambda integration with the holidays
Python library. It includes two Lambda functions created for a course where lambda_function_regular.py
shows a simple initial version demonstrating the holidays library usage, and lambda_function_bedrock.py
is designed for AWS Bedrock Agent integration.
repository/
├── test/ # Test events for AWS Lambda console
│ ├── lambda_function_bedrock/ # Test events for Bedrock function
│ └── lambda_function_regular/ # Test events for regular function
├── lambda_function_bedrock.py # Lambda for AWS Bedrock Agent integration
├── lambda_function_regular.py # Standalone Lambda for testing/demo
├── requirements.txt # Python dependencies
└── Dockerfile # Docker configuration for layer creation
Both functions check if a specific date is a holiday in a given country, but serve different educational purposes:
lambda_function_regular.py
: Simple version demonstrating basic holidays library usagelambda_function_bedrock.py
: Advanced version for AWS Bedrock Agent integration
- Python 3.9+
holidays
library
Create Virtual Environment
virtualenv venv
# Or specify Python version:
virtualenv -p python3.13 venv
Activate Virtual Environment
- macOS/Linux:
source venv/bin/activate
- Windows:
venv\Scripts\activate
# Install dependencies to layer directory
pip install -r requirements.txt -t python/
# Create layer ZIP file
zip -r aws-lambda-layer.zip python/
- Prepare the Layer Package:
- If you prefer to skip this step, use the pre-built
python_dependencies.zip
file provided in the tutorial directory. This file contains all required dependencies and can be uploaded directly as a layer. - If you want to build your own layer:
- Detailed instructions are available in the Managing Dependencies in AWS Lambda with Docker-Generated Layers tutorial.
- Ensure you have the
requirements.txt
andDockerfile
files provided in the tutorial directory. - Execute the following commands on your local machine to build a
.zip
file for your Lambda Layer:- Build the Docker Image:
docker build -t lambda_layer .
- Run a Container:
docker run --name my_lambda_layer_container lambda_layer
- Export the Layer:
docker cp my_lambda_layer_container:/home/python_dependencies.zip .
- Cleanup (Optional):
docker stop my_lambda_layer_container docker rm my_lambda_layer_container docker rmi lambda_layer
- Build the Docker Image:
- If you prefer to skip this step, use the pre-built
# Upload layer via AWS CLI
aws lambda publish-layer-version \
--layer-name holiday-checker-layer \
--zip-file fileb://aws-lambda-layer.zip \
--compatible-runtimes python3.9 python3.10 python3.11 python3.12
- Runtime: Python 3.9+
- Handler:
lambda_function.lambda_handler
- Layer: Add the layer created above
Note: AWS Bedrock requires Lambda resource-based policies to invoke the function.
- Navigate to the Configuration tab.
- In the left-hand menu, select Permissions.
- Under the Resource-based policy statements section, click Add permissions.
- In the dialog, go to
AWS account
tab and configure the following:- Statement ID:
AllowBedrockInvoke
- Principal:
bedrock.amazonaws.com
- Action:
lambda:InvokeFunction
- Statement ID:
- Click Save to apply the policy.
- The new policy should appear in the Resource-based policy statements section. Ensure it matches the following structure:
{ "Version": "2012-10-17", "Id": "default", "Statement": [ { "Sid": "AllowBedrockInvoke", "Effect": "Allow", "Principal": { "Service": "bedrock.amazonaws.com" }, "Action": "lambda:InvokeFunction", "Resource": "arn:aws:lambda:<region>:<account-id>:function:<function-name>" } ] }
JSON test files for AWS Lambda console testing are available in the test/
directory. These files contain various test scenarios that can be used to validate the Lambda functions.