Cannot upload build function to AWS Lambda

My build seems to execute without failure, but due to unknown reasons, the emitted Serverless function cannot be uploaded: https://app.netlify.com/sites/exigo/deploys/5dd34dfd34bd6a498579046b

3:08:00 AM: Function Dir: /opt/build/repo/server/build/functions

3:08:00 AM: TempDir: /tmp/zisi-5dd34dfd34bd6a498579046b

3:08:01 AM: Prepping functions with zip-it-and-ship-it 0.4.0-7

3:08:47 AM: [

3:08:47 AM: {

3:08:47 AM: “path”: “/tmp/zisi-5dd34dfd34bd6a498579046b/graphql.zip”,

3:08:47 AM: “runtime”: “js”

3:08:47 AM: }

3:08:47 AM: ]

3:08:47 AM: Prepping functions complete

3:08:47 AM: Caching artifacts

3:08:47 AM: Started saving node modules

3:08:47 AM: Finished saving node modules

3:08:47 AM: Started saving yarn cache

3:08:47 AM: Finished saving yarn cache

3:08:47 AM: Started saving pip cache

3:08:48 AM: Finished saving pip cache

3:08:48 AM: Started saving emacs cask dependencies

3:08:48 AM: Finished saving emacs cask dependencies

3:08:48 AM: Started saving maven dependencies

3:08:48 AM: Finished saving maven dependencies

3:08:48 AM: Started saving boot dependencies

3:08:48 AM: Finished saving boot dependencies

3:08:48 AM: Started saving go dependencies

3:08:48 AM: Finished saving go dependencies

3:08:52 AM: Build script success

3:08:52 AM: Starting to deploy site from ‘client/public/’

3:08:52 AM: Creating deploy tree

3:08:52 AM: 0 new files to upload

3:08:52 AM: 1 new functions to upload

3:11:22 AM: Failed to upload file: &{Name:graphql Sum:64ff8d173152158cff9bc7e035166ce0268620574933cc53bcd273d47c03cb8e Runtime:js Size: Path: Buffer:0xc0003d42d0}

3:11:22 AM: failed during stage ‘deploying site’: Failed to execute deploy: [PUT /deploys/{deploy_id}/functions/{name}][500] uploadDeployFunction default &{Code:0 Message:}

3:11:22 AM: Failing build: Failed to deploy site

It is a public repo so I cloned it, ran yarn install, yarn build, and then examined the results.

I think part of the issue is that the dependencies are not included in the same directory as function’s js file. Requires are using relative paths that reference a directory not bundled by zip-it-and-ship-it:

const context_1 = require("../graphql/context");
const schema_1 = require("../graphql/schema");

This isn’t a subdirectory of the directory containing the function so it isn’t available to the function. There is more about the supported ways dependencies can be included with your function here:

Quoting:

Ie, the following combinations would all work:

/functions/foo.js
/package.json
/node_modules/
/functions/foo.js
/functions/bar/bar.js
/functions/package.json
/functions/node_modules/
/functions/foo.js
/functions/bar/bar.js
/functions/bar/package.json
/functions/bar/node_modules
/package.json
/node_modules/

This function doesn’t use any of those directory structure formats above.

Would you please try including your dependencies in one of the way described above? If that doesn’t work and/or there are other questions, please reply here anytime to let us know.

Thank you for the quick response! I’ve changed the directory structure as noted, but unfortunately, it hasn’t fixed the deployment: https://app.netlify.com/sites/exigo/deploys/5dd3cab85a0f0f0009d4eda5

Hi @kripod , that function failed to upload because it’s too large. All single functions can only be up to 50MB, and it looks like yours is about 66MB. This is an AWS limit. You’ll have to shrink the function or remove some dependencies in order to deploy the function.

Thank you for the tip!

Somehow, https://app.netlify.com/sites/exigo/deploys/5ddafcc9836c890008d1588b could be uploaded, although I haven’t modified the deployment configuration. Since then, functions still cannot be uploaded, though, but now I can investigate the issue further.

I would like to suggest providing a clearer message about the 50MB file limit in build logs for easier debugging.

1 Like

We will bring this to the attention of our Docs team. Thank you for that suggestion!

Let us know how you make out with your functions upload.

Thank you for the response! Unfortunately, when I set NODE_ENV=production in netlify.toml, the dependencies of my function aren’t bundled with @netlify/zip-it-and-ship-it. The GraphQL server cannot start up, because:

{"errorMessage":"Cannot find module 'apollo-server-lambda'","errorType":"Error","stackTrace":["Module.load (module.js:565:32)","tryModuleLoad (module.js:505:12)","Function.Module._load (module.js:497:3)"]}

I tried installing the project’s dependencies locally using yarn install --production, after purging node_modules. When running npx @netlify/zip-it-and-ship-it@beta server/dist/functions dist-zip, it creates a ~40MB bundle instead of a ~70MB one. The latter gets built when running yarn install regularly, as it resolves to @netlify/zip-it-and-ship-it@0.4.0-7 (beta) instead of @netlify/zip-it-and-ship-it@0.3.1 (latest). The beta seems to work fine, while the latest seems to produce wrong output.

I’m not sure about which one is used by Netlify’s cloud services, but in this case, the beta seems to outperform the latest package.

@kripod I didn’t check your repo but devDependencies aren’t installed when you set the NODE_ENV is set to production. if you need to use production then you should make sure all dependencies you need are regular dependencies and not devDependencies.

After some investigation, it seems that the issue is caused by prisma2 being a peer dependency of @prisma/photon, with the latter being required at runtime. I’ve opened the following issues on GitHub to eliminate problems from two sides:

I’ve just fixed this bug and it seems like things are working for @kripod now.

More information at https://github.com/netlify/zip-it-and-ship-it/issues/73#issuecomment-559485430

2 Likes