cdk-real-drift 0.12.9 → 0.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -877,6 +877,15 @@ covers them. **If you never run `revert`, cdkrd needs no write permissions at al
877
877
  re-surfaces as drift — otherwise invisible (the bundle location is write-only).
878
878
  It fetches the presigned S3 URL the API returns; without the permission (or on
879
879
  any fetch failure) the signal is skipped, never false-flagged.
880
+ - Optional: `lambda:GetFunction` records the code digest of an
881
+ `AWS::Lambda::Function` (`CodeSha256`) so an out-of-band code swap
882
+ (`aws lambda update-function-code`, a console "Deploy", a SAM/hotswap sync)
883
+ re-surfaces as drift — otherwise invisible (the function `Code` is write-only and
884
+ a later `cdk deploy` does not heal it). It folds silently on a clean deploy
885
+ (zero first-run noise), `record` snapshots it, and a later change re-surfaces as
886
+ "changed since record". The old code bytes are gone, so it is detect-only (not
887
+ revertable — redeploy with a forced code update). Without the permission the
888
+ signal is skipped, never false-flagged.
880
889
  - Optional: `kms:ListAliases` enables strict verification that a declared
881
890
  `alias/aws/*` key was not swapped for a customer-managed key. Without it that case
882
891
  is conservatively suppressed AND cdkrd prints a one-line warning per region (the
package/dist/cli.js CHANGED
@@ -24,7 +24,7 @@ import { DescribeServicesCommand, ECSClient, ListServicesCommand, UpdateServiceC
24
24
  import { DescribeMountTargetsCommand, EFSClient } from "@aws-sdk/client-efs";
25
25
  import { DescribeListenersCommand, DescribeRulesCommand, ElasticLoadBalancingV2Client, GetTrustStoreCaCertificatesBundleCommand, ModifyLoadBalancerAttributesCommand, ModifyTargetGroupAttributesCommand } from "@aws-sdk/client-elastic-load-balancing-v2";
26
26
  import { DescribeEventBusCommand, EventBridgeClient, ListRulesCommand, PutPermissionCommand } from "@aws-sdk/client-eventbridge";
27
- import { GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
27
+ import { GetFunctionCommand, GetPolicyCommand, LambdaClient, ListAliasesCommand as ListAliasesCommand$1, ListEventSourceMappingsCommand, ListFunctionUrlConfigsCommand, ListVersionsByFunctionCommand } from "@aws-sdk/client-lambda";
28
28
  import { ChangeResourceRecordSetsCommand, ListResourceRecordSetsCommand, Route53Client } from "@aws-sdk/client-route-53";
29
29
  import { GetTopicAttributesCommand, ListSubscriptionsByTopicCommand, SNSClient, SetTopicAttributesCommand } from "@aws-sdk/client-sns";
30
30
  import { ACMClient, DescribeCertificateCommand, ListTagsForCertificateCommand } from "@aws-sdk/client-acm";
@@ -2893,6 +2893,7 @@ const GENERATED_TOPLEVEL_PATHS = {
2893
2893
  "ScalableDimension"
2894
2894
  ]),
2895
2895
  "AWS::Lambda::Version": new Set(["CodeSha256"]),
2896
+ "AWS::Lambda::Function": new Set(["CodeSha256"]),
2896
2897
  "AWS::EFS::AccessPoint": new Set(["ClientToken"])
2897
2898
  };
2898
2899
  const DESCEND_UNDECLARED_OBJECT_PATHS = {
@@ -10357,6 +10358,15 @@ const supplementTrustStore = async ({ physicalId, region }) => {
10357
10358
  const hash = hashCaBundle(await resp.text());
10358
10359
  return hash !== void 0 ? { CaCertificatesBundleSha256: hash } : void 0;
10359
10360
  };
10361
+ const supplementLambdaFunction = async ({ physicalId, region }) => {
10362
+ const name = str$1(physicalId);
10363
+ if (!name) return void 0;
10364
+ const sha = str$1((await new LambdaClient({
10365
+ region,
10366
+ ...READ_RETRY
10367
+ }).send(new GetFunctionCommand({ FunctionName: name }))).Configuration?.CodeSha256);
10368
+ return sha !== void 0 ? { CodeSha256: sha } : void 0;
10369
+ };
10360
10370
  function projectLexPrompt(p) {
10361
10371
  const ps = p;
10362
10372
  if (!ps || typeof ps !== "object") return void 0;
@@ -10583,6 +10593,7 @@ const SDK_SUPPLEMENTS = {
10583
10593
  "AWS::Lex::Bot": supplementLexBot,
10584
10594
  "AWS::MSK::Configuration": supplementMskConfiguration,
10585
10595
  "AWS::ElasticLoadBalancingV2::TrustStore": supplementTrustStore,
10596
+ "AWS::Lambda::Function": supplementLambdaFunction,
10586
10597
  "AWS::SSM::Parameter": supplementSsmParameter,
10587
10598
  "AWS::ElastiCache::ReplicationGroup": supplementElastiCacheReplicationGroup,
10588
10599
  "AWS::ECS::Service": supplementEcsService,
@@ -12178,13 +12189,19 @@ function checkBaselineAccount(baseline, currentAccountId, stackName, warn = cons
12178
12189
  }
12179
12190
  if (currentAccountId && baseline.accountId !== currentAccountId) throw new Error(`baseline file for ${stackName} was captured in account ${baseline.accountId}, but the current account is ${currentAccountId} (the file was likely copied or renamed to the wrong account path). Baselines are per-account — run \`cdkrd record\` to write this account's own baseline file, or restore the correct file from git.`);
12180
12191
  }
12192
+ const RECORDABLE_GENERATED_PATHS = { "AWS::Lambda::Function": new Set(["CodeSha256"]) };
12193
+ function isRecordableGenerated(f) {
12194
+ return f.tier === "generated" && (RECORDABLE_GENERATED_PATHS[f.resourceType]?.has(f.path) ?? false);
12195
+ }
12181
12196
  /** Build the recorded set from a check run's findings: undeclared PROPERTIES plus
12182
12197
  * out-of-band `added` RESOURCES (PR4 — `added` is the resource-granularity sibling of
12183
12198
  * undeclared, so `record` snapshots its full live model and a later change to it
12184
12199
  * surfaces as drift). An `added` entry has the synthesized child logicalId and an
12185
- * empty `path` (the whole resource is the value); `recordedKey` keeps it unique. */
12200
+ * empty `path` (the whole resource is the value); `recordedKey` keeps it unique.
12201
+ * Plus RECORDABLE_GENERATED_PATHS: a `generated` content-hash signal (Lambda
12202
+ * CodeSha256, #646) that folds first-run yet must be recorded so a later swap is seen. */
12186
12203
  function buildRecorded(findings) {
12187
- return findings.filter((f) => f.tier === "undeclared" || f.tier === "added").filter((f) => !f.modelReadFailed).map((f) => ({
12204
+ return findings.filter((f) => f.tier === "undeclared" || f.tier === "added" || isRecordableGenerated(f)).filter((f) => !f.modelReadFailed).map((f) => ({
12188
12205
  logicalId: f.logicalId,
12189
12206
  resourceType: f.resourceType,
12190
12207
  path: f.path,
@@ -14643,7 +14660,10 @@ function resolveSdkWriter(resourceType, ops) {
14643
14660
  //#endregion
14644
14661
  //#region src/revert/plan.ts
14645
14662
  const WRITEONLY_NESTED_NO_CC_REVERT = {};
14646
- const SYNTHETIC_READ_SIGNAL_PATHS = { "AWS::ElasticLoadBalancingV2::TrustStore": ["CaCertificatesBundleSha256"] };
14663
+ const SYNTHETIC_READ_SIGNAL_PATHS = {
14664
+ "AWS::ElasticLoadBalancingV2::TrustStore": ["CaCertificatesBundleSha256"],
14665
+ "AWS::Lambda::Function": ["CodeSha256"]
14666
+ };
14647
14667
  const CC_REVERTABLE_DESPITE_READ_OVERRIDE = new Set(["AWS::Scheduler::Schedule", "AWS::Cognito::IdentityPool"]);
14648
14668
  const REVERT_SET_DEFAULT_PATHS = new Set([
14649
14669
  "AWS::IAM::Role\0MaxSessionDuration",