No module named 'openpyxl'", - amazon-web-services

I am trying to write code using the AWS Lambda function to extract Pdf Invoice data from the AWS Textract Service and save the data into Excel. To do this, I installed the openpyxl library, created a zip file for it, and created a layer in lambda function that uses the openpyxl library. I am getting the following error ( No module named 'openpyxl'",). I would appreciate your assistance in resolving it.

Have you tried Textractor pip install amazon-textract-textractor? It comes built-in with the export-to-excel features and comes with the lamdba layers pre-built on the official GitHub repository: https://aws-samples.github.io/amazon-textract-textractor/using_in_lambda.html
Note that the available lamdba layer uses XlsxWriter instead of openpyxl.
Disclaimer: I am a maintainer of Textractor.

Related

"import requests" in AWS Lambda without a layer?

I've had a lambda function in Python 3.9 which is pretty simple. Just sends a post request. It has worked fine for the past few weeks.
I've deleted and remade the stack several times in CloudFormation, and have had no issues.
Randomly, today it started throwing the error
"errorMessage": "Unable to import module 'index': No module named 'requests'",
"errorType": "Runtime.ImportModuleError"
index.py is the name of the lambda function.
So I looked it up, and everyone says that 'requests' is not prepackaged into Lambda, and you need to create a layer where you manually install it into a zip etc.
How is this possible? It worked for weeks without having to create a layer, and the code was not touched.
But now 'import requests' just stops working?
There are of course other alternatives to the requests module. 'urllib' comes to mind. But this is bugging me. How is it possible that it worked for weeks, but randomly just stops being able to import this module?
Its like some kind of Mandela effect. Every single person says you need to create a venv, and package it with dependencies manually. I've never had to do that and it worked for AGES. I feel like im going crazy...
Did you possibly change the version of Python used by the function?
From Upcoming changes to the Python SDK in AWS Lambda | AWS Compute Blog:
In response to customer feedback, we have decided to cancel the change described in this blog post. The version of the AWS SDK included in the AWS Lambda runtimes for Python 2.7, Python 3.6 and Python 3.7 will continue to include the ‘requests’ module in Botocore. No action is required for customers using these runtimes. The Lambda runtimes for Python 3.8 and later do not include the ‘requests’ module. Customers using ‘requests’ with these runtimes should package the ‘requests’ module with their function code or as a Lambda layer.

ModuleNotFoundError: No module named 'aiohttp' in AWS Glue

I am using AWS glue to create ETL workflow, where I am fetching the data from the API and loading it into RDS. In AWS Glue, I used pyspark script. In the same script, I have used the 'aiohttp' and 'asyncio' modules of python to call my API asynchronously. But in AWS glue it is throwing me an error that Module Not found for the only aiohttp.
I have already tried with different versions of aiohttp module and tested in the glue job but still throwing me the same error. Can someone please help me with this topic?
Glue 2.0
AWS Glue version 2.0 lets you provide additional Python modules or different versions at the job level. You can use the --additional-python-modules job parameter with a list of comma-separated Python modules to add a new module or change the version of an existing module.
Also, within the --additional-python-modules option you can specify an Amazon S3 path to a Python wheel module.
This link to official documentation lists all modules already available. If you need a different version or need one to be installed, it can be specified in the parameter mentioned above.
Glue 1.0 & 2.0
You can zip the python library, upload it so s3 and specify the path as --extra-py-files job parameter.
See link to official documentation for more information.

Unable to import module Error in AWS Lambda Nodejs

I am working on an AWS Lambda where I need to use AWS Textract, for this, I have used AWS-SDK, with AWS-SDK I was able to import s3, but AWS Textract is not working, when I deploy and test it shows,
Unable to import module 'src/functions/routes/handler': Error
I think it has something to do with packaging, like may be It is not packaging the relevant file, but not sure and I don't know how to make it package if it is the problem, any suggestions are appreciated.
Since you have not given any code to go on, I will consider the possibility that you have properly written your import code and this error is a valid response to an issue. In that case, you should note that there are issues with importing Textract in Lambda via the aws-sdk. See this reported issue:
https://github.com/aws/aws-sdk-js/issues/2728
For a thorough and thoughtful example of using Textract with a Lambda service, consider this excellent article posted with complete details:
https://medium.com/#sumindaniro/aws-textract-with-lambda-walkthrough-ed4473aedd9d

how to import numpy and pandas inside aws lambda function?

i need to process csv file using numpy and pandas , i could do it in local machine its running as a expected manner then i am trying to do the same thing in aws lambda function with the same code i was used in my local machine.i am trying to import numpy inside my aws lambda function but error was thrown as Unable to import module 'aws_lambda_demo/lambda_function': No module named 'numpy'. then i create a zip file with aws lambda function along with numpy package after that also facing same issue Unable to import module 'aws_lambda_demo/lambda_function': No module named 'numpy'. Notes: i kept my csv files in s3 storage .any help will be appreciated . thanks in advance.
The problem is that your local numpy and pandas are compiled for the local machine's architecture. Since AWS Lambda uses custom Linux, they are probably not compatible.
So if you want to use them, you have two choices:
Compile dependencies on EC2 instance which uses the same Amazon Linux version as AWS Lambda and create a deployment package.
Use one of the precompiled packages from here

can we import specific version of botocore when implement Lambda in AWS?

when using cost explorer client in lambda function , 'ce' is not supported. but it may available in new version of botocore. so is it possible to import the new version of botocore in lambda python function ? if yes, how we can implement it. please provide some example
AWS Lambda provides a way to to use a version of Boto3 other than the one included by default, you can include it in your deployment package.
From Creating a Deployment Package (Python)
AWS Lambda includes the AWS SDK for Python (Boto 3), so you don't need
to include it in your deployment package. However, if you want to use
a version of Boto3 other than the one included by default, you can
include it in your deployment package.