Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
297 changes: 6 additions & 291 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ awscli-local = "^0.22.2"
polyfactory = "^3.2.0"
pyright = "^1.1.407"
brunns-matchers = "^2.9.0"
localstack = "^4.12.0"
pytest-docker = "^3.2.3"
stamina = "^25.2.0"
pytest-freezer = "^0.4.9"
Expand All @@ -63,7 +62,7 @@ behave = "^1.3.3"
python-dotenv = "^1.2.1"
openapi-spec-validator = "^0.7.2"
pip-licenses = "^5.5.0"

cachetools = "^7.0.1"

[tool.poetry-plugin-lambda-build]
docker-image = "public.ecr.aws/sam/build-python3.13:1.139-x86_64" # See https://gallery.ecr.aws/search?searchTerm=%22python%22&architecture=x86-64&popularRegistries=amazon&verified=verified&operatingSystems=Linux
Expand Down
12 changes: 6 additions & 6 deletions src/eligibility_signposting_api/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def config() -> dict[str, Any]:
audit_bucket_name = BucketName(os.getenv("AUDIT_BUCKET_NAME", "test-audit-bucket"))
hashing_secret_name = HashSecretName(os.getenv("HASHING_SECRET_NAME", "test_secret"))
aws_default_region = AwsRegion(os.getenv("AWS_DEFAULT_REGION", "eu-west-1"))
enable_xray_patching = bool(os.getenv("ENABLE_XRAY_PATCHING", "false"))
enable_xray_patching = os.getenv("ENABLE_XRAY_PATCHING", "false").lower() == "true"
kinesis_audit_stream_to_s3 = AwsKinesisFirehoseStreamName(
os.getenv("KINESIS_AUDIT_STREAM_TO_S3", "test_kinesis_audit_stream_to_s3")
)
Expand All @@ -51,21 +51,21 @@ def config() -> dict[str, Any]:
"log_level": log_level,
}

local_stack_endpoint = "http://localhost:4566"
moto_server_endpoint = "http://localhost:4566"
return {
"aws_access_key_id": AwsAccessKey(os.getenv("AWS_ACCESS_KEY_ID", "dummy_key")),
"aws_default_region": aws_default_region,
"aws_secret_access_key": AwsSecretAccessKey(os.getenv("AWS_SECRET_ACCESS_KEY", "dummy_secret")),
"dynamodb_endpoint": URL(os.getenv("DYNAMODB_ENDPOINT", local_stack_endpoint)),
"dynamodb_endpoint": URL(os.getenv("DYNAMODB_ENDPOINT", moto_server_endpoint)),
"person_table_name": person_table_name,
"s3_endpoint": URL(os.getenv("S3_ENDPOINT", local_stack_endpoint)),
"s3_endpoint": URL(os.getenv("S3_ENDPOINT", moto_server_endpoint)),
"rules_bucket_name": rules_bucket_name,
"audit_bucket_name": audit_bucket_name,
"consumer_mapping_bucket_name": consumer_mapping_bucket_name,
"firehose_endpoint": URL(os.getenv("FIREHOSE_ENDPOINT", local_stack_endpoint)),
"firehose_endpoint": URL(os.getenv("FIREHOSE_ENDPOINT", moto_server_endpoint)),
"kinesis_audit_stream_to_s3": kinesis_audit_stream_to_s3,
"enable_xray_patching": enable_xray_patching,
"secretsmanager_endpoint": URL(os.getenv("SECRET_MANAGER_ENDPOINT", local_stack_endpoint)),
"secretsmanager_endpoint": URL(os.getenv("SECRET_MANAGER_ENDPOINT", moto_server_endpoint)),
"hashing_secret_name": hashing_secret_name,
"log_level": log_level,
}
52 changes: 52 additions & 0 deletions tests/docker-compose.lambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
include:
- docker-compose.moto.yml

services:
lambda-api:
image: public.ecr.aws/lambda/python:3.13
container_name: lambda-api
ports:
- "4567:8080"
platform: linux/amd64
volumes:
- ../dist/lambda.zip:/tmp/lambda.zip:ro
environment:
- AWS_ACCESS_KEY_ID=dummy_key
- AWS_SECRET_ACCESS_KEY=dummy_secret
- AWS_DEFAULT_REGION=eu-west-1
- PYTHONPATH=/var/task
- AWS_ENDPOINT_URL=http://moto-server:5000
- DYNAMODB_ENDPOINT=http://moto-server:5000
- S3_ENDPOINT=http://moto-server:5000
- SECRET_MANAGER_ENDPOINT=http://moto-server:5000
- FIREHOSE_ENDPOINT=http://moto-server:5000
- LOG_LEVEL=INFO
entrypoint: /bin/sh
command:
- "-c"
- |
mkdir -p /var/task &&
python3 -m zipfile -e /tmp/lambda.zip /var/task &&
exec /usr/local/bin/aws-lambda-rie python3 -m awslambdaric eligibility_signposting_api.app.lambda_handler
networks:
- test-network
depends_on:
moto-server:
condition: service_healthy


api-gateway-mock:
#used for api gateway simulation
image: openresty/openresty:alpine
ports:
- "9123:9123"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- lambda-api
networks:
- test-network

networks:
test-network:
driver: bridge
19 changes: 19 additions & 0 deletions tests/docker-compose.moto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
moto-server:
#used for s3, dynamodb, kinesis, secret manager
# lambda cannot be used, because its 3.11 (older)
image: motoserver/moto:latest
container_name: moto-server
ports:
- "4566:5000"
networks:
- test-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/"]
interval: 1s
timeout: 1s
retries: 30

networks:
test-network:
driver: bridge
20 changes: 0 additions & 20 deletions tests/docker-compose.yml

This file was deleted.

25 changes: 25 additions & 0 deletions tests/gateway.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function unwrap(r) {
r.subrequest('/proxy' + r.uri, { method: r.method }, function(reply) {

if (reply.status !== 200) {
r.return(502, "Lambda Bridge Error: " + reply.status);
return;
}

// Check for empty/undefined body
if (!reply.responseBody) {
ngx.log(ngx.ERR, "CRITICAL: Lambda returned 200 but body is EMPTY/UNDEFINED");
r.return(502, "Lambda returned empty response. Check Python logs for logic errors.");
return;
}

try {
var response = JSON.parse(reply.responseBody);
r.return(response.statusCode || 200, response.body || "");
} catch (e) {
ngx.log(ngx.ERR, "JSON Parse Error: " + e.message + " | Body: " + reply.responseBody);
r.return(502, "Invalid JSON from Lambda");
}
});
}
export default { unwrap };
Loading
Loading