Python dependencies in AWS lambda - python

I am trying to create a lambda using python directly in the console and am stuck on installing a dependency. Is there a way to install dependencies in the console? I have tried a subprocess call but says I don't have permission to the folders.
I am used to doing lambdas in javascript and have deploy scripts for that. I just don't know how to translate that to python.

Related

Is there any way to import and run Python packages in Node.js or ReactJS?

I've written a Python program that I want to package and upload to the Python package index. After doing this, is there any way for me to import that Python package and use it in Node.js or ReactJS? I basically want to use the functions and classes in the Python package to get some information and show it in some frontend application.
I am not sure if there is any mode to access the packages directly, however, you sure can execute a python script from your Node.js backend by using the child_process package.
Reference:
How to call a Python function from Node.js

missing python language when i created azure function

I'm new for azure. i just tried to create azure function for python script, but under language list, python language is missing.
Firstly, you need create the Linux OS Function, for now the Python is not support on Windows OS. So when you create the Function you should choose the Linux OS then you will be able to choose the Python stack.
Secondly, after you create the function, for now in-portal file editing this feature is disabled, You could check this issue:In-portal editing will be disabled for Python Functions. So you have to use the Azure Functions Core Tools or VS Code extension. Then upload the local function to Azure.
You can use VS CODE for the same . Visual Studio 2017/2019 only supports C#.
You can install the package for VS CODE WITH
sudo apt-get install python3-venv

looking for a way to upgrade / downgrade inside Lambda

I need a way to upgrade/downgrade the boto3 lib inside my Python 3.7 env inside Lambda.
Right now, the version is 1.9.42 inside Lambda. I cannot use certain things like Textract (boto3.client('textract'), but I can on my local machine (boto3 version 1.9.138.
So, I decided to install boto3 into a package (pip3 install boto3 -t dir/ --system) then upload it to Lambda after zipping it.
This didn't work because Lambda won't accept a package larger than 3MB (it's around 8MB)
Any other workarounds?
edit: I know I could always just write code that works and keep uploading it to Lambda, but this will become cumbersome as I'd have to include all the packages installed in the package and rebuilding it as I make changes.
The Serverless Application Model is a tool provided by AWS that lets you develop locally as it simulates the lamdba environment inside a docker container. Once you are ready you can deploy your code to a lambda and it will work as expect.
If you really want to keep editing the code in the web platform, there is a workaround by using lambda layers. You create a package with all of your dependencies and upload that to a lambda layer. Then include your layer in the lambda and just modify your own code there. As it has been pointed out in the comments this is not the way to go for real development.

Jupyter Notebook Export Python file with dependencies

I have been trying hard to package a piece of Python code to be used on AWS Lambda. The problem is that I need the Python script developed in Notebook to be exported along with its dependencies, otherwise it causes various errors after uploading to AWS Lambda. What is the best way to go about this?
I want a .zip file with the .py file and all its dependencies
As described in your question and in comment, Apex will solve your problem. Apex lets you build, deploy, and manage AWS Lambda functions with ease.
You can read about it here and here and also watch video tutorial.
Hope it helps.

Aws Lambda: Python function with Pandas dependency

How to deploy to python function which has the dependency on external libraries?
For example, I am trying to deploy to a data-analysis python function. When I try to test the python function from the lambda console, I get:
Unable to import module 'lambda_function': No module named pandas
I am totally new to Aws Lambda
Is there a linux box on which Lambda functions run where I can install these libraries?
You need to create a deployment package as detailed here: http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html#deployment-pkg-for-virtualenv
This just means bundling the contents of site-packages for the environment you're developing on into the deployment package together with the lambda python script into a zip that is uploaded.
If you new to Lambda deployment, you might want check this tutorial (I wrote), which covers the most common pitfalls. And gives you a script as well to automate the entire process.

Categories

Resources