Skip to content

Commit

Permalink
fix: make large lambda warning message more informative (#578)
Browse files Browse the repository at this point in the history
* Update max lambda size message

* fix: error message format
  • Loading branch information
biruwon authored Apr 20, 2023
1 parent ca4b0c0 commit d86fd9b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions plugin/src/helpers/verification.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
import process from 'process'

import { yellowBright, redBright } from 'chalk'
import { yellowBright, blueBright } from 'chalk'
import { stripIndent } from 'common-tags'
import { existsSync, promises } from 'fs-extra'
import { async as StreamZip } from 'node-stream-zip'
import { relative } from 'pathe'
import prettyBytes from 'pretty-bytes'

// 50MB, which is the documented max, though the hard max seems to be higher
// 50MB, which is the warning max
// eslint-disable-next-line no-magic-numbers
export const LAMBDA_MAX_SIZE = 1024 * 1024 * 50
export const LAMBDA_WARNING_SIZE = 1024 * 1024 * 50

// 250MB, which is the hard max
// eslint-disable-next-line no-magic-numbers
export const LAMBDA_MAX_SIZE = 1024 * 1024 * 250

// eslint-disable-next-line max-statements
export const checkZipSize = async (
file: string,
warningSize: number = LAMBDA_WARNING_SIZE,
maxSize: number = LAMBDA_MAX_SIZE,
): Promise<void> => {
if (!existsSync(file)) {
console.warn(`Could not check zip size because ${file} does not exist`)
return
}
const fileSize = await promises.stat(file).then(({ size }) => size)
if (fileSize < maxSize) {
if (fileSize < warningSize) {
return
}
// We don't fail the build, because the actual hard max size is larger so it might still succeed
console.log(
redBright(stripIndent`
The function zip ${yellowBright(
yellowBright(stripIndent`
The function zip ${blueBright(
relative(process.cwd(), file),
)} size is ${prettyBytes(
fileSize,
)}, which is larger than the maximum supported size of ${prettyBytes(
)}, which is larger than the recommended maximum size of ${prettyBytes(
warningSize,
)}. This will fail the build if the unzipped size is bigger than the maximum size of ${prettyBytes(
maxSize,
)}.
)}
There are a few reasons this could happen, such as accidentally bundling a large dependency or adding lots of files to "included_files".
`),
)
Expand Down

0 comments on commit d86fd9b

Please sign in to comment.