serverless: Unable to deploy to Serverless due to 'empty zip'
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"
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 27 (6 by maintainers)
Yeah, Node version was the problem.
Here’s a quick script that I made if anyone needs it:
I successfully deployed the aws-python3 template using node image (14.15.4-buster). With the image 15.6.0-buster I have the same problem.
Got the same issue and downgrading to 14.15.4 worked for me as well
As of October 2021, the above solution is still valid.
Downgrading the to node version
14.15.4worked for me.Same error on Ubuntu 20.04 using 16.2.0 node version.
Downgrade to 15.3.0 and now everything is working.
Hello & Thanks…, Downgrading the node version to 14.15.4 worked for me too.
@pgrzesik Yeah, I think that my Serverless version was the real issue here. Upgraded to 3.17 and a few issues have actually been fixed, including something with graphQL schema validation. Thank you for the suggestion.
I have also experienced this issue with node v16.15.0, downgrading to v14.15.4 resolved it.