5

I am trying to have a mobile app access an amazon rds postgres instance. Referencing https://stackoverflow.com/questions/36103629/is-it-posible-to-query-an-amazon-rds-instance-directly-from-api-gateway#=, Mark said "You should look into pointing API Gateway at a Lambda function that has the ability to connect to your RDS database and run queries." So my question is could I implement this approach using this link: http://docs.aws.amazon.com/lambda/latest/dg/vpc-rds.html and then using api gateway to point at that lambda function? Then any mobile client with credentials from cognito would be able to call that api? Am I correct and is this the best way? My worries is that since a VPC is involved, only a small number of people will be able to use the lambda function.

Community
  • 1
  • 1
Jason Chitla
  • 289
  • 2
  • 8

1 Answers1

3

Yes you could use the technique listed in your link (which is exactly what I was referring to in my other answer that you reference) and then expose that Lambda function via API Gateway. This is (one of ) the correct ways to accompolish this.

My worries is that since a VPC is involved, only a small number of people will be able to use the lambda function.

I don't understand what you are saying here. Why would use of a VPC restrict the number of people that could use the Lambda function?

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • I read something about a limited number of ip addresses due to vpc, and lambda would need to scale up and down but is now limited... I may be misinterpreting this. – Jason Chitla Jun 16 '16 at 03:08
  • 1
    That's not an issue as long as you use a VPC with plenty of unused IP addresses. I've never heard of that being an actual issue in real usage scenarios. – Mark B Jun 16 '16 at 03:17
  • oh okay, thanks for your help, my main concern is if this setup is good for production and scale (for example: will it be able to handle a lot of people invoking the lambda functions to query and post to the rds db or am i missing something?). This mobile app is a social network and is going to mainly be doing some posts and a lot of querying of a postgres db. I'm just trying to set myself up for whats best (i might just be thinking too far ahead :)) – Jason Chitla Jun 16 '16 at 03:27
  • 1
    I think you are going to find that the database will end up being your bottleneck. You will be limited by the number of concurrent connections and transactions the database can handle. – Mark B Jun 16 '16 at 13:28
  • Interesting, so do you think the best approach would be to use heroku (setup something like this: https://devcenter.heroku.com/articles/ios-postgres-full-text-search#the-api-endpoint). Correct me if I'm wrong, heroku would manage all the deployment and configuration? Also, this would be a production db so there can be multiple dbs with the data synchronized across all of them automatically? – Jason Chitla Jun 16 '16 at 13:48
  • or I could just not use heroku and continue managing everything myself in aws but when the time comes do something like this: https://www.citusdata.com/blog/14-marco/178-scaling-out-postgresql-on-amazon-rds-using-masterless-pg-shard – Jason Chitla Jun 16 '16 at 13:58
  • I'm not sure I see how the Heroku solution is more scalable. In general if you want to stick with PostgreSQL then you would need to look into things like sharding and read-replicas to be prepared to handle large amounts of database transactions. Amazon RDS can help you manage some of that. – Mark B Jun 16 '16 at 14:09