diff --git a/Dockerfile b/Dockerfile index 557c2af..4e24514 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM public.ecr.aws/lambda/python:3.8 +FROM public.ecr.aws/lambda/python:3.12 # Copy function code COPY functions/replace-route/app.py ${LAMBDA_TASK_ROOT} diff --git a/functions/replace-route/requirements.txt b/functions/replace-route/requirements.txt index 434823c..e64d1e7 100644 --- a/functions/replace-route/requirements.txt +++ b/functions/replace-route/requirements.txt @@ -1 +1 @@ -boto3==1.24.62 +boto3==1.34.90 diff --git a/functions/replace-route/template.yaml b/functions/replace-route/template.yaml index e2a480e..7c529cc 100644 --- a/functions/replace-route/template.yaml +++ b/functions/replace-route/template.yaml @@ -5,11 +5,11 @@ Resources: Type: AWS::Serverless::Function Properties: Handler: app.handler - Runtime: python3.8 + Runtime: python3.12 Timeout: 30 ConnectivityTestFunction: Type: AWS::Serverless::Function Properties: Handler: app.connectivity_test_handler - Runtime: python3.8 + Runtime: python3.12 Timeout: 30 diff --git a/functions/replace-route/tests/pyproject.toml b/functions/replace-route/tests/pyproject.toml new file mode 100644 index 0000000..bdf1c8b --- /dev/null +++ b/functions/replace-route/tests/pyproject.toml @@ -0,0 +1,4 @@ +[tool.pytest.ini_options] +filterwarnings = [ + 'ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning', # https://github.com/boto/botocore/pull/3145 +] diff --git a/functions/replace-route/tests/test_replace_route.py b/functions/replace-route/tests/test_replace_route.py index 78e2d65..85ca32e 100644 --- a/functions/replace-route/tests/test_replace_route.py +++ b/functions/replace-route/tests/test_replace_route.py @@ -13,7 +13,7 @@ import boto3 import sure -from moto import mock_autoscaling, mock_ec2, mock_iam, mock_lambda +from moto import mock_aws sys.path.append('..') @@ -25,7 +25,7 @@ EXAMPLE_AMI_ID = "ami-12c6146b" -@mock_ec2 +@mock_aws def setup_networking(): az = f"{os.environ['AWS_DEFAULT_REGION']}a" ec2 = boto3.resource("ec2") @@ -113,8 +113,7 @@ def verify_nat_gateway_route(mocked_networking): zero_route.should.have.key("NatGatewayId").equals(mocked_networking["nat_gw"]) -@mock_autoscaling -@mock_ec2 +@mock_aws def test_handler(): mocked_networking = setup_networking() ec2_client = boto3.client("ec2") @@ -149,7 +148,7 @@ def test_handler(): verify_nat_gateway_route(mocked_networking) -@mock_iam +@mock_aws def get_role(): iam = boto3.client("iam") return iam.create_role( @@ -177,8 +176,7 @@ def _process_lambda(func_str): return zip_output.read() -@mock_lambda -@mock_ec2 +@mock_aws @mock.patch('urllib.request.urlopen') def test_connectivity_test_handler(mock_urlopen): from app import connectivity_test_handler diff --git a/functions/replace-route/tests/test_requirements.txt b/functions/replace-route/tests/test_requirements.txt index ef1a99d..da53d7e 100644 --- a/functions/replace-route/tests/test_requirements.txt +++ b/functions/replace-route/tests/test_requirements.txt @@ -1,3 +1,3 @@ -moto[ec2,autoscaling,iam,awslambda]==4.0.6 -pytest==7.1.3 +moto==5.0.5 +pytest==8.1.1 sure==2.0.0 diff --git a/modules/terraform-aws-alternat/lambda.tf b/modules/terraform-aws-alternat/lambda.tf index 919346b..166f354 100644 --- a/modules/terraform-aws-alternat/lambda.tf +++ b/modules/terraform-aws-alternat/lambda.tf @@ -5,6 +5,7 @@ locals { : replace(upper(obj.az), "-", "_") => join(",", obj.route_table_ids) } has_ipv6_env_var = { "HAS_IPV6" = var.lambda_has_ipv6 } + lambda_runtime = "python3.12" } data "archive_file" "lambda" { @@ -28,7 +29,7 @@ resource "aws_lambda_function" "alternat_autoscaling_hook" { image_uri = var.lambda_package_type == "Image" ? "${var.alternat_image_uri}:${var.alternat_image_tag}" : null - runtime = var.lambda_package_type == "Zip" ? "python3.8" : null + runtime = var.lambda_package_type == "Zip" ? local.lambda_runtime : null handler = var.lambda_package_type == "Zip" ? var.lambda_handlers.alternat_autoscaling_hook : null filename = var.lambda_package_type == "Zip" ? data.archive_file.lambda[0].output_path : null source_code_hash = var.lambda_package_type == "Zip" ? data.archive_file.lambda[0].output_base64sha256 : null @@ -138,7 +139,7 @@ resource "aws_lambda_function" "alternat_connectivity_tester" { image_uri = var.lambda_package_type == "Image" ? "${var.alternat_image_uri}:${var.alternat_image_tag}" : null - runtime = var.lambda_package_type == "Zip" ? "python3.8" : null + runtime = var.lambda_package_type == "Zip" ? local.lambda_runtime : null handler = var.lambda_package_type == "Zip" ? var.lambda_handlers.connectivity_tester : null filename = var.lambda_package_type == "Zip" ? data.archive_file.lambda[0].output_path : null source_code_hash = var.lambda_package_type == "Zip" ? data.archive_file.lambda[0].output_base64sha256 : null diff --git a/modules/terraform-aws-alternat/versions.tf b/modules/terraform-aws-alternat/versions.tf index 143b40d..869f362 100644 --- a/modules/terraform-aws-alternat/versions.tf +++ b/modules/terraform-aws-alternat/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 4" + version = ">= 5.32.0" } } }