Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Langchain on AWS Lambda #20

Open
ali-chaudhry8 opened this issue Mar 1, 2023 · 9 comments
Open

Langchain on AWS Lambda #20

ali-chaudhry8 opened this issue Mar 1, 2023 · 9 comments

Comments

@ali-chaudhry8
Copy link

Has anyone deployed langchain scripts on AWS - Lambda in particular. There is some issue with the way langchain imports numpy that is causing issues. I have tried it with different version and with a docker image as well but get numpy import issues. Locally it works fine.

@ellisonbg
Copy link

@3coins is working this and can help out.

@KBB99
Copy link

KBB99 commented Apr 6, 2023

I can help. You need to make sure that you are installing the langchain library in the same runtime as the lambda. If you want you can use this public Langchain layer I've made that includes Langchain and OpenAI libraries: arn:aws:lambda:us-east-1:609061237212:layer:langchain:6 . For a full implementation guide of a Langchain agent on Lambda you can check this article

@animateM
Copy link

Could you tell us what libraries you put in that layer? So we can update / patch / etc with the latest langchain? Would be awesome to know! I am having a heck of a time getting past this numpy error on lambda.

@KBB99
Copy link

KBB99 commented May 16, 2023

That one is using ARM64 architecture. It includes the langchain and openai packages.

@animateM
Copy link

Hmmm. I imported both those. All that is in a layer. Still get the numpy errors... Oh well, switch to container image and X86, cause that is pretty sure to work.

@KBB99
Copy link

KBB99 commented Jun 7, 2023

If someone is still looking for a Lambda layer including Langchain I just built this one and made it public: arn:aws:lambda:us-east-1:609061237212:layer:langchain:9 . It is running Langchain version 0.0.191 on ARM64 architecture and I have confirmed it's compatibility with Python3.10. To fix conflicts with boto3 I had to pin urllib<2.

@animateM
Copy link

animateM commented Jun 7, 2023

Thank you. Yes, knowing exactly how you did it, so we can continue to update ourselves as langchain updates is important. I am finding that using a container image may be required just because of how large langchain libraries are.

@KBB99
Copy link

KBB99 commented Jun 7, 2023

Sure, I create a Codebuild job with ARM64 architecture using the latest Amazon Linux AMI and run the command mkidr package/python && pip install <package_names> --target package/python && zip -r package.zip package. I then set the artifact source to package.zip and specify an S3 bucket as the destination. Lastly, I create a Lambda layer, pointing to that zipped file in the S3 bucket. I'll try and create a blog post sometime where I go through the process in more details, but that is the high-level overview.

@animateM
Copy link

animateM commented Jun 7, 2023 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants