access aurora serverless from public lambda - aws-lambda

I want my lambda function to access the database aurora serverless mysql. After some research, I found that we need to keep the lambda under the same VPC as aurora serverless. But keeping lambda in VPC leads to increase the cold start and also in order to access the internet we need to use NAT gateway which leads to additional cost. Since our application is small we cannot afford additional cost. Is there any other way we can access the aurora serverless database without keeping the lambda function in vpc?

maybe for the small application you can reduce the security level and run you serverless Aurora in the default VPC with the default security group. I mean to make the public access to the database with the login/password security gate only. Yes, it is less secure but your billing will be small.
I do not see another way.

Aurora Serverless has a feature called Data API. This allows you to access the database over http from outside the VPC or from anywhere on the Internet.
So, your database can be in a private VPC and your Lambda can be outside the VPC.
However, at the time of writing this, Data API has a high latency. Simple requests can take up to 200 ms to complete.

Related

Is JDBC the only option to connect to aws hosted rds from aws lambda function

Like the title asks, im wondering if the only way of connecting to my aws hosted rds through aws lambda function in java is through a jdbc connection?
Does the aws sdk provide a way of doing this, querying the data and returning results without the need for jdbc?
I've looked through the aws api documentation but nothing is jumping out at me in terms of making a connection through the aws sdk alone, it seems to provide functions on more admin type tasks. .
The reason I ask is in the interest of speed, the jdbc connection takes a few seconds for a connection, but thought if the aws sdk could connect it may be quicker?
Depending on the kind of database you use there are different options.
If you want to reduce the connection latency, you could look into using RDS proxy, which will act as a reverse-proxy in from of the database instances and has a couple of connections ready for you to use.
It's also optimized to let you quickly establish connections through JDBC to it.
If you use Aurora Serverless, you might be able to use the Data API, which uses the AWS SDK to make requests to the database over HTTP. You can find more information on that in the docs: Using the Data API for Aurora Serverless.
You can also always use connection pooling in your lambda functions, which will at least make warm lambdas more performant but doesn't help you with cold starts.

Can AWS Lambda coldout cause API Gateway timeout(30s)?

I am currently managing a website via Django.
The website's url will request an api which is stored in AWS Lambda Function.
Normally, a python based Lambda function with no VPC setting coldout wouldn't worry us.
But I have 2 concerns about my website performance.
The server function communicates with several 3rd party features like AWS S3, Firestore, Firebase Authentication, and DynamoDB. So every Lambda function needs to build up the required settings.
Every page of the website checks the Firebase authentication which persistance is local. Could process delay be critical to a coldstarted container, causing 30s timeout?
If some user occasionaly experience the API Gateway timeout, could the cause of this be AWS Lambda coldstart?
No, the cold start will never be that high. For all cases, cold start should be less than 1 second (even for lambdas bound to VPC).

Aurora Serverless AWS strong read consistency?

Is it possible to get strong read consistency (read-after-write) with Aurora Serverless? I'm using the data api client.
Aurora Serverless will always give you read-after-write consistency. It is pretty much a single (writer) instance Aurora provisioned cluster with serverless support to automatically scale (up or down) the compute.
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless.how-it-works.html

Accessing Amazon Aurora from Lambda?

I am a beginner in AWS development and I had a question regarding accessing amazon aurora from lambda.
I have read that all instances of Amazon Aurora needs to be created inside a VPC. However, it seems that Lambda will incure massive latency for setting up elastic network interface (ENI) everytime it tried to access resources which is inside a VPC
https://medium.freecodecamp.org/lambda-vpc-cold-starts-a-latency-killer-5408323278dd
Since this could increase the cold start time by around 10s , is there a way to avoid this ENI setup latency while using Lambda to access Amazon RDS?
No. There is currently no "good" way to reliably prevent the coldstart.
(1) Yes, keeping the lambda function warm can help reduce the problem, but it will still be present.
(2) The only way would be if you run your rds "outside" a VPC (i.e. make it publicly available) and secure it using security groups. But this is a really bad idea for a lot of reasons (lambda ip addresses change so you need to leave the rds instance wide open for any attacker, violates aws best practices, etc).
AWS lambda + rds is currently not suitable if you need responsiveness. That's why Amazon is pushing the use of dynamodb with lambda so much (since that uses https).
Tldr if you need responsiveness + security stay away from lambda + rds.
What you need to do is make sure your lambda role has the AWSLambdaVPCAccessExecutionRole policy attached to it.
Your ENI is created on cold start. Avoid the cold start by creating another lambda to invoke your current lambda on a schedule to keep it warm.

AWS Lambda vs Elastic Beanstalk

Im new to aws.
I am going to develop a REST full app which is going host on aws.
I decided to use
Amazon S3 for static contents
Amazon Cognito User Pool for Authentication
Amazon DynamoDB as db
I am confused on where my app is going to be hosted. I have 2 ideas for that.
AWS Lambda Function + api gateway
Can I implement entire app on it ?
Elastic Beanstalk
Can i integrate all the above aws services with it ?
(Backend on .net core web api 2.0)
Please guid me
As the experience of working with cloud, after 1y 6m I can give a proper answer for my own question.
Yes.
There is a possibility to use API Gateway + Lambda for the entire app as the back end. But you have to manage your most of the app logic from the front end. On there you have to get a risk because the source code can be viewed by the public.
Keeping your all business logic in the client code is not a good practice. And keeping all the logic in the Lambda also not easy or cost effective. The reason is when you making a real world app, you will need thousands of functions. To do one task, you will have to call many functions (Then its a function run time). So it will be very expensive.
Best solution is hosting the backend on Elastic Beanstalk and front end on S3. If you have any heavy task ? then you can make Lambda functions for that.
Lambda is best for CPU bounded functions. But not to have all the application logic on it.
Since you might not be interested in managing the underlying system, you should opt for AWS Lambda + API Gateway.

Resources