首页 > 解决方案 > Do I have to use AppSync for apollo graphql in lambda?

问题描述

I'd like to use apollo graphql in a lambda and I found AppSync is for graphql and API Gateway is for REST. Do I have to use AppSync for that? I also find out a library apollo-server-lambda which can be used with serverless but I don't want to use serverless because all my infrastructure code is written in Terraform. I don't want to bring another IaC library in my application. So is there a way to use API Gateway with apollo graphql in lambda? If yes, how should I declare API Gateway route for that?

标签: amazon-web-servicesgraphqlapollo-server

解决方案


Not really. You can just use the API gateway, Lambda, and Apollo Server. Install the npm library apollo-server-lambda and Import the required modules.

The current version of Apollo Server Lambda: 2.17.0

You can create a GraphQL handler using the function createHandler provided by Apollo server Lambda.

I am not sure about how it is done using Terraform but you can just declare a route to your handler function via the API gateway.

Make sure your GET and POST requests route to the same handler.

Refer to this documentation for more details: https://www.apollographql.com/docs/apollo-server/deployment/lambda/


推荐阅读