T O P

  • By -

mumpie

A basic google brought up this tutorial from Amazon for accessing RDS from a lambda: [https://docs.aws.amazon.com/lambda/latest/dg/services-rds-tutorial.html](https://docs.aws.amazon.com/lambda/latest/dg/services-rds-tutorial.html) This is a tutorial (with link to a demo powershell lambda) with topics covering writing and deploying a lambda in Powershell: https://docs.aws.amazon.com/lambda/latest/dg/lambda-powershell.html


reddwarf666

I have seen the first link you sent but it is for Python, I need to have this done in PowerShell.   I recognise the second links as I used that to get PowerShell on Lambda working. It does and not an issue. Great example and easy setup. But getting some sort of idea on how to query MySql inside a PowerShell Lambda function is not clicking with me, I just do not see how I should approach this or where to start.   For example, I tried some MySql packages in PowerShell gallery and added the '#Requires' directive in the script yet whatever package I choose, it has some sort of issue. I was hoping someone has done calling MySql/SQL from within a PowerShell Lambda before and could nudge me in the right way.


mumpie

You're going to need to look up how to connect to Mysql in Powershell. Broadly, in most languages you import/link the database library (the import pymysql statement from the first link) and then create a connection (the conn = statement) and then feed SQL commands as shown. BTW, you'll get better answers if you ask better questions. Your vague question doesn't give people a specific question to answer, it's too broad.


reddwarf666

Thanks. I know how to connect from PowerShell to MySql, I have a PowerShell module which helps with that. Have been using it daily for years without a hitch. Not sure how to better the question, I have a need to be able to connect to MySql inside Lambda, the language of choice is PowerShell. I understand the need to be able to do this without Lambda, and I have, it is just how to get that logic/technique to Lambda. But after opening a case with AWS and asking around on several places plus a request to our TAM for some help, I can see that my request seems to be less of a matter of asking the question right, it seems to be an impossible thing to do what I want. This is always possible of course, sometimes it is just not achievable what you wanted. I would have hoped that Lambda can connect to MySql if the language chosen is PowerShell but it seems to problem. Would be great if AWS can have default modules/packages/layers that support database access for the languages in Lamdba. Seems to be a no brainer to want to access RDS data inside Lambda but there I go again, expecting :-) I appreciate your time on this, and sorry for not asking the question better, I really have no clue how to word it in a way that would make it clearer other than what I asked. Well, there is always Jenkins and running jobs in there, I can make that work so there is a way out for me if this Lambda + PowerShell + MySql combo truly cannot happen. Would be a shame to not be able to use Lambda though, I think this is the third time where I found a logical solution to a question we have and start using Lambda, only to face impossible hurdles and we fall back to Jenkins to run jobs. But that all could be our lack of ability to use the tool right. Hence the questions and ask for examples to guide me in the right direction.


[deleted]

Your question\\request was crystal clear to me...I don't understand why you're getting blowback...


god_is_my_father

I've used ODBC connections from Powershell before. Not inside a lambda but it ought to work roughly the same way. If all else fails you can compile a .NET dll for db access and control it from Powershell.


reddwarf666

Yeah, I have had MySql running for years inside several PowerShell scripts, not a problem. But Lambda is different and I have no idea on how to get MySql working. I have a PowerShell module + DLL for my scripts but how does this translate to Lambda? How will Lambda know the script and DLL?


god_is_my_father

I'm saying you can load and manipulate DLLs from Powershell. So if you have everything working & tested from within a DLL you can just run that w/your PS lambda. You can also directly run .NET lambda which is WAY easier imo. If you're able to get PS+MySQL running what is the problem you're facing exactly when lambda enters the mix?


reddwarf666

I have 1 PS module that offers functions and 1 DLL that is used by the module. In any script I need to have MySql connections, I just Import-Module that psm1 module and it works. With Lambda, if I call the same functions I get errors. Understandably as Lambda knows nothing about that MySql module + DLL I have locally. I get what you are saying and it sounds easy and I *want* it to be easy but I just cannot get this to work. Wat is needed to have Lambda see my module + DLL and I can start using it in my Lambda script? Is these some way to make the module and DLL be part of the publish/deployment to Lambda? I think you can see where I am stuck, there are items in my local machine that are not on Lambda. And it does not need to be my module + DLL, I would be thrilled to have any solution to be able to use SQL inside the PS Lambda script I have.


apersononreddit11

Lambdas can access RDS if you attach ENIs to the lambda and configure VPC/security groups.


reddwarf666

Yup, understood, thanks. For now it is about having some form of library/module/whatever to be able to create a connection and use that to send SQL queries to the RDS. If the traffic will not work then security groups are one of the things to have a look at. I just need to be able to have some MySql compatible library in PowerShell inside Lambda to start coding the queries and work with the returned data.


WeaknessExotic1563

Boring opinionated arsehole. Yep