Unable to import module 'aws_encryption_sdk' from AWS Lambda function - python

I am trying to decrypt a file present in s3 bucket. I am using an AWS lambda function to do so.
Here the code that I want to execute using AWS Lambda (I'm using code entry type as Edit code inline):
import aws_encryption_sdk
with aws_encryption_sdk.stream(
mode='d',
source=src_file,
key_provider=kms_key
) as decryptor:
for block in decryptor:
tgt_file.write(block)
However, my AWS lambda function is failing with the error:
Unable to import module 'lambda_function': No module named aws_encryption_sdk
Isn't it possible to use aws_encryption_sdk in AWS Lambda? If it's possible, please guide me on how to use it.
Thanks in advance!

This is external python package. aws lambda provides Python environments for different python versions however if you want to use any of the external packages you should be uploading the package as part of your function package, for more details referpython packages for aws lambda

Related

How to import any module in AWS lambda which throw the Unable to import error

I am trying to scrape one website stuck with "errorMessage": "Unable to import module 'lambda_function': No module named 'requests'",
How to import any module in AWS lambda which throw the Unable to import error.
Disclaimer : I am not running on EC2 instance
i need to put x.text in the s3 bucket
code is below
import requests
x = requests.get('https://w3schools.com/python/demopage.htm')
print(x.text)
You have 2 choices for packaging extra python dependencies:
Run a pip install and zip the contents along with your Lambda function. Upload this Zip to your Python function.
Create a Lambda layer that you can then use with your Lambda function.
Regarding requests it is no longer included in the base Lambda setup.
AWS have a blog post that explains how to include these files in your codebase.
It also includes the AWS Arns for public Labda layers containing the requests dependency, although it does cap the SDK at a slightly older version.
In order to use external packages in AWS Lambda, as stated in official documentation, you should pack your dependencies along with your code and upload it all together.

no module found pyodbc in aws lambda for python mssql connection

AWS Lambda is showing me 'no module import error' for package pyodbc in my lambda function.
I've been using another library without error like this only getting error for this 'pyodbc' lib.
I've added pyodbc installing with pip to my python code directory and upload
them in zip to aws lambda.
You would need to ensure that the native libraries that pyodbc requires are present in the Lambda execution environment - either bundled as part of your deployment package or as a separate Lambda layer.
See https://medium.com/#narayan.anurag/breaking-the-ice-between-aws-lambda-pyodbc-6f53d5e2bd26 for more details about this.

how to use jwplatform api using python

I am going to create search api for Android and iOS developers.
Our client have setup a lambda function in AWS.
Now we need to fetch data using jwplatform Api based on search keyword passed as parameter. For this, I have to install jwplatform module in Lambda function or upload zip file of code with dependencies. So that i want to run python script locally and after getting appropriate result i will upload zip in AWS Lambda.
I want to use the videos/list (jwplatform Api) class to search the video library using python but i don't know much about Python. So i want to know how to run python script? and where should i put the pyhton script ?
There are a handful of useful Python script examples here: https://github.com/jwplayer/jwplatform-py
I am succeed to install jwplatform module locally.
Steps are as follows:
1. Open command line
2. Type 'python' on command line
3. Type command 'pip install jwplatform'
4. Now, you can use jwplatform api.
Above command added module jwplatform in python locally
But my another challenge is to install jwplatform in AWS Lambda.
After research i am succeed to install module in AWS Lambda. I have bundled module and code in a directory then create zip of bundle and upload it in AWS Lambda. This will install module(jwplatform) in AWS Lambda.

How does AWS know where my imports are?

I'm new to AWS Lambda and pretty new to Python.
I wanted to write a python lambda that uses the AWS API.
boto is the most popular python module to do this so I wanted to include it.
Looking at examples online I put import boto3 at the top of my Lambda and it just worked- I was able to use boto in my Lambda.
How does AWS know about boto? It's a community module. Are there a list of supported modules for Lambdas? Does AWS cache its own copy of community modules?
AWS Lambda's Python environment comes pre-installed with boto3. Any other libraries you want need to be part of the zip you upload. You can install them locally with pip install whatever -t mysrcfolder.
The documentation seems to suggest boto3 is provided by default on AWS Lambda:
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.
As far as I know, you will need to manually install any other dependencies in your deployment package, as shown in the linked documentation, using:
pip install foobar -t <project path>
AWS Lambda includes the AWS SDK for Python (Boto 3), so you don't need to include it in your deployment package.
This link will give you a little more in-depth info on Lambda environment
https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/
And this too
https://alestic.com/2014/12/aws-lambda-persistence/

How to create AWS Lambda deployment package that uses Couchbase Python client

I'm trying to use AWS Lambda to transfer data from my S3 bucket to Couchbase server, and I'm writing in Python. So I need to import couchbase module in my Python script. Usually if there are external modules used in the script, I need to pip install those modules locally and zip the modules and script together, then upload to Lambda. But this doesn't work this time. The reason is the Python client of couchbase works with the c client of couchbase: libcouchbase. So I'm not clear what I should do. When I simply add in the c client package (with that said, I have 6 package folders in my deployment package, the first 5 are the ones installed when I run "pip install couchbase": couchbase, acouchbase, gcouchbase, txcouchbase, couchbase-2.1.0.dist-info; and the last one is the c client of Couchbase I installed: libcouchbase), lambda doesn't work and said:
"Unable to import module 'lambda_function': libcouchbase.so.2: cannot open shared object file: No such file or directory"
Any idea on how I can get the this work? With a lot of thanks.
Following two things worked for me:
Manually copy /usr/lib64/libcouchbase.so.2 into ur project folder
and zip it with your code before uploading to AWS Lambda.
Use Python 2.7 as runtime on the AWS Lambda console to connect to couchbase.
Thanks !
Unfortunately AWS Lambda does not support executing C-based python modules, like the Couchbase SDK.
Your best bet would be to use a pure-python client. The easiest way to do this would be to use the unofficial memcached client https://github.com/couchbase/couchbase-cli/blob/master/cb_bin_client.py which uses server-side moxi to handle memcached clients on port 11211.

Categories