@intentius/chant-lexicon-aws 0.0.8 → 0.0.9

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.
Files changed (115) hide show
  1. package/dist/integrity.json +25 -10
  2. package/dist/manifest.json +1 -1
  3. package/dist/meta.json +5743 -896
  4. package/dist/rules/cf-refs.ts +99 -0
  5. package/dist/rules/ext001.ts +30 -21
  6. package/dist/rules/hardcoded-region.ts +1 -0
  7. package/dist/rules/iam-wildcard.ts +1 -0
  8. package/dist/rules/s3-encryption.ts +1 -0
  9. package/dist/rules/waw016.ts +86 -0
  10. package/dist/rules/waw017.ts +53 -0
  11. package/dist/rules/waw018.ts +71 -0
  12. package/dist/rules/waw019.ts +82 -0
  13. package/dist/rules/waw020.ts +64 -0
  14. package/dist/rules/waw021.ts +53 -0
  15. package/dist/rules/waw022.ts +43 -0
  16. package/dist/rules/waw023.ts +47 -0
  17. package/dist/rules/waw024.ts +54 -0
  18. package/dist/rules/waw025.ts +43 -0
  19. package/dist/rules/waw026.ts +46 -0
  20. package/dist/rules/waw027.ts +50 -0
  21. package/dist/rules/waw028.ts +47 -0
  22. package/dist/rules/waw029.ts +62 -0
  23. package/dist/rules/waw030.ts +246 -0
  24. package/dist/skills/chant-aws.md +388 -30
  25. package/dist/types/index.d.ts +1552 -1528
  26. package/package.json +2 -2
  27. package/src/actions/actions.test.ts +75 -0
  28. package/src/actions/dynamodb.ts +36 -0
  29. package/src/actions/ecr.ts +9 -0
  30. package/src/actions/ecs.ts +5 -0
  31. package/src/actions/iam.ts +3 -0
  32. package/src/actions/index.ts +9 -0
  33. package/src/actions/lambda.ts +11 -0
  34. package/src/actions/logs.ts +4 -0
  35. package/src/actions/s3.ts +34 -0
  36. package/src/actions/sns.ts +5 -0
  37. package/src/actions/sqs.ts +15 -0
  38. package/src/codegen/__snapshots__/snapshot.test.ts.snap +2 -2
  39. package/src/codegen/docs-links.test.ts +143 -0
  40. package/src/codegen/docs.ts +247 -132
  41. package/src/codegen/generate-lexicon.ts +8 -0
  42. package/src/codegen/generate-typescript.ts +25 -1
  43. package/src/composites/composites.test.ts +442 -0
  44. package/src/composites/fargate-alb.ts +253 -0
  45. package/src/composites/index.ts +20 -0
  46. package/src/composites/lambda-api.ts +20 -0
  47. package/src/composites/lambda-dynamodb.ts +64 -0
  48. package/src/composites/lambda-eventbridge.ts +36 -0
  49. package/src/composites/lambda-function.ts +76 -0
  50. package/src/composites/lambda-s3.ts +72 -0
  51. package/src/composites/lambda-sns.ts +30 -0
  52. package/src/composites/lambda-sqs.ts +44 -0
  53. package/src/composites/scheduled-lambda.ts +37 -0
  54. package/src/composites/vpc-default.ts +148 -0
  55. package/src/default-tags.test.ts +38 -0
  56. package/src/default-tags.ts +77 -0
  57. package/src/generated/index.d.ts +1552 -1528
  58. package/src/generated/lexicon-aws.json +5743 -896
  59. package/src/import/roundtrip-fixtures.test.ts +1 -1
  60. package/src/index.ts +21 -0
  61. package/src/integration.test.ts +71 -0
  62. package/src/intrinsics.ts +24 -13
  63. package/src/lint/post-synth/cf-refs.ts +99 -0
  64. package/src/lint/post-synth/ext001.test.ts +214 -31
  65. package/src/lint/post-synth/ext001.ts +30 -21
  66. package/src/lint/post-synth/waw013.test.ts +120 -0
  67. package/src/lint/post-synth/waw014.test.ts +121 -0
  68. package/src/lint/post-synth/waw015.test.ts +147 -0
  69. package/src/lint/post-synth/waw016.test.ts +141 -0
  70. package/src/lint/post-synth/waw016.ts +86 -0
  71. package/src/lint/post-synth/waw017.test.ts +130 -0
  72. package/src/lint/post-synth/waw017.ts +53 -0
  73. package/src/lint/post-synth/waw018.test.ts +109 -0
  74. package/src/lint/post-synth/waw018.ts +71 -0
  75. package/src/lint/post-synth/waw019.test.ts +138 -0
  76. package/src/lint/post-synth/waw019.ts +82 -0
  77. package/src/lint/post-synth/waw020.test.ts +125 -0
  78. package/src/lint/post-synth/waw020.ts +64 -0
  79. package/src/lint/post-synth/waw021.test.ts +81 -0
  80. package/src/lint/post-synth/waw021.ts +53 -0
  81. package/src/lint/post-synth/waw022.test.ts +54 -0
  82. package/src/lint/post-synth/waw022.ts +43 -0
  83. package/src/lint/post-synth/waw023.test.ts +53 -0
  84. package/src/lint/post-synth/waw023.ts +47 -0
  85. package/src/lint/post-synth/waw024.test.ts +64 -0
  86. package/src/lint/post-synth/waw024.ts +54 -0
  87. package/src/lint/post-synth/waw025.test.ts +42 -0
  88. package/src/lint/post-synth/waw025.ts +43 -0
  89. package/src/lint/post-synth/waw026.test.ts +54 -0
  90. package/src/lint/post-synth/waw026.ts +46 -0
  91. package/src/lint/post-synth/waw027.test.ts +63 -0
  92. package/src/lint/post-synth/waw027.ts +50 -0
  93. package/src/lint/post-synth/waw028.test.ts +68 -0
  94. package/src/lint/post-synth/waw028.ts +47 -0
  95. package/src/lint/post-synth/waw029.test.ts +179 -0
  96. package/src/lint/post-synth/waw029.ts +62 -0
  97. package/src/lint/post-synth/waw030.test.ts +800 -0
  98. package/src/lint/post-synth/waw030.ts +246 -0
  99. package/src/lint/rules/hardcoded-region.ts +1 -0
  100. package/src/lint/rules/iam-wildcard.ts +1 -0
  101. package/src/lint/rules/s3-encryption.ts +1 -0
  102. package/src/lsp/hover.ts +15 -0
  103. package/src/nested-stack-integration.test.ts +100 -0
  104. package/src/nested-stack.ts +1 -1
  105. package/src/plugin.ts +468 -36
  106. package/src/serializer.test.ts +330 -2
  107. package/src/serializer.ts +62 -1
  108. package/src/spec/fetch.ts +10 -0
  109. package/src/spec/parse.test.ts +141 -0
  110. package/src/spec/parse.ts +40 -0
  111. package/src/taggable.ts +44 -0
  112. package/src/testdata/nested-stacks/app.ts +26 -0
  113. package/src/testdata/nested-stacks/network/outputs.ts +17 -0
  114. package/src/testdata/nested-stacks/network/security.ts +17 -0
  115. package/src/testdata/nested-stacks/network/vpc.ts +54 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * WAW023: CloudFront Without WAF
