0

How can I establish a connection with the SQL database in Lambda function using Node.js? I want to get and post data in SQL database.

Thanks

Talenel
  • 422
  • 2
  • 6
  • 25
Rafaqat Ali
  • 676
  • 7
  • 26
  • 3
    Please post what you have so far – Arun Kamalanathan Dec 07 '19 at 23:17
  • 1
    Just a tip here as well: lambda execution envitonments "freeze" when they are done and "unfreeze" when they start. So you can establish a db connection once outside the handler function and let it persist through multiple invocations. Just add some code to check if the connection still exists. Good luck! – adamkgray Dec 08 '19 at 02:00

1 Answers1

0

Running nodejs code in lambda is same as running same code on any other server or your local machine. You get the same nodejs runtime. There might be limitations when it comes to lambda such as package size, but there is no difference in how the code is executed.

The link below shows, how to connect to mysql from nodejs https://www.w3schools.com/nodejs/nodejs_mysql_select.asp

if you are specifically expecting mysql in lambda, this article may be a good start. https://blog.risingstack.com/getting-started-with-aws-lambda-and-node-js/

or else if you want to use mssql with lambda, look at this SO question. AWS Lambda and SQL Server Integration

Arun Kamalanathan
  • 8,107
  • 4
  • 23
  • 39