diff --git a/platform/production/us-east-1/000/terraform.tfvars b/platform/production/us-east-1/000/terraform.tfvars new file mode 100644 index 0000000..db8aaa6 --- /dev/null +++ b/platform/production/us-east-1/000/terraform.tfvars @@ -0,0 +1,10 @@ +create_package = true +create = true +handler = "app.lambda_handler" +cors = { allow_origins = ["*"] } +source_path = "../../../../../../../src/function/" +name = "platform_sample-useast1-production-000-fn-000" +environment_variables = { + PAYLOAD = "Primary" +} + diff --git a/platform/production/us-east-1/000/terragrunt.hcl b/platform/production/us-east-1/000/terragrunt.hcl new file mode 100644 index 0000000..d9aaa73 --- /dev/null +++ b/platform/production/us-east-1/000/terragrunt.hcl @@ -0,0 +1,7 @@ +include "root" { + path = find_in_parent_folders() +} + +terraform { + source = "git::https://github.com/launchbynttdata/tf-aws-module_primitive-lambda_function//.?ref=1.0.3" +} \ No newline at end of file diff --git a/platform/production/us-east-2/000/terraform.tfvars b/platform/production/us-east-2/000/terraform.tfvars index 9edc1f4..8955673 100644 --- a/platform/production/us-east-2/000/terraform.tfvars +++ b/platform/production/us-east-2/000/terraform.tfvars @@ -3,4 +3,7 @@ create = true handler = "app.lambda_handler" cors = { allow_origins = ["*"] } source_path = "../../../../../../../src/function/" -name = "platform-sample-lambda-function" +name = "platform_sample-useast2-production-000-fn-000" +environment_variables = { + PAYLOAD = "Failover" +} diff --git a/platform/sandbox/us-east-2/000/terraform.tfvars b/platform/sandbox/us-east-2/000/terraform.tfvars index 9edc1f4..8bde537 100644 --- a/platform/sandbox/us-east-2/000/terraform.tfvars +++ b/platform/sandbox/us-east-2/000/terraform.tfvars @@ -3,4 +3,7 @@ create = true handler = "app.lambda_handler" cors = { allow_origins = ["*"] } source_path = "../../../../../../../src/function/" -name = "platform-sample-lambda-function" +name = "platform_sample-useast2-sandbox-000-fn-000" +environment_variables = { + PAYLOAD = "Primary-East" +} diff --git a/platform/sandbox/us-east-2/001/terraform.tfvars b/platform/sandbox/us-east-2/001/terraform.tfvars index cc149e0..1738c6f 100644 --- a/platform/sandbox/us-east-2/001/terraform.tfvars +++ b/platform/sandbox/us-east-2/001/terraform.tfvars @@ -1,6 +1,9 @@ create_package = true create = true -handler = "app.alternate_lambda_handler" +handler = "app.lambda_handler" cors = { allow_origins = ["*"] } source_path = "../../../../../../../src/function/" -name = "platform-sample-lambda-function-2" +name = "platform_sample-useast2-sandbox-001-fn-000" +environment_variables = { + PAYLOAD = "Failover-East" +} diff --git a/platform/sandbox/us-west-2/000/terraform.tfvars b/platform/sandbox/us-west-2/000/terraform.tfvars new file mode 100644 index 0000000..6405163 --- /dev/null +++ b/platform/sandbox/us-west-2/000/terraform.tfvars @@ -0,0 +1,9 @@ +create_package = true +create = true +handler = "app.lambda_handler" +cors = { allow_origins = ["*"] } +source_path = "../../../../../../../src/function/" +name = "platform_sample-uswest2-sandbox-000-fn-000" +environment_variables = { + PAYLOAD = "Primary-West" +} diff --git a/platform/sandbox/us-west-2/000/terragrunt.hcl b/platform/sandbox/us-west-2/000/terragrunt.hcl new file mode 100644 index 0000000..d9aaa73 --- /dev/null +++ b/platform/sandbox/us-west-2/000/terragrunt.hcl @@ -0,0 +1,7 @@ +include "root" { + path = find_in_parent_folders() +} + +terraform { + source = "git::https://github.com/launchbynttdata/tf-aws-module_primitive-lambda_function//.?ref=1.0.3" +} \ No newline at end of file diff --git a/platform/sandbox/us-west-2/001/terraform.tfvars b/platform/sandbox/us-west-2/001/terraform.tfvars new file mode 100644 index 0000000..52932fb --- /dev/null +++ b/platform/sandbox/us-west-2/001/terraform.tfvars @@ -0,0 +1,9 @@ +create_package = true +create = true +handler = "app.lambda_handler" +cors = { allow_origins = ["*"] } +source_path = "../../../../../../../src/function/" +name = "platform_sample-uswest2-sandbox-001-fn-000" +environment_variables = { + PAYLOAD = "Failover-West" +} diff --git a/platform/sandbox/us-west-2/001/terragrunt.hcl b/platform/sandbox/us-west-2/001/terragrunt.hcl new file mode 100644 index 0000000..d9aaa73 --- /dev/null +++ b/platform/sandbox/us-west-2/001/terragrunt.hcl @@ -0,0 +1,7 @@ +include "root" { + path = find_in_parent_folders() +} + +terraform { + source = "git::https://github.com/launchbynttdata/tf-aws-module_primitive-lambda_function//.?ref=1.0.3" +} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 7c19c7d..7816a03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ dependencies = [] dev = [ "pytest>=8.4.0", "pytest-cov>=6.2.1", + "pytest-mock>=3.14.1", "ruff>=0.11.13", ] @@ -52,4 +53,4 @@ exclude = [ "node_modules", "site-packages", ".venv", -] \ No newline at end of file +] diff --git a/src/function/app.py b/src/function/app.py index c765aa3..2d196e8 100644 --- a/src/function/app.py +++ b/src/function/app.py @@ -1,6 +1,10 @@ -def lambda_handler(event, context): - return {"statusCode": 200, "body": "Hello from a sample Python Lambda!"} +import os + +PAYLOAD = os.environ.get("PAYLOAD") -def alternate_lambda_handler(event, context): - return {"statusCode": 200, "body": "Hello from a different sample Python Lambda!"} +def lambda_handler(event, context): + return { + "statusCode": 200, + "body": f"Hello from a sample Python Lambda! Payload: {PAYLOAD}", + } diff --git a/test/unit/test_app.py b/test/unit/test_app.py index fa82f51..4912fb8 100644 --- a/test/unit/test_app.py +++ b/test/unit/test_app.py @@ -1,13 +1,18 @@ +from unittest.mock import patch + from function import app def test_primary_handler(): result = app.lambda_handler(None, None) assert result["statusCode"] == 200 - assert result["body"] == "Hello from a sample Python Lambda!" + assert result["body"] == "Hello from a sample Python Lambda! Payload: None" -def test_alternate_handler(): - result = app.alternate_lambda_handler(None, None) - assert result["statusCode"] == 200 - assert result["body"] == "Hello from a different sample Python Lambda!" +def test_primary_handler_with_payload(): + with patch.object(app, "PAYLOAD", "test_payload"): + result = app.lambda_handler(None, None) + assert result["statusCode"] == 200 + assert ( + result["body"] == "Hello from a sample Python Lambda! Payload: test_payload" + ) diff --git a/uv.lock b/uv.lock index 3ec04dd..f6656ff 100644 --- a/uv.lock +++ b/uv.lock @@ -107,6 +107,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/bc/16/4ea354101abb1287856baa4af2732be351c7bee728065aed451b678153fd/pytest_cov-6.2.1-py3-none-any.whl", hash = "sha256:f5bc4c23f42f1cdd23c70b1dab1bbaef4fc505ba950d53e0081d0730dd7e86d5", size = 24644 }, ] +[[package]] +name = "pytest-mock" +version = "3.14.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/71/28/67172c96ba684058a4d24ffe144d64783d2a270d0af0d9e792737bddc75c/pytest_mock-3.14.1.tar.gz", hash = "sha256:159e9edac4c451ce77a5cdb9fc5d1100708d2dd4ba3c3df572f14097351af80e", size = 33241 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b2/05/77b60e520511c53d1c1ca75f1930c7dd8e971d0c4379b7f4b3f9644685ba/pytest_mock-3.14.1-py3-none-any.whl", hash = "sha256:178aefcd11307d874b4cd3100344e7e2d888d9791a6a1d9bfe90fbc1b74fd1d0", size = 9923 }, +] + [[package]] name = "python-platform-sample-lambda-function" version = "0.0.0" @@ -116,6 +128,7 @@ source = { virtual = "." } dev = [ { name = "pytest" }, { name = "pytest-cov" }, + { name = "pytest-mock" }, { name = "ruff" }, ] @@ -125,6 +138,7 @@ dev = [ dev = [ { name = "pytest", specifier = ">=8.4.0" }, { name = "pytest-cov", specifier = ">=6.2.1" }, + { name = "pytest-mock", specifier = ">=3.14.1" }, { name = "ruff", specifier = ">=0.11.13" }, ]