RequestEntityTooLargeException: Request must be smaller than 69905067 bytes for the CreateFunction operation

I’m seeing this error in the build logs on my deployments:

2020-09-16T12:32:23Z - internal error - RequestEntityTooLargeException: Request must be smaller than 69905067 bytes for the CreateFunction operation
    at Object.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:51:27)
    at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)
    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request

How do I fix it?

This happens when your production application bundle exceeds the maximum size limit allowed (50 mb).

If you’re using Next.js or bundling your server build with webpack, ensure that you do not have includeNodeModules: true in xdn.config.js (it can be false or simply not present).

If you do need to set includeNodeModules: true, this can likely be fixed by ensuring that dependencies that are only needed at build time (for example, webpack, babel, etc…) are listed under devDependencies in your package.json instead of dependencies.

The xdn deploy command creates the deployment bundle with only those packages listed in dependencies.