OpenAI AWS Lambda Layer (Open Source)

For anyone looking to deploy scalable and cost-efficient micro services using AWS Lambda for your OpenAI project, check out my repo:

You can also use Lambda concurrency to implement rate-limiting required by OpenAI!

5 Likes

hello, I modified your code to use 3.10 but it doesnā€™t work. Why donā€™t you use an official aws amazon linux ?

Nicely done @eren! Iā€™ve also published something somewhat similar. See FullStackWithLawrence/aws-openai.

This creates A REST API implementing each of the 30 example applications from the official OpenAI API Documentation. Implemented as a serverless microservice using AWS API Gateway, Lambda and the OpenAI Python Library. Leverages OpenAIā€™s suite of AI models, including GPT-3.5, GPT-4, DALLĀ·E, Whisper, Embeddings, and Moderation.

Cool, but why wouldnā€™t I just create my own lambda layer from the OpenAI SDK?

Is this for people that donā€™t know how to create their own layers? It only takes a few minutes! What am I missing?

1 Like

Same question here, but I get ā€œService Unavailableā€ messages when I try to call e.g. openai.audio.transcriptions.create with the OpenAI Node.js API from an AWS Lambda.

Do I need some kind of OpenAI Lambda layer if Iā€™m just using the OpenAI Node.js API?

Update: my issue could be Usage Limit related, investigatingā€¦

If it helps, when the Whisper API was first announced, I had trouble calling it. But you can call it directly without the SDK.

Here is a post where the Python version of that code lives, and this is what I run from Lambda.

1 Like

Hey, I see that the layer was built using the OpenAI version 0.27.4. I tried updating it by doin pip install openai==1.2.1, but when creating the layer in lambda and testing the code I am getting the error:

errorMessage": ā€œUnable to import module ā€˜lambda_functionā€™: No module named ā€˜openaiā€™ā€

Anyone mind helping out?

You get this sorted. I am having a hard time with the lambda layer when I try to import ā€œfrom openai import OpenAIā€

1 Like

I am having issues with this. Do you have a version for 3.11?

having the same issue when trying to use:
from openai import OpenAI

i have built my own OpenAI layer which works in AWS Lambda Layer:
from openai import OpenAI

you can download it from here.

1 Like

Was running into the same issue, your package saved the day. Much appreciated.

Hello sir, now I am facing this error. I am trying to implement asssitant in AWS Lambda but I do not have the updated version of Openai Library

Thanks

1 Like

Thanks a ton!! I was facing the same error and your package saved lots of time!