How to Query RDS MySQL From AWS Lambda in Python | Step by Step Tutorial
Trying to connect to RDS from a Lambda function but having Trouble? This is the video for you.
Part 1 – Create a RDS MySQL Database – https://youtu.be/Ng_zi11N4_c
02:11 Installing Pymysql
03:00 Writing our Lambda Handler Function with Python
07:45 Preparing your handler and dependencies for Lambda
08:26 Creating our Lambda Function
10:43 Testing our Function
🎉 SUPPORT BE A BETTER DEV 🎉
Become a Patron: https://www.patreon.com/beabetterdev
📚 MY RECOMMENDED READING LIST FOR SOFTWARE DEVELOPERS📚
Clean Code – https://amzn.to/37T7xdP
Clean Architecture – https://amzn.to/3sCEGCe
Head First Design Patterns – https://amzn.to/37WXAMy
Domain Driver Design – https://amzn.to/3aWSW2W
Code Complete – https://amzn.to/3ksQDrB
The Pragmatic Programmer – https://amzn.to/3uH4kaQ
Algorithms – https://amzn.to/3syvyP5
Working Effectively with Legacy Code – https://amzn.to/3kvMza7
Refactoring – https://amzn.to/3r6FQ8U
🎙 MY RECORDING EQUIPMENT 🎙
Shure SM58 Microphone – https://amzn.to/3r5Hrf9
Behringer UM2 Audio Interface – https://amzn.to/2MuEllM
XLR Cable – https://amzn.to/3uGyZFx
Acoustic Sound Absorbing Foam Panels – https://amzn.to/3ktIrY6
Desk Microphone Mount – https://amzn.to/3qXMVIO
Logitech C920s Webcam – https://amzn.to/303zGu9
Fujilm XS10 Camera – https://amzn.to/3uGa30E
Fujifilm XF 35mm F2 Lens – https://amzn.to/3rentPe
Neewer 2 Piece Studio Lights – https://amzn.to/3uyoa8p
💻 MY DESKTOP EQUIPMENT 💻
Dell 34 inch Ultrawide Monitor – https://amzn.to/2NJwph6
Autonomous ErgoChair 2 – https://bit.ly/2YzomEm
Autonomous SmartDesk 2 Standing Desk – https://bit.ly/2YzomEm
MX Master 3 Productivity Mouse – https://amzn.to/3aYwKVZ
Das Keyboard Prime 13 MX Brown Mechanical- https://amzn.to/3uH6VBF
Veikk A15 Drawing Tablet – https://amzn.to/3uBRWsN
📚 References:
Part 1 – How to connect to AWS RDS MySQL: https://youtu.be/Ng_zi11N4_c
Getting started with AWS: https://youtu.be/lTyqzyk86f8
Code: https://pastebin.com/X0Yq9t0S
☁Topics covered include:
RDS MySQL Connection
Lambda RDS IAM Permissions
Pymysql for Querying RDS MySQL
🌎 Find me here:
Twitter – https://twitter.com/BeABetterDevv
Instagram – https://www.instagram.com/beabetterdevv/
Patreon – Donations help fund additional content – https://www.patreon.com/beabetterdev
#AWS
#Serverless
#RDS
#MySQL
source
Leave us a comment Cancel reply
COMMON QUESTIONS
Categories
- Agile Coach
- ARTIFICIAL INTELLIGENCE
- Block chain
- Business Analyst BA
- DATA science
- Development
- Devops Automation
- Dotnet
- Education
- Free Job training and assistance
- Information
- Infrastructure automation
- Interview questions
- JAVA
- jobs
- Learn
- Machine learning
- Python Automation
- QA Automation
- RPA Automation
- SAP crm
- Scrum master Agile
- Skill
- UI Design
- Uncategorized
22 Comments
jumboliah13 Kipfer
May 13, 2022 07:11 amOh, I've been searching for this one. THANKS!!
manikanta alapati
May 13, 2022 07:11 am"errorMessage": "Unable to import module 'lambda_function': No module named 'lambda_function'",
"errorType": "Runtime.ImportModuleError",
"requestId": "a0df413f-957b-42ca-a37a-ef4788c347b1",
"stackTrace": []
I am getting this error , can anyone tell me what to do?
Venkatesh Polisetty
May 13, 2022 07:11 amIt's fantastic that you have explained it very well. I want to know that is it possible to create a table in aws RDS Instance itself without configuring with local mysql db?
TheDoud33
May 13, 2022 07:11 amThanks a lot for this video 🙂
Using SAM, I deployed a lambda function, and it's supposed to connect to a postgre DB (it is working locally).
Next step, I created an Aurora postgre serverless RDS (not using dataAPI).
VPC, subnets and security group were created during RDS creation.
And Lambda was deployed on same VPC and security group. IAM role seems ok.
But I'm getting a timeout error when trying to access the DB (through the API gateway).
Is there some network routing or anything else to set so that my lambda can connect the RDS ?
Thanks a lot (again)
Max Moor
May 13, 2022 07:11 amHi, excellent video, is it possible that you make a video to connect to SQL Server RDS from Lambda function? I will buy you donuts whenever we meet 😃thanks
marcin2x4
May 13, 2022 07:11 amI'm getting error: `No module named pymssql._pymssql`…
Evan Erickson
May 13, 2022 07:11 amAny idea what this means?
Traceback (most recent call last):
File "handler.py", line 1, in <module>
import pymysql
File "/Users/zhangyiwan/code/python/pythonRdsQuery/pymysql/__init__.py", line 59, in <module>
from . import connections # noqa: E402
File "/Users/zhangyiwan/code/python/pythonRdsQuery/pymysql/connections.py", line 167
*,
^
SyntaxError: invalid syntax
mustafa aydın
May 13, 2022 07:11 amThanks for the great tutorial. I hava a question. What if we have a code including many libraries (many imports) and also some compiled functions in it via numba,cpython etc? I am asking this since in every api trigger, the imports and compilations will be also recalled which creates unnecessary overheads. How can it be overcome?
Ghanshyam Khatri
May 13, 2022 07:11 amgreat video !!
yTek
May 13, 2022 07:11 amHelpful. Thanks.
Satya K
May 13, 2022 07:11 amSo each lambda will have its own db connection object ? Is it there any benefit with common util function that can provide connection object to these lambda?
Wai Yan Leung
May 13, 2022 07:11 amHow should I modify your lambda function to connect with API gateway?
High Volume
May 13, 2022 07:11 amIf anyone can help: I am trying to pass the queryStringParameters to pymysql query to get the desired result for user selection
param = event['queryStringParameters']['param']
query = "select from xxxx where param = %s",(param,)
but the value i am passing is turning to be null, any suggestion or solution approach
LM SM
May 13, 2022 07:11 amthanks a lot for your videos !
Md Nababuddin
May 13, 2022 07:11 amHi Can you explain how to connect Private RDS using Lambda?
Alex Ma
May 13, 2022 07:11 ammay I know is it possible to create a "GET" api to query MySQL through lambda function?
Abhay Nayak
May 13, 2022 07:11 amHey this is great place to begin with AWS db and lambda, Could you also make a similar play through video on using database proxy, environment variables and other best practices for production? Would love to understand the best practices you follow in prod.
Ruth Kiruki
May 13, 2022 07:11 amJus t a quick question: Do you need to attach the lambda and RDS to the same VPC for this to work?
Anand Kumar
May 13, 2022 07:11 am22,020 views•Apr 20, 2020
nice number
Georgia-PRO
May 13, 2022 07:11 amhello , thank you for the video , how do you do if you want to setup an api and a json formatted return ?
Akash Narvekar
May 13, 2022 07:11 amThis is an awesome Tutorial .. Short and Simple. Very Nicely explained.. Keep making these kind of videos .. Its gonna help lots of People to learn AWS without going through the lengthy tutorials we see these days.. Liked and Subscribed .. 🙂
tpol45
May 13, 2022 07:11 amThis is great and really well explained. Thanks!