Lambda Layer for ARM64 architecture

2021年12月21日

-
In some cases, Python code need to run in Lambda with ARM64 architecture together with one or more Lambda layers. After investigation and experiment, it is found not necessary to have its Lambda layer to be built by a machine with ARM64 architecture. When publish the Lambda layer, the only thing need to do is to specify the architecture it belongs to. In other words, arm64 and/or x86_64.

However, one could still leverage ARM64 architecture EC2 instance, e.g., t4g-series, to build Lambda layers for cost efficiency.

Below are some general steps.

Launch EC2 with Amazon Linux 2 AMI - ARM64
Instance type and size: t4g.micro

Install Python 3.
# amazon-linux-extras install -y python3.8

Install AWS CLI v2.
# curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"

# unzip awscliv2.zip

# ./aws/install


# yum install -y python38-devel

# python3.8 -m pip install --upgrade pip

Prepare Lambda layer package.
# mkdir python
# cd python/

# python3.8 -m pip install --target /root/python gremlinpython --ignore-installed

# cd ..
# zip -r gremlinpython.zip ./python

Publish Lambda layer with architecture specification.
# /usr/local/bin/aws lambda publish-layer-version --layer-name lambdalayer-gremlinpython-py38-arm64 --description "gremlinpython for Python-3.8 ARM64-arch" --compatible-architectures arm64 x86_64 --compatible-runtimes python3.8 --zip-file fileb://gremlinpython.zip --region us-west-2


References


pip error: No such file or directory: '/tmp/pip-...-build/setup.py' #56

publish-layer-version
-

Category: AWS Tags: public

Upvote


Downvote