Skip to content

Add layer-python example #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2024
Merged
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
9 changes: 9 additions & 0 deletions sample-apps/layer-python/function/lambda_function.py
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions sample-apps/layer-python/layer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM amazonlinux:2023
RUN dnf update && dnf install -y python3.11 zip && dnf clean all
7 changes: 7 additions & 0 deletions sample-apps/layer-python/layer/docker_install.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions sample-apps/layer-python/layer/docker_runner.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions sample-apps/layer-python/layer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.31.0