Skip to content

fix: make large lambda warning message more informative #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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