Retrieve Data from AWS RDS (MSSQL) using AWS Lambda Function - amazon-web-services

I'm searching the internet for a comprehensive step by step tutorial regarding this topic and I can't seem to find one. The docs provided by AWS are a bit vague. Can you guys recommend a site, article or a tutorial? Thank you very much!

To access RDS, you need to place your Lambda function in a subnet inside a VPC since its not recommended to deploy RDS instance in a public subnet which is accessible through internet. You also needs to make sure you Lambda function can access the RDS instance via the network by configuring Security groups assigned to the Lambda function appropriately.
Go through tutorial: Configuring a Lambda Function to Access Amazon RDS in an Amazon VPCfor more details.

Related

Connect RDS from a local aws sam instance

I would like to use aws sam to setup my serverless application. I have used it with dynamoDB before. This was very easy to since all I had to do was setup a dynamoDB table as a resource and then link it to the lambda functions. AWS SAM seams to know where the table is located. I was even able ot run the functions on my local machine using the sam-cli.
With RDS its a lot harder. The RDS Aurora Instance I am using sits behind a specific endpoint, in a specific subnet with security groups in my vpc protected by specific roles.
Now from what I understand, its aws sams job to use my template.yml to generate the roles and organize access rules for me.
But I don't think RDS is supported by aws sam by default, which means I would either be unable to test locally or need a vpn access to the aws vpc, which I am not a massive fan of, since it might be a real security risk.
I know RDS proxies exist, which can be created in aws sam, but they would also need vpc access, and so they just kick the problem down the road.
So how can I connect my aws sam project to RDS and if possible, execute the lambda functions on my machine?

'no vpc' AWS Lambda accessing RDS in VPC

I have a lambda connected to an API gateway; it's deployed using sls and works great. However, it's datastore is an Aurora that is in the default VPC and is set to public. This is less than ideal, security-wise.
I have, in the past, set up Auroras in their own VPC on private subnets and had ec2s in that VPC easily access it. However, all of the material I have read about getting a lambda to use a VPC RDS states that the lambda itself should also reside in the VPC.
This concerns me because of the cold start issue. So, my questions are:
Is there a way for my 'no vpc' lambda to access an Aurora RDS that
lives in its own VPC without putting the lambda into the VPC itself?
There has been talk for some time that aws will be addressing the lambda VPC 'cold start' issue soon. Do we know when that is anticipated to happen? Will existing lambdas benefit from this change once it is instituted?
Is there some other method of securing a public RDS to restrict access to only my lambda (besides the obvious user/pass credentials)?
Thanks in advance
1. Is there a way for my 'no vpc' lambda to access an Aurora RDS that
lives in its own VPC without putting the lambda into the VPC itself?
No, if your RDS instance is not publicly accessible then your Lambda must be deployed in your VPC.
2. There has been talk for some time that AWS will be addressing the lambda VPC 'cold start' issue soon. Do we know when that is anticipated to happen? Will existing lambdas benefit from this change once it is instituted?
I don't think that a specific timeline has been officially communicated for this feature. Existing Lambda functions will obviously benefit from this change (after all, Lambda functions are just code that is continuously redeployed on containers). Information about the new architecture: AWS Lambda in a VPC Will Soon be Much Faster
3. Is there some other method of securing a public RDS to restrict access to only my Lambda (besides the obvious user/pass credentials)?
You can use IAM Database Authentication with Aurora. With this method, authentication is managed externally using IAM.

AWS - What is the simplest way to get a dump of all allowed inbound IP addresses?

Pretty new to the AWS APIs/Lambda so apologies if I'm missing something simple. I just want to get an automated dump of the inbound IP addresses under each of our security groups on a weekly interval. Is this something I can setup under lambda or do I need to do it through the API or CLI? I've looked at the DescribeSecurityGroup functions under https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSecurityGroups.html and https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html, but am wondering if I'm overcomplicating. Thanks in advance.
You would need to write an AWS Lambda function that queries the security groups for CIDR rules, using the AWS SDK for whatever programming language you are writing the Lambda function in. Then you could write the output to a file in the /tmp folder of the AWS Lambda environment, and then copy that file to S3 using the AWS SDK. Then you would schedule the Lambda function to run weekly.
If you already have an EC2 instance running on AWS then the "simplest" way would probably be to add a cron job to that instance that uses the AWS CLI tool to query for the CIDR rules.

Change RDS to Public accessible

I am a newbie in amazon web services and have got some questions related to amazon RDS:
1.How can we use AWS API to define an RDS and send the parameter 'publicly accessible' to it? I know that the CLI has a -pub flag (CLI-RDS) which can be used, but what about when we are not using CLI and gonna use some programming language like Node.js?
2.Is it possible to change the state of publicly-accessible parameter of an RDS? I mean If we have already defined an RDS in private state, can we change it later? If yes How? I also read the discussion here (RDS to public), and they offered to Delete the current RDS & create final snapshot and then Restore the Snapshot with the the public availability zone. It's not possible in my case. Is there any other way? we want to change the state of publicly accessible parameter dynamically because of some security issues.
This API call is available on all clients (Console, SDK, CLI, ...) here is the documentation for node.js, check the PubliclyAccessible parameter:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/RDS.html#modifyDBInstance-property
It is surely possible. However, as the cloudformation documentation mentions, that requires substitution and so expect and plan for some downtime:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-publiclyaccessible

Is it possible to launch an RDS instance without a VPC?

I'm trying to insert records into a Postgres database in RDS from a Lambda function. My Node.js lambda function works correctly when run locally, but the database connection times out when run in AWS.
I've read several articles and tutorials which suggest that AWS Lambda functions cannot access RDS instances that are within a VPC. For example: http://ashiina.github.io/2015/01/amazon-lambda-first-impression/
Unfortunately; it seems I am unable to create an RDS instance that exists outside of a VPC. At this dropdown I would expect to be able to select an option for "No VPC" or something along those lines.
Has this option been removed? Perhaps I have missed a step?
You can create a publicly accessible RDS instance. Then you should be able to access it from anywhere, inside or outside AWS. I believe that would get around your issue with Lambda. You are asked if the instances needs to be publicly accessible when you create a new RDS instance via the web console.
Or you could just wait a few weeks, as Lambda within a VPC is supposed to be enabled "later this year".
Edit: Note that newer Amazon accounts are restricted to VPC only resources. You can't create EC2 or RDS instances outside of a VPC anymore. That's why you don't see the "No VPC" option anymore.
Second Edit: VPC access for Lambda functions is now genearally available.
This question is awhile back, but for those of you who are using MySQL, now you can connect AWS Lambda with Aurora Serverless without VPC, utilizing their new Data API. Take a look at this example for details https://coderecipe.ai/architectures/77374273