fix(hosting): disable installLatestAwsSdk on CDN invalidation custom resource - #372
Open
soberm wants to merge 1 commit into
Open
fix(hosting): disable installLatestAwsSdk on CDN invalidation custom resource#372soberm wants to merge 1 commit into
soberm wants to merge 1 commit into
Conversation
…resource The DeployInvalidation AwsCustomResource in CdnConstruct left installLatestAwsSdk at the CDK default of true, so the custom-resource provider Lambda npm-installed the AWS SDK at invoke time (~15-30s cold start, 512MB memory floor). The resource only calls CloudFront.createInvalidation, a stable API already bundled in the Lambda runtime's AWS SDK v3, and it fires on every hosting deploy, so that cost was paid per deploy rather than once. Setting it to false removes the penalty and silences CDK's installLatestAwsSdkNotSpecified warning for this construct. Invalidation behavior, IAM policy, and deploy ordering are unchanged. Adds a test asserting the synthesized Custom::AWS carries InstallLatestAwsSdk: false, scoped to the createInvalidation resource.
🦋 Changeset detectedLatest commit: a9f7b54 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
cadivus
approved these changes
Aug 14, 2026
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.
Problem
The
DeployInvalidationAwsCustomResourceinCdnConstruct(
packages/hosting/src/constructs/cdn_construct.ts) leftinstallLatestAwsSdkat its CDK default of
true. With that default, the custom-resource providerLambda runs
npm installfor the AWS SDK at invoke time, which adds roughly15-30s of cold start and forces a 512MB memory floor on the provider function.
Two things make this worse than a typical occurrence of the anti-pattern:
CloudFront.createInvalidationcall — along-stable API already bundled in the Lambda runtime's AWS SDK v3, so there
is nothing to gain from a newer SDK.
CallerReferenceandphysicalResourceIdare keyed onbuildId), so theinstall cost was paid on each deploy rather than once.
CDK also emits its
installLatestAwsSdkNotSpecifiedwarning for this constructon every synth.
Sibling fix to #371 — same anti-pattern, different package. That PR covers the
bb-knowledge-basesite; this one covershosting. No overlap: this branch iscut independently from
origin/mainand touches onlypackages/hosting.Issue #, if available: n/a
Changes
packages/hosting/src/constructs/cdn_construct.ts: addinstallLatestAwsSdk: falseto theDeployInvalidationAwsCustomResourceoptions, with a short comment recording the rationale.
packages/hosting/src/constructs/cdn_construct.test.ts: add a test assertingthe synthesized
Custom::AWScarriesInstallLatestAwsSdk: false.@aws-blocks/hostingpatch.@aws-blocks/blocksis intentionallynot included — it has no dependency on
@aws-blocks/hostingand does notre-export the construct.
Invalidation behavior, the IAM policy (
cloudfront:CreateInvalidationon*),and the deploy ordering dependency on the KVS cutover are all unchanged. The
only synthesized-template delta is the
InstallLatestAwsSdkproperty flippingfrom
truetofalse. No public API surface change, soAPI.mdis untouched.Validation
Clean build (node 22.22.3),
rm -rf dist *.tsbuildinfo && npm run buildinpackages/hosting: exit 0. No dependency blockers;package.jsonandpackage-lock.jsonare unmodified (git statusclean apart from the threeintended files).
Tests: 839 pass / 0 fail (212 suites), including the new
pins the invalidation resource to the bundled SDK (no install at invoke).Synth proof —
DeployInvalidationfragment from a synthesized SSR stack:The CDK warning is also gone: synth reports 0 stack messages with the fix. That
check is not vacuous — reverting only the construct change reproduces exactly
one warning,
installLatestAwsSdkNotSpecifiedat/TestStack/Cdn/DeployInvalidation, and the fragment shows"InstallLatestAwsSdk": true.Non-vacuity of the test: with the construct change stashed, the suite is
838 pass / 1 fail, the single failure being the new assertion. With the change
applied it passes.
Checklist
API.mdupdate; rationale captured in a code comment and the changesetBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.