Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1faacd6
feat: add AWS Lambda containerized deployment support
aaarendt Oct 13, 2025
65d6186
fix: update Lambda test invocation payload and add CLI binary format …
aaarendt Oct 29, 2025
0c15665
fix: enhance Lambda test script with improved response handling and l…
aaarendt Oct 29, 2025
8daf438
fix: add missing dependencies for shapely and pandas in Lambda requir…
aaarendt Oct 29, 2025
78b4a1d
fix: add pytest markers for integration and Lambda-specific tests
aaarendt Oct 29, 2025
79329be
fix: enhance Lambda integration by improving dependency imports and a…
aaarendt Oct 29, 2025
c92cd84
feat: add SnowEx Lambda API client and handler for serverless databas…
aaarendt Dec 6, 2025
8b29864
fix: replace db_session with db_session_with_credentials so that DB n…
aaarendt Dec 15, 2025
b66b09d
additional serialization functionality
aaarendt Dec 18, 2025
da9eec3
add from_area method
aaarendt Dec 18, 2025
e813a35
Merge branch 'master' into lambda
aaarendt Dec 18, 2025
8617aa5
feat: enhance from_area method to support server-side spatial filteri…
aaarendt Dec 19, 2025
0a65a6b
refactor: streamline handle_event_with_secret and update from_area me…
aaarendt Dec 19, 2025
c4cf19c
refactor: enhance spatial query handling by eliminating geoalchemy2 d…
aaarendt Dec 19, 2025
116d992
feat: add conftest.py for deployment/integration tests with Lambda su…
aaarendt Dec 19, 2025
50ba6ba
feat: add end-to-end tests for SnowExLambdaClient functionality with …
aaarendt Dec 19, 2025
7ba4417
feat: add comprehensive tests for Lambda handler functionality with l…
aaarendt Dec 19, 2025
ef13420
feat: add script to update Lambda function configuration for timeout …
aaarendt Dec 19, 2025
c74fdd3
fix: update from_area method to include CRS parameter in TestLayerMea…
aaarendt Dec 19, 2025
ec9c98e
feat: enhance timeout handling in Lambda client tests and update requ…
aaarendt Dec 19, 2025
6224b48
fix: include CRS parameter in from_area method for PointMeasurementFi…
aaarendt Dec 19, 2025
bd7d3ae
fix: update to db_session_with_credentials to align with our newer cr…
aaarendt Dec 19, 2025
1dde1ba
fix: refactor local_credentials fixture to align with our new approac…
aaarendt Dec 19, 2025
7a69c7d
fix: enhance geometry handling and optimize query performance in Base…
aaarendt Dec 19, 2025
dcd8f5d
improve code readability by formatting comments and docstrings in api.py
aaarendt Dec 19, 2025
c1415c0
fix: starting on modifying gallery examples to work with the new Lamb…
aaarendt Dec 19, 2025
15d9f23
fix: add boto3 to dependencies
aaarendt Dec 19, 2025
da65214
small blunder
aaarendt Dec 19, 2025
885eae8
fix: update test cases to include layer_data fixture for area tests
aaarendt Dec 19, 2025
d9857bd
fix: update geometry handling to maintain provided CRS for spatial qu…
aaarendt Dec 19, 2025
9b99bb6
fix: update pytest command to exclude integration tests
aaarendt Dec 19, 2025
3551413
fix: update pytest command to exclude integration tests
aaarendt Dec 19, 2025
98ce1a9
refactor: simplify conftest.py by removing unused DB session fixtures
aaarendt Dec 24, 2025
c994d04
fix: enhance geometry handling to detect and use database SRID for sp…
aaarendt Dec 24, 2025
98b83ac
fix: add fixtures for test point and layer data to enhance spatial qu…
aaarendt Dec 24, 2025
f3f219c
Initial example of the functionality of the lambda client and new db …
aaarendt Dec 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Ignore unnecessary files for Docker build
.git
.gitignore
README.rst
docs/
notebooks/
tests/
.pytest_cache/
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.egg-info/
.coverage
.tox
venv/
env/
ENV/
.venv/
.env
.DS_Store
Thumbs.db
*.log
.mypy_cache/
.idea/
.vscode/
*.swp
*.swo
*~

# Build artifacts
build/
dist/
*.egg-info/

# Docker files (don't include docker-compose in container)
docker-compose.yml
Dockerfile
.dockerignore

# Development and documentation
CHANGELOG.rst
CODE_OF_CONDUCT.md
CONTRIBUTING.rst
LICENSE
Makefile
MANIFEST.in
deploy.sh
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: python3 -m pip install -e ".[dev]"
- name: Run tests and collect coverage
run: |
pytest --cov snowexsql --cov-report=xml
pytest --cov snowexsql --cov-report=xml -m "not integration"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
python3 -m pip install -e ".[dev]"
- name: Test with pytest
run: |
pytest -s
pytest -s -m "not integration"
31 changes: 31 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Deployment

This directory contains all the infrastructure and deployment configurations for
running snowexsql on AWS Lambda.

## Structure

- **`docker/`** - Docker container configuration for Lambda
- `Dockerfile` - Lambda-compatible container definition
- `.dockerignore` - Optimization for container builds
- `requirements-lambda.txt` - Lightweight dependencies

- **`aws/`** - AWS IAM policies and configurations
- `ecr_policy.json` - ECR repository permissions for Lambda
- `secrets_policy.json` - Secrets Manager access policy

