Skip to content

Commit

Permalink
Upgrade lambda runtime to python3.12 (#92)
Browse files Browse the repository at this point in the history
* Upgrade lambda runtime to python3.12

AWS announced they are ending support for Python 3.8 in Lambda on
October 14, 2023. This follows Python 3.8 End-Of-Life which is
scheduled October, 2024.

* Fix dependencies

* Reference issue in botocore

* Bump required provider version

* Bump Docker base image to python 3.12

---------

Co-authored-by: Ben Whaley <[email protected]>
  • Loading branch information
armona and bwhaley authored Apr 25, 2024
1 parent 01420b2 commit ed6f4de
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 1 addition & 1 deletion functions/replace-route/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
boto3==1.24.62
boto3==1.34.90
4 changes: 2 additions & 2 deletions functions/replace-route/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions functions/replace-route/tests/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.pytest.ini_options]
filterwarnings = [
'ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning', # https://github.com/boto/botocore/pull/3145
]
12 changes: 5 additions & 7 deletions functions/replace-route/tests/test_replace_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('..')

Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions functions/replace-route/tests/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions modules/terraform-aws-alternat/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/terraform-aws-alternat/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4"
version = ">= 5.32.0"
}
}
}

0 comments on commit ed6f4de

Please sign in to comment.