如何将Apollo服务器连接到AWS Lambda服务?

时间:2020-08-28 08:06:34

标签: python amazon-web-services apollo-server apollo-federation

我想将Apollo服务器连接到我具有要查询的模型的“ Python” Lambda服务。我到处搜索,但只能找到使Apollo服务器本身成为AWS Lambda服务的示例。

我创建了一个连接到lambda服务的AWS API网关。
这是我拥有的服务器代码:

const { ApolloGateway, RemoteGraphQLDataSource } = require('@apollo/gateway');
const { ApolloServer, gql } = require('apollo-server');

const gateway = new ApolloGateway({
  serviceList: [
    { name: 'clients', url: 'AWS_API_GATEWAY_URL'}
  ],
  buildService({ name, url }){
    return new RemoteGraphQLDataSource({
      url,
      willSendRequest({ request, context }) {
        request.http.headers.set(
          "user",
          context.user ? JSON.stringify(context.user) : null
        );
      }
    });
  }
});

const server = new ApolloServer({
    gateway,
    subscriptions: false
});
server.listen(3000).then(({ url }) => {
  console.log(`Server ready at ${url}`);
});

但是即使尝试启动服务器也会出现此错误:Error checking for changes to service definitions: Couldn't load service definitions for "reports" at AWS_GATEWAY_URL

有什么想法吗?

0 个答案:

没有答案