- **`scripts/`** - Deployment automation scripts
- `deploy.sh` - Main deployment script (container-based)
- `test_lambda.sh` - Automated testing script

## Quick Start

1. Run `scripts/deploy.sh` to deploy the Lambda function
2. Test with `scripts/test_lambda.sh`

## Prerequisites

- AWS CLI configured
- Docker installed and running
- Existing ECR repository named `snowexsql`
- Lambda function with container image support
33 changes: 33 additions & 0 deletions deployment/aws/ecr_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "LambdaECRImageRetrievalPolicy",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer"
],
"Condition": {
"StringLike": {
"aws:sourceArn": "arn:aws:lambda:us-west-2:390402539674:function:*"
}
}
},
{
"Sid": "LambdaECRImageCrossAccount",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::390402539674:root"
},
"Action": [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:GetAuthorizationToken"
]
}
]
}
12 changes: 12 additions & 0 deletions deployment/aws/secrets_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue"
],
"Resource": "arn:aws:secretsmanager:us-west-2:390402539674:secret:rds/snowexsql/credentials-*"
}
]
}
49 changes: 49 additions & 0 deletions deployment/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Ignore unnecessary files for Docker build
.git
.gitignore
README.rst
docs/
notebooks/
tests/
.pytest_cache/
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.egg-info/
.coverage
.tox
venv/
env/
ENV/
.venv/
.env
.DS_Store
Thumbs.db
*.log
.mypy_cache/
.idea/
.vscode/
*.swp
*.swo
*~

# Build artifacts
build/
dist/
*.egg-info/

# Docker files (don't include docker-compose in container)
docker-compose.yml
Dockerfile
.dockerignore

# Development and documentation
CHANGELOG.rst
CODE_OF_CONDUCT.md
CONTRIBUTING.rst
LICENSE
Makefile
MANIFEST.in
deploy.sh
11 changes: 11 additions & 0 deletions deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM public.ecr.aws/lambda/python:3.12

# Copy requirements and install dependencies
COPY deployment/docker/requirements-lambda.txt ${LAMBDA_TASK_ROOT}/
RUN pip install --no-cache-dir -r requirements-lambda.txt

# Copy the snowexsql package
COPY snowexsql/ ${LAMBDA_TASK_ROOT}/snowexsql/

# Set the CMD to your handler
CMD ["snowexsql.lambda_handler.lambda_handler"]
8 changes: 8 additions & 0 deletions deployment/docker/requirements-lambda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Lambda-optimized requirements without heavy dependencies
utm>=0.5.0,<1.0
geoalchemy2>=0.6,<1.0
shapely>=2.0.0,<3.0
pandas>=1.5.0,<3.0
psycopg2-binary>=2.9.0,<2.10.0
SQLAlchemy>=2.0.0
boto3>=1.26.0
84 changes: 84 additions & 0 deletions deployment/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# AWS Lambda Deployment Script for SnowEx SQL
# This script builds and deploys the Docker container to AWS Lambda

set -e

# Configuration
AWS_ACCOUNT_ID="390402539674"
AWS_REGION="us-west-2"
ECR_REPOSITORY="snowexsql"
LAMBDA_FUNCTION_NAME="lambda-snowex-sql"
IMAGE_TAG="$(git rev-parse --short HEAD)"

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${GREEN}Starting SnowEx SQL Lambda deployment...${NC}"

# Check if AWS CLI is installed and configured
if ! command -v aws &> /dev/null; then
echo -e "${RED}Error: AWS CLI is not installed${NC}"
exit 1
fi

# Check if Docker is running
if ! docker info &> /dev/null; then
echo -e "${RED}Error: Docker is not running${NC}"
exit 1
fi

# Build the Docker image
echo -e "${YELLOW}Building Docker image...${NC}"
DOCKER_BUILDKIT=0 docker build -f ../docker/Dockerfile -t ${ECR_REPOSITORY}:${IMAGE_TAG} ../..

# Get ECR login token
echo -e "${YELLOW}Logging into ECR...${NC}"
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com

# Tag the image for ECR
ECR_URI="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}"
echo -e "${YELLOW}Tagging image for ECR: ${ECR_URI}${NC}"
docker tag ${ECR_REPOSITORY}:${IMAGE_TAG} ${ECR_URI}

# Push to ECR
echo -e "${YELLOW}Pushing image to ECR...${NC}"
docker push ${ECR_URI}

# Update Lambda function
echo -e "${YELLOW}Updating Lambda function...${NC}"
aws lambda update-function-code \
--region ${AWS_REGION} \
--function-name ${LAMBDA_FUNCTION_NAME} \
--image-uri ${ECR_URI}

# Wait for the update to complete
echo -e "${YELLOW}Waiting for Lambda function update to complete...${NC}"
aws lambda wait function-updated \
--region ${AWS_REGION} \
--function-name ${LAMBDA_FUNCTION_NAME}

echo -e "${GREEN}Deployment completed successfully!${NC}"
echo -e "${GREEN}Lambda function '${LAMBDA_FUNCTION_NAME}' has been updated with the new image.${NC}"

# Optional: Test the function
read -p "Would you like to test the Lambda function? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Testing Lambda function...${NC}"
aws lambda invoke \
--region ${AWS_REGION} \
--function-name ${LAMBDA_FUNCTION_NAME} \
--cli-binary-format raw-in-base64-out \
--payload '{"action":"test_connection"}' \
response.json

echo -e "${GREEN}Test response:${NC}"
cat response.json
echo
rm -f response.json
fi
Loading