3
+ *
4
+ * Flags CloudFront distributions without WebACLId.
5
+ */
6
+
7
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
8
+ import { parseCFTemplate } from "./cf-refs";
9
+
10
+ export function checkCloudFrontWaf(ctx: PostSynthContext): PostSynthDiagnostic[] {
11
+ const diagnostics: PostSynthDiagnostic[] = [];
12
+
13
+ for (const [_lexicon, output] of ctx.outputs) {
14
+ const template = parseCFTemplate(output);
15
+ if (!template?.Resources) continue;
16
+
17
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
18
+ if (resource.Type !== "AWS::CloudFront::Distribution") continue;
19
+
20
+ const props = resource.Properties ?? {};
21
+ const distConfig = props.DistributionConfig;
22
+ if (typeof distConfig !== "object" || distConfig === null) continue;
23
+
24
+ const config = distConfig as Record<string, unknown>;
25
+ if (!("WebACLId" in config)) {
26
+ diagnostics.push({
27
+ checkId: "WAW023",
28
+ severity: "warning",
29
+ message: `CloudFront distribution "${logicalId}" has no WebACLId — consider attaching a WAF web ACL for protection`,
30
+ entity: logicalId,
31
+ lexicon: "aws",
32
+ });
33
+ }
34
+ }
35
+ }
36
+
37
+ return diagnostics;
38
+ }
39
+
40
+ export const waw023: PostSynthCheck = {
41
+ id: "WAW023",
42
+ description: "CloudFront distribution has no WAF web ACL — consider attaching one for protection",
43
+
44
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
45
+ return checkCloudFrontWaf(ctx);
46
+ },
47
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * WAW024: ALB Without Access Logging
3
+ *
4
+ * Flags Application Load Balancers without access logging enabled.
5
+ */
6
+
7
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
8
+ import { parseCFTemplate } from "./cf-refs";
9
+
10
+ export function checkAlbAccessLogs(ctx: PostSynthContext): PostSynthDiagnostic[] {
11
+ const diagnostics: PostSynthDiagnostic[] = [];
12
+
13
+ for (const [_lexicon, output] of ctx.outputs) {
14
+ const template = parseCFTemplate(output);
15
+ if (!template?.Resources) continue;
16
+
17
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
18
+ if (resource.Type !== "AWS::ElasticLoadBalancingV2::LoadBalancer") continue;
19
+
20
+ const props = resource.Properties ?? {};
21
+ const attrs = props.LoadBalancerAttributes;
22
+
23
+ let hasAccessLogs = false;
24
+ if (Array.isArray(attrs)) {
25
+ hasAccessLogs = attrs.some((attr) => {
26
+ if (typeof attr !== "object" || attr === null) return false;
27
+ const a = attr as Record<string, unknown>;
28
+ return a.Key === "access_logs.s3.enabled" && (a.Value === "true" || a.Value === true);
29
+ });
30
+ }
31
+
32
+ if (!hasAccessLogs) {
33
+ diagnostics.push({
34
+ checkId: "WAW024",
35
+ severity: "warning",
36
+ message: `Load balancer "${logicalId}" does not have access logging enabled — enable access_logs.s3.enabled for audit trails`,
37
+ entity: logicalId,
38
+ lexicon: "aws",
39
+ });
40
+ }
41
+ }
42
+ }
43
+
44
+ return diagnostics;
45
+ }
46
+
47
+ export const waw024: PostSynthCheck = {
48
+ id: "WAW024",
49
+ description: "Application Load Balancer does not have access logging enabled",
50
+
51
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
52
+ return checkAlbAccessLogs(ctx);
53
+ },
54
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WAW025: SNS Topic Not Encrypted
3
+ *
4
+ * Flags SNS topics without KmsMasterKeyId.
5
+ */
6
+
7
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
8
+ import { parseCFTemplate } from "./cf-refs";
9
+
10
+ export function checkSnsEncryption(ctx: PostSynthContext): PostSynthDiagnostic[] {
11
+ const diagnostics: PostSynthDiagnostic[] = [];
12
+
13
+ for (const [_lexicon, output] of ctx.outputs) {
14
+ const template = parseCFTemplate(output);
15
+ if (!template?.Resources) continue;
16
+
17
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
18
+ if (resource.Type !== "AWS::SNS::Topic") continue;
19
+
20
+ const props = resource.Properties ?? {};
21
+ if (!("KmsMasterKeyId" in props)) {
22
+ diagnostics.push({
23
+ checkId: "WAW025",
24
+ severity: "warning",
25
+ message: `SNS topic "${logicalId}" is not encrypted — add KmsMasterKeyId for encryption at rest`,
26
+ entity: logicalId,
27
+ lexicon: "aws",
28
+ });
29
+ }
30
+ }
31
+ }
32
+
33
+ return diagnostics;
34
+ }
35
+
36
+ export const waw025: PostSynthCheck = {
37
+ id: "WAW025",
38
+ description: "SNS topic is not encrypted — add KmsMasterKeyId for encryption at rest",
39
+
40
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
41
+ return checkSnsEncryption(ctx);
42
+ },
43
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * WAW026: SQS Queue Not Encrypted
3
+ *
4
+ * Flags SQS queues without SqsManagedSseEnabled or KmsMasterKeyId.
5
+ */
6
+
7
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
8
+ import { parseCFTemplate } from "./cf-refs";
9
+
10
+ export function checkSqsEncryption(ctx: PostSynthContext): PostSynthDiagnostic[] {
11
+ const diagnostics: PostSynthDiagnostic[] = [];
12
+
13
+ for (const [_lexicon, output] of ctx.outputs) {
14
+ const template = parseCFTemplate(output);
15
+ if (!template?.Resources) continue;
16
+
17
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
18
+ if (resource.Type !== "AWS::SQS::Queue") continue;
19
+
20
+ const props = resource.Properties ?? {};
21
+ const hasSseSqs = props.SqsManagedSseEnabled === true;
22
+ const hasKms = "KmsMasterKeyId" in props;
23
+
24
+ if (!hasSseSqs && !hasKms) {
25
+ diagnostics.push({
26
+ checkId: "WAW026",
27
+ severity: "warning",
28
+ message: `SQS queue "${logicalId}" is not encrypted — enable SqsManagedSseEnabled or set KmsMasterKeyId`,
29
+ entity: logicalId,
30
+ lexicon: "aws",
31
+ });
32
+ }
33
+ }
34
+ }
35
+
36
+ return diagnostics;
37
+ }
38
+
39
+ export const waw026: PostSynthCheck = {
40
+ id: "WAW026",
41
+ description: "SQS queue is not encrypted — enable SqsManagedSseEnabled or set KmsMasterKeyId",
42
+
43
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
44
+ return checkSqsEncryption(ctx);
45
+ },
46
+ };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * WAW027: DynamoDB Missing Point-in-Time Recovery
3
+ *
4
+ * Flags DynamoDB tables without PointInTimeRecoverySpecification.PointInTimeRecoveryEnabled.
5
+ */
6
+
7
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
8
+ import { parseCFTemplate } from "./cf-refs";
9
+
10
+ export function checkDynamoDbPitr(ctx: PostSynthContext): PostSynthDiagnostic[] {
11
+ const diagnostics: PostSynthDiagnostic[] = [];
12
+
13
+ for (const [_lexicon, output] of ctx.outputs) {
14
+ const template = parseCFTemplate(output);
15
+ if (!template?.Resources) continue;
16
+
17
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
18
+ if (resource.Type !== "AWS::DynamoDB::Table") continue;
19
+
20
+ const props = resource.Properties ?? {};
21
+ const pitrSpec = props.PointInTimeRecoverySpecification;
22
+
23
+ let pitrEnabled = false;
24
+ if (typeof pitrSpec === "object" && pitrSpec !== null) {
25
+ pitrEnabled = (pitrSpec as Record<string, unknown>).PointInTimeRecoveryEnabled === true;
26
+ }
27
+
28
+ if (!pitrEnabled) {
29
+ diagnostics.push({
30
+ checkId: "WAW027",
31
+ severity: "info",
32
+ message: `DynamoDB table "${logicalId}" does not have point-in-time recovery enabled — consider enabling for data protection`,
33
+ entity: logicalId,
34
+ lexicon: "aws",
35
+ });
36
+ }
37
+ }
38
+ }
39
+
40
+ return diagnostics;
41
+ }
42
+
43
+ export const waw027: PostSynthCheck = {
44
+ id: "WAW027",
45
+ description: "DynamoDB table does not have point-in-time recovery enabled",
46
+
47
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
48
+ return checkDynamoDbPitr(ctx);
49
+ },
50
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * WAW028: EBS Volume Not Encrypted
3
+ *
4
+ * Flags EBS volumes without Encrypted: true.
5
+ */
6
+
7
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
8
+ import { parseCFTemplate, isIntrinsic } from "./cf-refs";
9
+
10
+ export function checkEbsEncryption(ctx: PostSynthContext): PostSynthDiagnostic[] {
11
+ const diagnostics: PostSynthDiagnostic[] = [];
12
+
13
+ for (const [_lexicon, output] of ctx.outputs) {
14
+ const template = parseCFTemplate(output);
15
+ if (!template?.Resources) continue;
16
+
17
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
18
+ if (resource.Type !== "AWS::EC2::Volume") continue;
19
+
20
+ const props = resource.Properties ?? {};
21
+ const encrypted = props.Encrypted;
22
+
23
+ if (isIntrinsic(encrypted)) continue;
24
+
25
+ if (encrypted !== true) {
26
+ diagnostics.push({
27
+ checkId: "WAW028",
28
+ severity: "warning",
29
+ message: `EBS volume "${logicalId}" does not have Encrypted: true — enable encryption at rest`,
30
+ entity: logicalId,
31
+ lexicon: "aws",
32
+ });
33
+ }
34
+ }
35
+ }
36
+
37
+ return diagnostics;
38
+ }
39
+
40
+ export const waw028: PostSynthCheck = {
41
+ id: "WAW028",
42
+ description: "EBS volume is not encrypted — enable encryption at rest",
43
+
44
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
45
+ return checkEbsEncryption(ctx);
46
+ },
47
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * WAW029: Invalid DependsOn Target
3
+ *
4
+ * Detects two cases in the serialized template:
5
+ * - Dangling reference: DependsOn target not in template.Resources
6
+ * - Self-reference: Resource depends on itself
7
+ */
8
+
9
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
10
+ import { parseCFTemplate } from "./cf-refs";
11
+
12
+ export function checkInvalidDependsOn(ctx: PostSynthContext): PostSynthDiagnostic[] {
13
+ const diagnostics: PostSynthDiagnostic[] = [];
14
+
15
+ for (const [_lexicon, output] of ctx.outputs) {
16
+ const template = parseCFTemplate(output);
17
+ if (!template?.Resources) continue;
18
+
19
+ const resourceIds = new Set(Object.keys(template.Resources));
20
+
21
+ for (const [logicalId, resource] of Object.entries(template.Resources)) {
22
+ if (!resource.DependsOn) continue;
23
+
24
+ const deps = Array.isArray(resource.DependsOn)
25
+ ? resource.DependsOn
26
+ : [resource.DependsOn];
27
+
28
+ for (const dep of deps) {
29
+ if (typeof dep !== "string") continue;
30
+
31
+ if (dep === logicalId) {
32
+ diagnostics.push({
33
+ checkId: "WAW029",
34
+ severity: "error",
35
+ message: `Resource "${logicalId}" has a DependsOn on itself — self-references are invalid`,
36
+ entity: logicalId,
37
+ lexicon: "aws",
38
+ });
39
+ } else if (!resourceIds.has(dep)) {
40
+ diagnostics.push({
41
+ checkId: "WAW029",
42
+ severity: "error",
43
+ message: `Resource "${logicalId}" has DependsOn "${dep}" which does not exist in the template`,
44
+ entity: logicalId,
45
+ lexicon: "aws",
46
+ });
47
+ }
48
+ }
49
+ }
50
+ }
51
+
52
+ return diagnostics;
53
+ }
54
+
55
+ export const waw029: PostSynthCheck = {
56
+ id: "WAW029",
57
+ description: "Invalid DependsOn target — dangling reference or self-reference",
58
+
59
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
60
+ return checkInvalidDependsOn(ctx);
61
+ },
62
+ };
@@ -0,0 +1,246 @@
1
+ /**
2
+ * WAW030: Missing DependsOn for Known Patterns
3
+ *
4
+ * Detects resources that are likely missing a required DependsOn
5
+ * based on well-known CloudFormation ordering requirements:
6
+ *
7
+ * - ECS Service with LoadBalancers but no DependsOn on a Listener
8
+ * - EC2 Route with GatewayId but no DependsOn on VPCGatewayAttachment
9
+ * - API Gateway Deployment with no DependsOn on any Method
10
+ * - API Gateway V2 Deployment with no DependsOn on any Route
11
+ * - DynamoDB ScalableTarget with no DependsOn on the Table
12
+ * - ECS ScalableTarget with no DependsOn on the ECS Service
13
+ */
14
+
15
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
16
+ import { parseCFTemplate } from "./cf-refs";
17
+
18
+ export function checkMissingDependsOn(ctx: PostSynthContext): PostSynthDiagnostic[] {
19
+ const diagnostics: PostSynthDiagnostic[] = [];
20
+
21
+ for (const [_lexicon, output] of ctx.outputs) {
22
+ const template = parseCFTemplate(output);
23
+ if (!template?.Resources) continue;
24
+
25
+ const resources = template.Resources;
26
+
27
+ // Collect logical IDs by type
28
+ const listenerIds: string[] = [];
29
+ const vpcGatewayAttachmentIds: string[] = [];
30
+ const methodIds: string[] = [];
31
+ const deploymentIds: string[] = [];
32
+ const routeV2Ids: string[] = [];
33
+ const deploymentV2Ids: string[] = [];
34
+ const dynamoTableIds: string[] = [];
35
+ const ecsServiceIds: string[] = [];
36
+ const scalableTargetEntries: { logicalId: string; namespace: string }[] = [];
37
+
38
+ for (const [logicalId, resource] of Object.entries(resources)) {
39
+ if (resource.Type === "AWS::ElasticLoadBalancingV2::Listener") {
40
+ listenerIds.push(logicalId);
41
+ }
42
+ if (resource.Type === "AWS::EC2::VPCGatewayAttachment") {
43
+ vpcGatewayAttachmentIds.push(logicalId);
44
+ }
45
+ if (resource.Type === "AWS::ApiGateway::Method") {
46
+ methodIds.push(logicalId);
47
+ }
48
+ if (resource.Type === "AWS::ApiGateway::Deployment") {
49
+ deploymentIds.push(logicalId);
50
+ }
51
+ if (resource.Type === "AWS::ApiGatewayV2::Route") {
52
+ routeV2Ids.push(logicalId);
53
+ }
54
+ if (resource.Type === "AWS::ApiGatewayV2::Deployment") {
55
+ deploymentV2Ids.push(logicalId);
56
+ }
57
+ if (resource.Type === "AWS::DynamoDB::Table") {
58
+ dynamoTableIds.push(logicalId);
59
+ }
60
+ if (resource.Type === "AWS::ECS::Service") {
61
+ ecsServiceIds.push(logicalId);
62
+ }
63
+ if (resource.Type === "AWS::ApplicationAutoScaling::ScalableTarget") {
64
+ const props = resource.Properties ?? {};
65
+ const ns = inferScalingNamespace(props);
66
+ if (ns) {
67
+ scalableTargetEntries.push({ logicalId, namespace: ns });
68
+ }
69
+ }
70
+ }
71
+
72
+ for (const [logicalId, resource] of Object.entries(resources)) {
73
+ // Pattern 1: ECS Service with LoadBalancers but no DependsOn on Listener
74
+ if (resource.Type === "AWS::ECS::Service" && listenerIds.length > 0) {
75
+ const props = resource.Properties ?? {};
76
+ if (props.LoadBalancers && Array.isArray(props.LoadBalancers) && props.LoadBalancers.length > 0) {
77
+ const deps = getDependsOnSet(resource);
78
+ const hasListenerDep = listenerIds.some((id) => deps.has(id));
79
+ if (!hasListenerDep) {
80
+ diagnostics.push({
81
+ checkId: "WAW030",
82
+ severity: "warning",
83
+ message: `ECS Service "${logicalId}" has LoadBalancers but no DependsOn on a Listener — the Service may fail to create if the Listener isn't ready`,
84
+ entity: logicalId,
85
+ lexicon: "aws",
86
+ });
87
+ }
88
+ }
89
+ }
90
+
91
+ // Pattern 2: EC2 Route with GatewayId but no DependsOn on VPCGatewayAttachment
92
+ if (resource.Type === "AWS::EC2::Route" && vpcGatewayAttachmentIds.length > 0) {
93
+ const props = resource.Properties ?? {};
94
+ if (props.GatewayId) {
95
+ const deps = getDependsOnSet(resource);
96
+ const hasAttachmentDep = vpcGatewayAttachmentIds.some((id) => deps.has(id));
97
+ // Also check if any property refs point to the attachment
98
+ const propRefs = collectPropertyRefs(resource);
99
+ const hasAttachmentRef = vpcGatewayAttachmentIds.some((id) => propRefs.has(id));
100
+ if (!hasAttachmentDep && !hasAttachmentRef) {
101
+ diagnostics.push({
102
+ checkId: "WAW030",
103
+ severity: "warning",
104
+ message: `Route "${logicalId}" uses a Gateway but has no dependency on VPCGatewayAttachment — the route may fail if the gateway isn't attached yet`,
105
+ entity: logicalId,
106
+ lexicon: "aws",
107
+ });
108
+ }
109
+ }
110
+ }
111
+
112
+ // Pattern 3: API Gateway Deployment with no DependsOn on any Method
113
+ if (resource.Type === "AWS::ApiGateway::Deployment" && methodIds.length > 0) {
114
+ const deps = getDependsOnSet(resource);
115
+ const hasMethodDep = methodIds.some((id) => deps.has(id));
116
+ const propRefs = collectPropertyRefs(resource);
117
+ const hasMethodRef = methodIds.some((id) => propRefs.has(id));
118
+ if (!hasMethodDep && !hasMethodRef) {
119
+ diagnostics.push({
120
+ checkId: "WAW030",
121
+ severity: "warning",
122
+ message: `API Gateway Deployment "${logicalId}" has no DependsOn on any Method — the deployment may fail with "REST API doesn't contain any methods"`,
123
+ entity: logicalId,
124
+ lexicon: "aws",
125
+ });
126
+ }
127
+ }
128
+
129
+ // Pattern 4: API Gateway V2 Deployment with no DependsOn on any Route
130
+ if (resource.Type === "AWS::ApiGatewayV2::Deployment" && routeV2Ids.length > 0) {
131
+ const deps = getDependsOnSet(resource);
132
+ const hasRouteDep = routeV2Ids.some((id) => deps.has(id));
133
+ const propRefs = collectPropertyRefs(resource);
134
+ const hasRouteRef = routeV2Ids.some((id) => propRefs.has(id));
135
+ if (!hasRouteDep && !hasRouteRef) {
136
+ diagnostics.push({
137
+ checkId: "WAW030",
138
+ severity: "warning",
139
+ message: `API Gateway V2 Deployment "${logicalId}" has no DependsOn on any Route — the deployment may fail if no routes exist yet`,
140
+ entity: logicalId,
141
+ lexicon: "aws",
142
+ });
143
+ }
144
+ }
145
+ }
146
+
147
+ // Pattern 5 & 6: ScalableTarget with no DependsOn on the target resource
148
+ for (const entry of scalableTargetEntries) {
149
+ const resource = resources[entry.logicalId];
150
+ const deps = getDependsOnSet(resource);
151
+ const propRefs = collectPropertyRefs(resource);
152
+
153
+ if (entry.namespace === "dynamodb" && dynamoTableIds.length > 0) {
154
+ const hasTableDep = dynamoTableIds.some((id) => deps.has(id));
155
+ const hasTableRef = dynamoTableIds.some((id) => propRefs.has(id));
156
+ if (!hasTableDep && !hasTableRef) {
157
+ diagnostics.push({
158
+ checkId: "WAW030",
159
+ severity: "warning",
160
+ message: `ScalableTarget "${entry.logicalId}" targets DynamoDB but has no DependsOn on any Table — scaling registration may fail if the table doesn't exist yet`,
161
+ entity: entry.logicalId,
162
+ lexicon: "aws",
163
+ });
164
+ }
165
+ }
166
+
167
+ if (entry.namespace === "ecs" && ecsServiceIds.length > 0) {
168
+ const hasServiceDep = ecsServiceIds.some((id) => deps.has(id));
169
+ const hasServiceRef = ecsServiceIds.some((id) => propRefs.has(id));
170
+ if (!hasServiceDep && !hasServiceRef) {
171
+ diagnostics.push({
172
+ checkId: "WAW030",
173
+ severity: "warning",
174
+ message: `ScalableTarget "${entry.logicalId}" targets ECS but has no DependsOn on any ECS Service — scaling registration may fail if the service doesn't exist yet`,
175
+ entity: entry.logicalId,
176
+ lexicon: "aws",
177
+ });
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ return diagnostics;
184
+ }
185
+
186
+ /** Infer the scaling namespace from a ScalableTarget's properties. */
187
+ function inferScalingNamespace(props: Record<string, unknown>): string | null {
188
+ if (typeof props.ServiceNamespace === "string") {
189
+ return props.ServiceNamespace;
190
+ }
191
+ if (typeof props.ScalableDimension === "string") {
192
+ const prefix = props.ScalableDimension.split(":")[0];
193
+ if (prefix) return prefix;
194
+ }
195
+ return null;
196
+ }
197
+
198
+ /** Extract DependsOn entries as a Set of strings. */
199
+ function getDependsOnSet(resource: { DependsOn?: string | string[] }): Set<string> {
200
+ if (!resource.DependsOn) return new Set();
201
+ const deps = Array.isArray(resource.DependsOn)
202
+ ? resource.DependsOn
203
+ : [resource.DependsOn];
204
+ return new Set(deps.filter((d): d is string => typeof d === "string"));
205
+ }
206
+
207
+ /** Collect all Ref and Fn::GetAtt target logical IDs from resource properties. */
208
+ function collectPropertyRefs(resource: { Properties?: Record<string, unknown> }): Set<string> {
209
+ const refs = new Set<string>();
210
+ if (!resource.Properties) return refs;
211
+
212
+ function walk(value: unknown): void {
213
+ if (typeof value !== "object" || value === null) return;
214
+ if (Array.isArray(value)) {
215
+ for (const item of value) walk(item);
216
+ return;
217
+ }
218
+ const obj = value as Record<string, unknown>;
219
+ if ("Ref" in obj && typeof obj.Ref === "string") {
220
+ refs.add(obj.Ref);
221
+ }
222
+ if ("Fn::GetAtt" in obj) {
223
+ const getAtt = obj["Fn::GetAtt"];
224
+ if (Array.isArray(getAtt) && typeof getAtt[0] === "string") {
225
+ refs.add(getAtt[0]);
226
+ } else if (typeof getAtt === "string") {
227
+ // Dot-delimited form: "LogicalId.Attribute"
228
+ const logicalId = getAtt.split(".")[0];
229
+ if (logicalId) refs.add(logicalId);
230
+ }
231
+ }
232
+ for (const val of Object.values(obj)) walk(val);
233
+ }
234
+
235
+ walk(resource.Properties);
236
+ return refs;
237
+ }
238
+
239
+ export const waw030: PostSynthCheck = {
240
+ id: "WAW030",
241
+ description: "Missing DependsOn for known CloudFormation ordering patterns",
242
+
243
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
244
+ return checkMissingDependsOn(ctx);
245
+ },
246
+ };