serverless / serverless-graphql

Serverless GraphQL Examples for AWS AppSync and Apollo
https://www.serverless.com
MIT License
2.72k stars 364 forks source link

Use AppSync with Amazon RDS #349

Closed widdydev closed 6 years ago

widdydev commented 6 years ago

I'm struggling with the combination of AppSync and Amazon RDS. I tried the implementation of the standalone rds, and the appsync examples provided in the repository. These are working like a charm. But obviously there are many differences and difficulties if you'd like to combine these technologies. I used the schema, resolver and handler functions from the rds directory and combined it with the appsync lambda implementation. I adjusted the mapping templates and updated the serverless.yml file. I could successfully deploy the whole appsync service and all resources without any errors. I'm able to access the graphql endpoint from graphiql and do my queries. But when I try it from the appsync console I get null as a response. I guess it has something to do with the mapping templates, but I'm not quite sure. Has anybody got any suggestions or maybe a working example of this specific combination?

romainquellec commented 6 years ago

Hello @getsbydev, any improvement ? Can you share your code ?

widdydev commented 6 years ago

Hey @romainquellec yeah I already figured it out how to successfully connect the Amazon AppSync service with a RDS via a lambda-function. In the next days, I'm going to create a small repository to share my implementation.

romainquellec commented 6 years ago

Thanks ! ping me then ;)

sid88in commented 6 years ago

@getsbydev @romainquellec key is to make sure lambda has access to RDS (VPC settings are correct). Then you can use the lambda + graphql code in appsync (with correct templating) and it should work!

romainquellec commented 6 years ago

@getsbydev Any code to share with the community ? Thanks !

widdydev commented 6 years ago

@romainquellec I created a repository with my implementation. Feel free to leave some feedback!

mattbt commented 6 years ago

Hey @getsbydev thanks for sharing. Is your lambda within a VPC? I tried and implement something similar, but I'm experiencing cold starts up to 10s (!)

widdydev commented 6 years ago

@mattbt my lambda is currently not within a VPC and the executing times vary from 2ms to 200ms.

stephme commented 6 years ago

@getsbydev thx a lot for your code ! Great help !

For those who are using the pgmodule : knex is using it at runtime and so you will have to require it manually in your code to force the inclusion in the bundle. Otherwise it won't be included and knex will crash.

Or you can add this in your serverless.yml file :

custom:
  webpack:
    includeModules:
      forceInclude:
        - pg
mattbt commented 6 years ago

@getsbydev thanks, and is your RDS instance in a VPC? if so, how do you restrict access to RDS only to that Lambda? I have not found an answer yet, beside putting Lambda in the VPC itself (and therefore experiencing cold starts).