From 39bdd92de7a442bab453b3e61801bc88c4858db3 Mon Sep 17 00:00:00 2001 From: Alexander Yu Date: Thu, 22 Feb 2024 13:50:17 -0800 Subject: [PATCH] Add layer-python example --- sample-apps/layer-python/function/lambda_function.py | 9 +++++++++ sample-apps/layer-python/layer/Dockerfile | 2 ++ sample-apps/layer-python/layer/docker_install.sh | 7 +++++++ sample-apps/layer-python/layer/docker_runner.sh | 11 +++++++++++ sample-apps/layer-python/layer/requirements.txt | 1 + 5 files changed, 30 insertions(+) create mode 100644 sample-apps/layer-python/function/lambda_function.py create mode 100644 sample-apps/layer-python/layer/Dockerfile create mode 100644 sample-apps/layer-python/layer/docker_install.sh create mode 100755 sample-apps/layer-python/layer/docker_runner.sh create mode 100644 sample-apps/layer-python/layer/requirements.txt diff --git a/sample-apps/layer-python/function/lambda_function.py b/sample-apps/layer-python/function/lambda_function.py new file mode 100644 index 00000000..11ef4b5e --- /dev/null +++ b/sample-apps/layer-python/function/lambda_function.py @@ -0,0 +1,9 @@ +import requests + +def lambda_handler(event, context): + print(f"Version of requests library: {requests.__version__}") + request = requests.get('https://api.github.com/') + return { + 'statusCode': request.status_code, + 'body': request.text + } diff --git a/sample-apps/layer-python/layer/Dockerfile b/sample-apps/layer-python/layer/Dockerfile new file mode 100644 index 00000000..846893f4 --- /dev/null +++ b/sample-apps/layer-python/layer/Dockerfile @@ -0,0 +1,2 @@ +FROM amazonlinux:2023 +RUN dnf update && dnf install -y python3.11 zip && dnf clean all diff --git a/sample-apps/layer-python/layer/docker_install.sh b/sample-apps/layer-python/layer/docker_install.sh new file mode 100644 index 00000000..40f67711 --- /dev/null +++ b/sample-apps/layer-python/layer/docker_install.sh @@ -0,0 +1,7 @@ +python3.11 -m venv create_layer +source create_layer/bin/activate +pip install -r requirements.txt + +mkdir python +cp -r create_layer/lib python/ +zip -r layer_content.zip python diff --git a/sample-apps/layer-python/layer/docker_runner.sh b/sample-apps/layer-python/layer/docker_runner.sh new file mode 100755 index 00000000..5b7201d2 --- /dev/null +++ b/sample-apps/layer-python/layer/docker_runner.sh @@ -0,0 +1,11 @@ +container_name=lambda_python_layer_container +docker_image=lambda_python_layer_image:example + +docker run -td --name=$container_name $docker_image +docker cp ./requirements.txt $container_name:/ + +docker exec -i $container_name /bin/bash < ./docker_install.sh +docker cp $container_name:/layer_content.zip layer_content.zip + +docker stop $container_name +docker rm $container_name diff --git a/sample-apps/layer-python/layer/requirements.txt b/sample-apps/layer-python/layer/requirements.txt new file mode 100644 index 00000000..2c24336e --- /dev/null +++ b/sample-apps/layer-python/layer/requirements.txt @@ -0,0 +1 @@ +requests==2.31.0