How to install pymysql on AWS lambda

I looked here and here as I “We tried to figure out how to get pymysql on AWS lambda. The examples that I have reviewed so far are extremely complex, and with the GitHub tutorial I got to IAM before I started working with permission errors, which I did not know how to solve them.

Literally, all I want to do is call import pymysql on the AWS ready-made lambda console template.

This seems like a simple problem, but it's hard for me to find a clear, step-by-step work on how to make new dependencies work for my lambda function. Ideally, the example would not be through the AWS CLI, since there is apparently a console option, and it looks like some kind of headache will come out of this process.

Greetings

Aaron

+5
source share
2 answers

I ran into a similar problem with the python Redis library. I follow the same documentation instructions that you mentioned in your second link.

Here is an example snippet for your reference:

Create a new directory MyPythonLambda and put MyPythonLambda.py in the same.

Suppose MyPythonLambda / MyPythonLambda.py is the main handler containing lambda.

  cd MyPythonLambda/ pip install redis -t . zip -r MyPythonLambda.zip * 

Download / import zip in creating lambda from S3 or local file system.

I think you need to create a zip file in a similar way containing your python mysql library.

+6
source

TheYoungSoul has a great YouTube example of how to do this step by step. Once I followed these instructions, it was pretty easy to do.

Steps:

  • Write a locally verifiable version of the routine that I want to implement on lambda, and call this function main.py main.py has inside itself a lambda_handler function, which has the basic structure def lambda_handler(event, context): ...

  • Use the create_deployment.py script available in your repo along with requirements.txt to create your deployment zip file. Please note that if you are on a Mac and these errors occur the first time you try , you may need to do this .

  • As soon as you run the locally tested example, create your lambda function on AWS and instead of recording from scratch, select the console menu option to download the ZIP file.

  • Be sure to create a custom role that has access to RDS resources, and be sure to place the database you want to connect to in the same VPC group. When setting up your function, specify that you want your lambda function to have access to the VPC.

+1
source

Source: https://habr.com/ru/post/1259563/


All Articles