Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

feat: Add python3.9 runtime #348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:nodejs12.x app.my
# Test a `lambda_handler` function in `lambda_function.py` with an empty event on Python 3.8
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:python3.8 lambda_function.lambda_handler

# Test a `lambda_handler` function in `lambda_function.py` with an empty event on Python 3.9
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:python3.9 lambda_function.lambda_handler

# Similarly with Ruby 2.7
docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:ruby2.7 lambda_function.lambda_handler

Expand Down Expand Up @@ -230,6 +233,9 @@ docker run --rm -v "$PWD":/var/task lambci/lambda:build-nodejs12.x npm rebuild -
# To install defined poetry dependencies
docker run --rm -v "$PWD":/var/task lambci/lambda:build-python3.8 poetry install

# To install defined poetry dependencies
docker run --rm -v "$PWD":/var/task lambci/lambda:build-python3.9 poetry install

# To resolve dependencies on go1.x (working directory is /go/src/handler)
docker run --rm -v "$PWD":/go/src/handler lambci/lambda:build-go1.x go mod download

Expand All @@ -242,6 +248,12 @@ docker run --rm lambci/lambda:build-python3.8 aws --version

# To run an interactive session on a build container
docker run -it lambci/lambda:build-python3.8 bash

# Run custom commands on a build container
docker run --rm lambci/lambda:build-python3.9 aws --version

# To run an interactive session on a build container
docker run -it lambci/lambda:build-python3.9 bash
```

## Using a Dockerfile to build
Expand Down Expand Up @@ -307,6 +319,7 @@ These follow the Lambda runtime names:
- `python3.6`
- `python3.7`
- `python3.8`
- `python3.9`
- `ruby2.5`
- `ruby2.7`
- `java8`
Expand All @@ -327,6 +340,7 @@ These follow the Lambda runtime names:
- `build-python3.6`
- `build-python3.7`
- `build-python3.8`
- `build-python3.9`
- `build-ruby2.5`
- `build-ruby2.7`
- `build-java8`
Expand Down
69 changes: 69 additions & 0 deletions base/dump-python39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from __future__ import print_function

import os
import sys
import subprocess
import json
import boto3
from boto3.s3.transfer import S3Transfer

TRANSFER = S3Transfer(boto3.client("s3"))


def lambda_handler(event, context):
if "cmd" in event:
return print(
subprocess.check_output(["sh", "-c", event["cmd"]]).decode("utf-8")
)

filename = "python3.9.tgz"

subprocess.call(
[
"sh",
"-c",
f"tar -cpzf /tmp/{filename} --numeric-owner --ignore-failed-read "
+ "/var/runtime /var/lang /var/rapid",
]
)

print("Zipping done! Uploading...")

TRANSFER.upload_file(
f"/tmp/{filename}",
"lambci",
f"fs/{filename}",
extra_args={"ACL": "public-read"},
)

print("Uploading done!")

info = {
"sys.executable": sys.executable,
"sys.argv": sys.argv,
"sys.path": sys.path,
"os.getcwd": os.getcwd(),
"__file__": __file__,
"os.environ": {k: str(v) for k, v in os.environ.items()},
"context": {k: str(v) for k, v in context.__dict__.items()},
"proc environ": subprocess.check_output(
["sh", "-c", "echo /proc/1/environ; xargs -n 1 -0 < /proc/1/environ"]
)
.decode("utf-8")
.splitlines(),
"ps aux": subprocess.check_output(
[
"bash",
"-O",
"extglob",
"-c",
"for cmd in /proc/+([0-9])/cmdline; do echo $cmd; xargs -n 1 -0 < $cmd; done",
]
)
.decode("utf-8")
.splitlines(),
}

print(json.dumps(info, indent=2))

return info
2 changes: 1 addition & 1 deletion base/runtimes.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1"
RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 provided.al2 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1 python3.9"
2 changes: 2 additions & 0 deletions base/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ docker run --rm -v "$PWD":/var/task lambci/lambda:python2.7
docker run --rm -v "$PWD":/var/task lambci/lambda:python3.6
docker run --rm -v "$PWD":/var/task lambci/lambda:python3.7 lambda_function.lambda_handler
docker run --rm -v "$PWD":/var/task lambci/lambda:python3.8 lambda_function.lambda_handler
docker run --rm -v "$PWD":/var/task lambci/lambda:python3.9 lambda_function.lambda_handler

cd ${EXAMPLES_DIR}/python
docker run --rm -it lambci/lambda:build-python2.7 pip install marisa-trie
docker run --rm -it lambci/lambda:build-python3.6 pip install marisa-trie
docker run --rm -it lambci/lambda:build-python3.7 pip install marisa-trie
docker run --rm -it lambci/lambda:build-python3.8 pip install marisa-trie
docker run --rm -it lambci/lambda:build-python3.9 pip install marisa-trie

cd ${EXAMPLES_DIR}/ruby
docker run --rm -v "$PWD":/var/task lambci/lambda:ruby2.5 lambda_function.lambda_handler
Expand Down
24 changes: 24 additions & 0 deletions python3.9/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM lambci/lambda:python3.9

FROM lambci/lambda-base-2:build

ENV PATH=/var/lang/bin:$PATH \
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
AWS_EXECUTION_ENV=AWS_Lambda_python3.9 \
PKG_CONFIG_PATH=/var/lang/lib/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig \
PIPX_BIN_DIR=/var/lang/bin \
PIPX_HOME=/var/lang/pipx

COPY --from=0 /var/runtime /var/runtime
COPY --from=0 /var/lang /var/lang
COPY --from=0 /var/rapid /var/rapid

# Add these as a separate layer as they get updated frequently
RUN pip install -U pip setuptools wheel --no-cache-dir && \
pip install pipx --no-cache-dir && \
pipx install virtualenv && \
pipx install pipenv && \
pipx install poetry==1.1.4 && \
pipx install awscli==1.* && \
pipx install aws-lambda-builders==1.2.0 && \
pipx install aws-sam-cli==1.15.0
22 changes: 22 additions & 0 deletions python3.9/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM lambci/lambda-base

RUN curl https://lambci.s3.amazonaws.com/fs/python3.9.tgz | tar -zx -C /opt


FROM lambci/lambda:provided


FROM lambci/lambda-base-2

ENV PATH=/var/lang/bin:$PATH \
LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \
AWS_EXECUTION_ENV=AWS_Lambda_python3.9

COPY --from=0 /opt/* /var/

COPY --from=1 /var/runtime/init /var/rapid/init

USER sbx_user1051

ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"]