https://github.com/syedfaiqueali/aws-lambda-layer-openai
Guide to make aws custom lambda layer to support openai
https://github.com/syedfaiqueali/aws-lambda-layer-openai
aws-lambda
Last synced: 6 months ago
JSON representation
Guide to make aws custom lambda layer to support openai
- Host: GitHub
- URL: https://github.com/syedfaiqueali/aws-lambda-layer-openai
- Owner: syedfaiqueali
- License: mit
- Created: 2024-07-04T06:09:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-28T18:15:33.000Z (about 1 year ago)
- Last Synced: 2025-02-10T00:26:45.656Z (8 months ago)
- Topics: aws-lambda
- Homepage:
- Size: 4.65 MB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aws-lambda-layer-openai
This repository provides steps to create a **custom AWS Lambda layer** for the ```OpenAI``` library, including the latest version .zip file for direct deployment.
## Step 1: Create a virtual environment
Create a Python virtual environment and activate it.```bash
# Create the aws-lambda-layer directory and navigate into it
mkdir aws-lambda-layer
cd aws-lambda-layer# Create a virtual environment named 'myenv' with Python 3.10
python3.10 -m venv myenv# Activate the virtual environment
source ./myenv/bin/activate
```## Step 2: List your dependencies in requirements.txt
The ```OpenAi``` Python library depends on quite a few other libraries. Make sure to list all of them in the ```requirements.txt``` file along with their desired versions. This ensures that all their built distributions are installed with respect to your targeted platform. Place your **requirements.txt** file inside the above directory **aws-lambda-layer**## Step 3: Install built distributions (wheels)
To download a wheel that’s compatible with Lambda, you use the pip --platform option.If your Lambda function uses the **x86_64** instruction set architecture, run the following ```pip install``` command to install a compatible wheel in your package directory. Replace ```--python 3.x``` with the version of the Python runtime you are using.
```bash
pip install \
--platform manylinux2014_x86_64 \
--target=package \
--implementation cp \
--python-version 3.10 \
--only-binary=:all: --upgrade \
-r requirements.txt
```If your Lambda function uses the **arm64** instruction set architecture, run the following ```pip install``` command to install a compatible wheel in your package directory. Replace ```--python 3.x``` with the version of the Python runtime you are using.
```bash
pip install \
--platform manylinux2014_aarch64 \
--target=package \
--implementation cp \
--python-version 3.10 \
--only-binary=:all: --upgrade \
-r requirements.txt
```## Step 4: Deactivate the environment
```bash
deactivate
```## Step 5: Create a .zip file for the downloaded packages
```bash
# Create the 'python' folder
mkdir python# Copy all contents from 'package' to 'python'
cp -r package/* python/# Zip the 'python' folder
zip -r .zip python
```## Step 6: Upload the .zip file as custom layer over aws console
1. Navigate to Lambda -> Layers
2. Press **Create Layer**
3. Write your layer name, description
4. Upload **.zip file**
5. Choose compatible architectures *(x86_64, arm64)*
6. Choose compatible runtimes *(Python3.10, Python3.11, Python3.12)*
7. Press Create