Skip to content

Commit

Permalink
- update lambda code to new api
Browse files Browse the repository at this point in the history
  • Loading branch information
psmithshine committed Jul 3, 2024
1 parent 147f315 commit 38dc4fa
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions packages/server/src/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import { ApolloServer } from "apollo-server-lambda";
import { ApolloServer } from "@apollo/server";
import { APIGatewayProxyEvent } from "aws-lambda";
import { createConfig } from "./config";
import { Env, createConfig } from "./config";
import { handlers, startServerAndCreateLambdaHandler } from "@as-integrations/aws-lambda";

const server = new ApolloServer(
createConfig(
/**
* Create a basic server, for use with `startServerAndCreateLambdaHandler` function
*/
const server = new ApolloServer({
...createConfig(
// Get environment-specific information from environment variables
process.env,
process.env as Env,
(integrationContext: { event: APIGatewayProxyEvent }, headerName) =>
// Because we're running in an AWS Lambda, extract headers from the
// lambda event
integrationContext.event.headers[headerName]
)
);
),
});

exports.handler = server.createHandler();
export const handler = startServerAndCreateLambdaHandler(
server,
handlers.createAPIGatewayProxyEventV2RequestHandler(),
{
middleware: [
async (event) => {
console.log("###? received event body=" + JSON.stringify(event.body));
// @ts-ignore
event.requestContext["http"] = { method: event.requestContext.httpMethod }; //have to do this otherwise error in request handler
},
]
}
);

0 comments on commit 38dc4fa

Please sign in to comment.