
Description
I have a GraphQL API that has two indexes, one runs Express (index.js) and the other runs Serverless (indexServerless.js). For the Serverless I use serverless-offline
to test the API out of Serverless. I tested both Express and Serverless locally and both of them are working. If I try to deploy to Serverless through serverless login
and serverless deploy
I receive the following message from Serverless CLI:
An error occurred: GraphqlLambdaFunction - Uploaded file must be a non-empty zip (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException
And this one from Cloudformation:
UPDATE_COMPLETE
UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS
UPDATE_ROLLBACK_COMPLETE
Which is strange cause I have not changed the API since the last deploy so I contacted Serverless support but they throw GraphQL into the conversation and told me that they could not help me, any idea on how to fix it?
Here's the serverless.yml:
org: X
app: X
service: X
provider:
name: aws
runtime: nodejs12.x
stage: production # development
region: eu-central-1
plugins:
- serverless-offline
functions:
graphql:
handler: indexServerless.graphqlServerless
timeout: 20
events:
- http:
path: graphql
method: post
cors: true
The indexServerless.js:
const { graphqlServerless } = require("./graphql");
require("dotenv").config();
module.exports.graphqlServerless = graphqlServerless;
And the graphql.js, which export both configurations, i.e Express and Serverless:
// Apollo serverless
const graphqlServerless = new ApolloServerless({
typeDefs,
resolvers,
cors: false,
playground: {
endpoint: "/dev/graphql",
},
introspection: false,
debug: false,
mocks: false,
schemaDirectives: {
auth: directives.AuthDirective,
guest: directives.GuestDirective,
},
context: ({ event, context }) => {
return {
headers: event.headers,
functionName: context.functionName,
event,
context,
};
},
});
module.exports = {
graphqlServer, // Express
graphqlServerless: graphqlServerless.createHandler({
cors: {
origin: process.env.GRAPHQL_CORS_SERVERLESS, // true
credentials: true,
},
}), // Serverless
};
I tried to exclude node_modules by setting exclude on serverless.yml and update the Node version, but no changes.
Here's the Serverless CLI version:
Framework Core: 2.19.0
Plugin: 4.4.2
SDK: 2.3.2
Components: 3.4.7
And the Node dependencies:
{
"apollo-server-express": "^2.19.2",
"apollo-server-lambda": "^2.19.2"
}