Repository navigation
fix(lambda): report the size and digest of the deployed package (#545) - #557
Merged
Merged
Conversation
CodeSize was 0 and CodeSha256 empty for every function whose code did not arrive as an inline base64 ZipFile on a direct CreateFunction, so a consumer polling CodeSize to decide whether a deploy took effect was told nothing had. The issue's premise was confounded. Measuring all four combinations showed the axis is inline vs. S3 source, not CFN vs. direct: direct+ZipFile=156, direct+S3=0, CFN+S3=0, and CFN+inline ZipFile=0 — the row the report never tested, proving two independent gaps. CloudFormation sent no Code key at all, so a CFN function reported size 0 however its template declared its code and an image function lost both its image and its PackageType. All of ZipFile, S3Bucket, S3Key, S3ObjectVersion and ImageUri are now forwarded, Ref-resolved like any other property. An inline template needed more than forwarding: the resource type's ZipFile is source text CloudFormation "places in a file named index and zips", while the API's is "the base64-encoded contents of the deployment package". Substrate now builds that archive, one entry named for the runtime (.js, .py, or bare index), with no timestamps so the same template yields the same digest twice. An S3-sourced package is sized from substrate's own S3 state, honouring S3ObjectVersion; ZipStored stays false. UpdateFunctionCode no longer randomises CodeSha256, and an image function's digest tracks its URI from creation. Two decisions are substrate's own and docs/services.md states both: an S3-sourced package's digest is the object's ETag, and an absent object deploys with size 0 rather than failing. Two adjacent gaps are fixed with it: Code.ImageUri was accepted only at the top level, and GetFunction claimed RepositoryType S3 with a stub presigned URL for an image-packaged function, which now reports ECR.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #545
CodeSizewas0andCodeSha256empty for every function whose code did not arrive as an inline base64ZipFileon a directCreateFunction. A consumer pollingCodeSizeto decide whether a deploy took effect was told nothing had, whatever it deployed — this release's shape: a request accepted, answered200, producing no effect a caller can observe.The issue's premise was confounded, and correcting it doubled the change
It was filed as a CloudFormation problem. Measuring all four combinations against v0.89.0 showed the axis is inline vs. S3 source, not CFN vs. direct:
ZipFileCreateFunctionCFN + inline is the row the report never tested, and the one that proves there were two independent gaps rather than one.
CloudFormation sent no
Codeat alldeployLambdaFunctionbuilt aCreateFunctionbody carryingFunctionName,Runtime,Role,Handler,Description,TimeoutandMemorySizeand noCodekey of any kind. So every CFN-deployed function reported size 0 and an empty digest however its template declared its code, a container-image function lost both its image and itsPackageType, andUpdateFunctionCodedrift was undetectable. All ofZipFile,S3Bucket,S3Key,S3ObjectVersionandImageUriare now forwarded, each through the template'sRefand pseudo-parameter resolution like any other property.An inline template needed more than forwarding
The resource type's
Code.ZipFileis "the source code of your Lambda function" — "CloudFormation places it in a file namedindexand zips it to create a deployment package" — while the API'sCode.ZipFileis "the base64-encoded contents of the deployment package". Forwarding the template's string would have handed Lambda something that is not a package and usually not valid base64, leavingCodeSizeat 0 exactly as before. Substrate now builds the archive CloudFormation would have built: one entry namedindexwith the extension the runtime reads (.jsfornodejs*per the reference,.pyforpython*, bareindexotherwise), carrying no timestamps so the same template deployed twice yields the same package and the same digest. A digest that moved on every deploy would not be worth comparing.An S3-sourced package is sized, and the digest stopped being random
Both
createFunctionandupdateFunctionCoderead the object's recorded length out of substrate's own S3 state, honouringS3ObjectVersion.ZipStoredstaysfalse— the bytes are still not staged for execution, which is a separate and correct fact from knowing the size.UpdateFunctionCodeassignedCodeSha256a fresh random value on every call, so a caller asking "did the code change?" was always told yes. The digest is now derived from the package, an update carrying no package changes neither size nor digest, and an image function's digest tracks its URI from creation rather than only after the first update.RevisionIdis not a digest of anything and still advances on every call.Substrate's own decisions
Two, both stated in
docs/services.md:Two adjacent gaps, fixed with it
Leaving either would have kept a write with no observable.
Code.ImageUri, the documented spelling, was accepted only at the top level; it now wins over the legacy field and infersPackageType: Image. AndGetFunctionreportedRepositoryType: S3with a stub presigned URL for an image-packaged function — a claim a caller can act on and be wrong about — and now reportsRepositoryType: ECRwithImageUri/ResolvedImageUriand noLocation.Tests
16 tests in
emulator/lambda_code_size_test.go, asserting on the JSONGetFunctionreturns rather than on the state record, sinceCodeSizeis only interesting as an observation a caller makes. With the two source files stashed, 12 fail; the 3 that pass are the deliberate no-regression guards (absent object, CFN absent object, CFN with noCode).Mutation testing: 21 mutants, 21 CAUGHT, 0 survivors, including the plan's named mutant (
Codeforwarded forZipFilebut not forS3Bucket), the deployer not calling theCodehelper at all (the exact pre-fix state), inline code forwarded unzipped, the entry name ignoring the runtime, a nondeterministic archive, the S3 sizing removed from create and from update,S3ObjectVersionignored, an absent object reporting a size, the ETag not de-quoted, a delete marker read as an object, and four on the image path.Three mutants were informative rather than merely caught:
Deflate → Storesurvived and is a genuine equivalent — the compression method is unconstrained; only the bytes' determinism is.hdr.Modified = time.Now()survived because ZIP stores mtime at two-second granularity, so both deploys in a test land in the same slot. Rewritten to put the nondeterminism in the payload → CAUGHT.ImageUriupdate leftCodeSha256untouched. Fixed in the plugin; the mutant and two new ones now fail.The image create path reporting no digest was found by the live e2e below, not by the tests, and is covered by a new mutant (M21).
Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race) green,make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./...all pass.Live, against
substrate server:Compatibility
A test asserting that
CodeSizeis0, thatCodeSha256is empty, or thatCodeSha256changes on everyUpdateFunctionCodewill go red. That is the fix. A test assertingRepositoryType: S3for an image-packaged function will also go red.