@jaypie/constructs 1.1.63 → 1.1.65

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 (131) hide show
  1. package/package.json +6 -6
  2. package/dist/cjs/JaypieAccountLoggingBucket.d.ts +0 -60
  3. package/dist/cjs/JaypieApiGateway.d.ts +0 -47
  4. package/dist/cjs/JaypieAppStack.d.ts +0 -5
  5. package/dist/cjs/JaypieBucketQueuedLambda.d.ts +0 -48
  6. package/dist/cjs/JaypieDatadogBucket.d.ts +0 -55
  7. package/dist/cjs/JaypieDatadogForwarder.d.ts +0 -76
  8. package/dist/cjs/JaypieDatadogSecret.d.ts +0 -5
  9. package/dist/cjs/JaypieDistribution.d.ts +0 -76
  10. package/dist/cjs/JaypieDnsRecord.d.ts +0 -45
  11. package/dist/cjs/JaypieEnvSecret.d.ts +0 -40
  12. package/dist/cjs/JaypieEventsRule.d.ts +0 -45
  13. package/dist/cjs/JaypieExpressLambda.d.ts +0 -5
  14. package/dist/cjs/JaypieGitHubDeployRole.d.ts +0 -14
  15. package/dist/cjs/JaypieHostedZone.d.ts +0 -59
  16. package/dist/cjs/JaypieInfrastructureStack.d.ts +0 -5
  17. package/dist/cjs/JaypieLambda.d.ts +0 -100
  18. package/dist/cjs/JaypieMongoDbSecret.d.ts +0 -5
  19. package/dist/cjs/JaypieNextJs.d.ts +0 -18
  20. package/dist/cjs/JaypieNextJs.test.d.ts +0 -1
  21. package/dist/cjs/JaypieOpenAiSecret.d.ts +0 -5
  22. package/dist/cjs/JaypieOrganizationTrail.d.ts +0 -62
  23. package/dist/cjs/JaypieQueuedLambda.d.ts +0 -73
  24. package/dist/cjs/JaypieSsoPermissions.d.ts +0 -96
  25. package/dist/cjs/JaypieSsoSyncApplication.d.ts +0 -27
  26. package/dist/cjs/JaypieStack.d.ts +0 -8
  27. package/dist/cjs/JaypieStaticWebBucket.d.ts +0 -22
  28. package/dist/cjs/JaypieTraceSigningKeySecret.d.ts +0 -5
  29. package/dist/cjs/JaypieWebDeploymentBucket.d.ts +0 -84
  30. package/dist/cjs/__tests__/JaypieBucketQueuedLambda.spec.d.ts +0 -1
  31. package/dist/cjs/__tests__/JaypieDistribution.spec.d.ts +0 -1
  32. package/dist/cjs/__tests__/JaypieDnsRecord.spec.d.ts +0 -1
  33. package/dist/cjs/__tests__/JaypieEnvSecret.spec.d.ts +0 -1
  34. package/dist/cjs/__tests__/JaypieExpressLambda.spec.d.ts +0 -1
  35. package/dist/cjs/__tests__/JaypieHostedZone.spec.d.ts +0 -1
  36. package/dist/cjs/__tests__/JaypieLambda.spec.d.ts +0 -1
  37. package/dist/cjs/__tests__/JaypieQueuedLambda.spec.d.ts +0 -1
  38. package/dist/cjs/__tests__/JaypieSsoPermissions.spec.d.ts +0 -1
  39. package/dist/cjs/__tests__/JaypieSsoSyncApplication.spec.d.ts +0 -1
  40. package/dist/cjs/__tests__/JaypieStaticWebBucket.spec.d.ts +0 -1
  41. package/dist/cjs/__tests__/index.spec.d.ts +0 -1
  42. package/dist/cjs/constants.d.ts +0 -151
  43. package/dist/cjs/helpers/__tests__/envHostname.spec.d.ts +0 -1
  44. package/dist/cjs/helpers/__tests__/jaypieLambdaEnv.spec.d.ts +0 -1
  45. package/dist/cjs/helpers/__tests__/resolveDatadogForwarderFunction.spec.d.ts +0 -1
  46. package/dist/cjs/helpers/__tests__/resolveDatadogLoggingDestination.spec.d.ts +0 -1
  47. package/dist/cjs/helpers/addDatadogLayers.d.ts +0 -5
  48. package/dist/cjs/helpers/constructEnvName.d.ts +0 -5
  49. package/dist/cjs/helpers/constructStackName.d.ts +0 -1
  50. package/dist/cjs/helpers/constructTagger.d.ts +0 -4
  51. package/dist/cjs/helpers/envHostname.d.ts +0 -6
  52. package/dist/cjs/helpers/extendDatadogRole.d.ts +0 -31
  53. package/dist/cjs/helpers/index.d.ts +0 -16
  54. package/dist/cjs/helpers/isEnv.d.ts +0 -12
  55. package/dist/cjs/helpers/isValidHostname.d.ts +0 -1
  56. package/dist/cjs/helpers/isValidSubdomain.d.ts +0 -1
  57. package/dist/cjs/helpers/jaypieLambdaEnv.d.ts +0 -8
  58. package/dist/cjs/helpers/mergeDomain.d.ts +0 -1
  59. package/dist/cjs/helpers/resolveDatadogForwarderFunction.d.ts +0 -7
  60. package/dist/cjs/helpers/resolveDatadogLayers.d.ts +0 -7
  61. package/dist/cjs/helpers/resolveDatadogLoggingDestination.d.ts +0 -4
  62. package/dist/cjs/helpers/resolveHostedZone.d.ts +0 -6
  63. package/dist/cjs/helpers/resolveParamsAndSecrets.d.ts +0 -13
  64. package/dist/cjs/index.cjs +0 -3322
  65. package/dist/cjs/index.cjs.map +0 -1
  66. package/dist/cjs/index.d.ts +0 -29
  67. package/dist/esm/JaypieAccountLoggingBucket.d.ts +0 -60
  68. package/dist/esm/JaypieApiGateway.d.ts +0 -47
  69. package/dist/esm/JaypieAppStack.d.ts +0 -5
  70. package/dist/esm/JaypieBucketQueuedLambda.d.ts +0 -48
  71. package/dist/esm/JaypieDatadogBucket.d.ts +0 -55
  72. package/dist/esm/JaypieDatadogForwarder.d.ts +0 -76
  73. package/dist/esm/JaypieDatadogSecret.d.ts +0 -5
  74. package/dist/esm/JaypieDistribution.d.ts +0 -76
  75. package/dist/esm/JaypieDnsRecord.d.ts +0 -45
  76. package/dist/esm/JaypieEnvSecret.d.ts +0 -40
  77. package/dist/esm/JaypieEventsRule.d.ts +0 -45
  78. package/dist/esm/JaypieExpressLambda.d.ts +0 -5
  79. package/dist/esm/JaypieGitHubDeployRole.d.ts +0 -14
  80. package/dist/esm/JaypieHostedZone.d.ts +0 -59
  81. package/dist/esm/JaypieInfrastructureStack.d.ts +0 -5
  82. package/dist/esm/JaypieLambda.d.ts +0 -100
  83. package/dist/esm/JaypieMongoDbSecret.d.ts +0 -5
  84. package/dist/esm/JaypieNextJs.d.ts +0 -18
  85. package/dist/esm/JaypieNextJs.test.d.ts +0 -1
  86. package/dist/esm/JaypieOpenAiSecret.d.ts +0 -5
  87. package/dist/esm/JaypieOrganizationTrail.d.ts +0 -62
  88. package/dist/esm/JaypieQueuedLambda.d.ts +0 -73
  89. package/dist/esm/JaypieSsoPermissions.d.ts +0 -96
  90. package/dist/esm/JaypieSsoSyncApplication.d.ts +0 -27
  91. package/dist/esm/JaypieStack.d.ts +0 -8
  92. package/dist/esm/JaypieStaticWebBucket.d.ts +0 -22
  93. package/dist/esm/JaypieTraceSigningKeySecret.d.ts +0 -5
  94. package/dist/esm/JaypieWebDeploymentBucket.d.ts +0 -84
  95. package/dist/esm/__tests__/JaypieBucketQueuedLambda.spec.d.ts +0 -1
  96. package/dist/esm/__tests__/JaypieDistribution.spec.d.ts +0 -1
  97. package/dist/esm/__tests__/JaypieDnsRecord.spec.d.ts +0 -1
  98. package/dist/esm/__tests__/JaypieEnvSecret.spec.d.ts +0 -1
  99. package/dist/esm/__tests__/JaypieExpressLambda.spec.d.ts +0 -1
  100. package/dist/esm/__tests__/JaypieHostedZone.spec.d.ts +0 -1
  101. package/dist/esm/__tests__/JaypieLambda.spec.d.ts +0 -1
  102. package/dist/esm/__tests__/JaypieQueuedLambda.spec.d.ts +0 -1
  103. package/dist/esm/__tests__/JaypieSsoPermissions.spec.d.ts +0 -1
  104. package/dist/esm/__tests__/JaypieSsoSyncApplication.spec.d.ts +0 -1
  105. package/dist/esm/__tests__/JaypieStaticWebBucket.spec.d.ts +0 -1
  106. package/dist/esm/__tests__/index.spec.d.ts +0 -1
  107. package/dist/esm/constants.d.ts +0 -151
  108. package/dist/esm/helpers/__tests__/envHostname.spec.d.ts +0 -1
  109. package/dist/esm/helpers/__tests__/jaypieLambdaEnv.spec.d.ts +0 -1
  110. package/dist/esm/helpers/__tests__/resolveDatadogForwarderFunction.spec.d.ts +0 -1
  111. package/dist/esm/helpers/__tests__/resolveDatadogLoggingDestination.spec.d.ts +0 -1
  112. package/dist/esm/helpers/addDatadogLayers.d.ts +0 -5
  113. package/dist/esm/helpers/constructEnvName.d.ts +0 -5
  114. package/dist/esm/helpers/constructStackName.d.ts +0 -1
  115. package/dist/esm/helpers/constructTagger.d.ts +0 -4
  116. package/dist/esm/helpers/envHostname.d.ts +0 -6
  117. package/dist/esm/helpers/extendDatadogRole.d.ts +0 -31
  118. package/dist/esm/helpers/index.d.ts +0 -16
  119. package/dist/esm/helpers/isEnv.d.ts +0 -12
  120. package/dist/esm/helpers/isValidHostname.d.ts +0 -1
  121. package/dist/esm/helpers/isValidSubdomain.d.ts +0 -1
  122. package/dist/esm/helpers/jaypieLambdaEnv.d.ts +0 -8
  123. package/dist/esm/helpers/mergeDomain.d.ts +0 -1
  124. package/dist/esm/helpers/resolveDatadogForwarderFunction.d.ts +0 -7
  125. package/dist/esm/helpers/resolveDatadogLayers.d.ts +0 -7
  126. package/dist/esm/helpers/resolveDatadogLoggingDestination.d.ts +0 -4
  127. package/dist/esm/helpers/resolveHostedZone.d.ts +0 -6
  128. package/dist/esm/helpers/resolveParamsAndSecrets.d.ts +0 -13
  129. package/dist/esm/index.d.ts +0 -29
  130. package/dist/esm/index.js +0 -3246
  131. package/dist/esm/index.js.map +0 -1
package/dist/esm/index.js DELETED
@@ -1,3246 +0,0 @@
1
- import * as cdk from 'aws-cdk-lib';
2
- import { Tags, Stack, Duration, RemovalPolicy, CfnStack, Fn, CfnOutput, SecretValue } from 'aws-cdk-lib';
3
- import * as s3 from 'aws-cdk-lib/aws-s3';
4
- import { Bucket, StorageClass, BucketAccessControl, EventType } from 'aws-cdk-lib/aws-s3';
5
- import { Construct } from 'constructs';
6
- import * as acm from 'aws-cdk-lib/aws-certificatemanager';
7
- import * as apiGateway from 'aws-cdk-lib/aws-apigateway';
8
- import * as route53 from 'aws-cdk-lib/aws-route53';
9
- import { TxtRecord, NsRecord, MxRecord, CnameRecord, ARecord, RecordTarget, HostedZone } from 'aws-cdk-lib/aws-route53';
10
- import * as route53Targets from 'aws-cdk-lib/aws-route53-targets';
11
- import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
12
- import { DatadogLambda } from 'datadog-cdk-constructs-v2';
13
- import { ConfigurationError } from '@jaypie/errors';
14
- import { Role, PolicyStatement, Policy, FederatedPrincipal, Effect, ServicePrincipal, ManagedPolicy } from 'aws-cdk-lib/aws-iam';
15
- import * as lambda from 'aws-cdk-lib/aws-lambda';
16
- import * as logDestinations from 'aws-cdk-lib/aws-logs-destinations';
17
- import * as s3n from 'aws-cdk-lib/aws-s3-notifications';
18
- import { LambdaDestination } from 'aws-cdk-lib/aws-s3-notifications';
19
- import * as sqs from 'aws-cdk-lib/aws-sqs';
20
- import * as lambdaEventSources from 'aws-cdk-lib/aws-lambda-event-sources';
21
- import * as logs from 'aws-cdk-lib/aws-logs';
22
- import { LogGroup, RetentionDays, FilterPattern } from 'aws-cdk-lib/aws-logs';
23
- import { Rule, RuleTargetInput } from 'aws-cdk-lib/aws-events';
24
- import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets';
25
- import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
26
- import * as origins from 'aws-cdk-lib/aws-cloudfront-origins';
27
- import { Nextjs } from 'cdk-nextjs-standalone';
28
- import * as path from 'path';
29
- import { Trail, ReadWriteType } from 'aws-cdk-lib/aws-cloudtrail';
30
- import { CfnPermissionSet, CfnAssignment } from 'aws-cdk-lib/aws-sso';
31
- import { CfnApplication } from 'aws-cdk-lib/aws-sam';
32
-
33
- const CDK$2 = {
34
- ACCOUNT: {
35
- DEVELOPMENT: "development",
36
- MANAGEMENT: "management",
37
- OPERATIONS: "operations",
38
- PRODUCTION: "production",
39
- SANDBOX: "sandbox",
40
- SECURITY: "security",
41
- STAGE: "stage",
42
- },
43
- BUILD: {
44
- CONFIG: {
45
- ALL: "all",
46
- API: "api",
47
- INFRASTRUCTURE: "infrastructure",
48
- NONE: "none",
49
- WEB: "web",
50
- },
51
- PERSONAL: "personal",
52
- /**
53
- * @deprecated rename "ephemeral" to "personal" (since 2/24/2025)
54
- */
55
- EPHEMERAL: "ephemeral",
56
- /**
57
- * @deprecated as even "ephemeral" builds have static assets (since 7/6/2024)
58
- */
59
- STATIC: "static",
60
- },
61
- CREATION: {
62
- CDK: "cdk",
63
- CLOUDFORMATION_TEMPLATE: "template",
64
- MANUAL: "manual",
65
- },
66
- DATADOG: {
67
- SITE: "datadoghq.com",
68
- LAYER: {
69
- // https://docs.datadoghq.com/serverless/aws_lambda/installation/nodejs/?tab=awscdk
70
- NODE: 127, // 127 on 9/12/2025
71
- EXTENSION: 86, // 86 on 9/12/2025
72
- },
73
- },
74
- DEFAULT: {
75
- REGION: "us-east-1",
76
- },
77
- DNS: {
78
- CONFIG: {
79
- TTL: 300, // 5 minutes in seconds for Route53
80
- },
81
- RECORD: {
82
- A: "A",
83
- CNAME: "CNAME",
84
- MX: "MX",
85
- NS: "NS",
86
- TXT: "TXT",
87
- },
88
- },
89
- DURATION: {
90
- EXPRESS_API: 30,
91
- LAMBDA_MAXIMUM: 900,
92
- LAMBDA_WORKER: 900,
93
- },
94
- ENV: {
95
- DEMO: "demo", // Mirror of production
96
- DEVELOPMENT: "development", // Internal most stable development space
97
- /** @deprecated */ EPHEMERAL: "ephemeral", // Alias for "build"
98
- LOCAL: "local",
99
- /** @deprecated */ MAIN: "main", // Alias for development
100
- META: "meta", // For non-environment/infrastructure stacks
101
- PERSONAL: "personal", // Personal builds using resources provided by sandbox
102
- PREVIEW: "preview", // External next thing to be released
103
- PRODUCTION: "production",
104
- RELEASE: "release", // Internal next thing to be released
105
- REVIEW: "review", // Internal place to collaborate on issues
106
- SANDBOX: "sandbox", // Internal build space with no guaranteed longevity
107
- TRAINING: "training", // aka "test"; mirror of production for external audiences
108
- },
109
- HOST: {
110
- APEX: "@",
111
- },
112
- IMPORT: {
113
- DATADOG_LOG_FORWARDER: "account-datadog-forwarder",
114
- DATADOG_ROLE: "account-datadog-role",
115
- DATADOG_SECRET: "account-datadog-secret",
116
- LOG_BUCKET: "account-log-bucket",
117
- OIDC_PROVIDER: "github-oidc-provider",
118
- },
119
- LAMBDA: {
120
- LOG_RETENTION: 90,
121
- MEMORY_SIZE: 1024,
122
- },
123
- PRINCIPAL: {
124
- ROUTE53: "route53.amazonaws.com",
125
- },
126
- PRINCIPAL_TYPE: {
127
- GROUP: "GROUP",
128
- USER: "USER",
129
- },
130
- PROJECT: {
131
- INFRASTRUCTURE: "infrastructure",
132
- },
133
- ROLE: {
134
- API: "api",
135
- DEPLOY: "deploy",
136
- HOSTING: "hosting",
137
- MONITORING: "monitoring",
138
- NETWORKING: "networking",
139
- PROCESSING: "processing",
140
- SECURITY: "security",
141
- STACK: "stack",
142
- STORAGE: "storage",
143
- TOY: "toy",
144
- },
145
- SERVICE: {
146
- DATADOG: "datadog",
147
- INFRASTRUCTURE: "infrastructure",
148
- LIBRARIES: "libraries",
149
- NONE: "none",
150
- SSO: "sso",
151
- TRACE: "trace",
152
- },
153
- TAG: {
154
- BUILD_DATE: "buildDate",
155
- BUILD_HEX: "buildHex",
156
- BUILD_NUMBER: "buildNumber",
157
- BUILD_TIME: "buildTime",
158
- BUILD_TYPE: "buildType",
159
- COMMIT: "commit",
160
- CREATION: "creation",
161
- ENV: "env",
162
- NONCE: "nonce",
163
- PROJECT: "project",
164
- ROLE: "role",
165
- SERVICE: "service",
166
- SPONSOR: "sponsor",
167
- STACK: "stack",
168
- STACK_SHA: "stackSha",
169
- VENDOR: "vendor",
170
- VERSION: "version",
171
- },
172
- TARGET_TYPE: {
173
- AWS_ACCOUNT: "AWS_ACCOUNT",
174
- },
175
- VENDOR: {
176
- ANTHROPIC: "anthropic",
177
- AUTH0: "auth0",
178
- DATADOG: "datadog",
179
- KNOWTRACE: "knowtrace",
180
- MONGODB: "mongodb",
181
- OPENAI: "openai",
182
- SPLINTERLANDS: "splinterlands",
183
- },
184
- };
185
-
186
- class JaypieAccountLoggingBucket extends Construct {
187
- /**
188
- * Create a new account-wide logging S3 bucket with lifecycle policies and export
189
- */
190
- constructor(scope, idOrProps, propsOrUndefined) {
191
- // Handle overloaded constructor signatures
192
- let props;
193
- let id;
194
- if (typeof idOrProps === "string") {
195
- // First param is ID, second is props
196
- props = propsOrUndefined || {};
197
- id = idOrProps;
198
- }
199
- else {
200
- // First param is props
201
- props = idOrProps || {};
202
- id = props.id || "AccountLoggingBucket";
203
- }
204
- super(scope, id);
205
- // Generate default bucket name with PROJECT_NONCE
206
- const defaultBucketName = process.env.PROJECT_NONCE
207
- ? `account-logging-stack-${process.env.PROJECT_NONCE.toLowerCase()}`
208
- : "account-logging-stack";
209
- // Extract Jaypie-specific options
210
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
211
- const { bucketName = defaultBucketName, createOutput = true, expirationDays = 365, exportName = CDK$2.IMPORT.LOG_BUCKET, glacierTransitionDays = 180, id: _id, infrequentAccessTransitionDays = 30, outputDescription = "Account-wide logging bucket", project, service = CDK$2.SERVICE.INFRASTRUCTURE, ...bucketProps } = props;
212
- // Create the bucket with lifecycle rules
213
- this.bucket = new Bucket(this, "Bucket", {
214
- accessControl: BucketAccessControl.LOG_DELIVERY_WRITE,
215
- bucketName,
216
- lifecycleRules: [
217
- {
218
- expiration: cdk.Duration.days(expirationDays),
219
- transitions: [
220
- {
221
- storageClass: StorageClass.INFREQUENT_ACCESS,
222
- transitionAfter: cdk.Duration.days(infrequentAccessTransitionDays),
223
- },
224
- {
225
- storageClass: StorageClass.GLACIER,
226
- transitionAfter: cdk.Duration.days(glacierTransitionDays),
227
- },
228
- ],
229
- },
230
- ],
231
- ...bucketProps,
232
- });
233
- // Add tags
234
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
235
- if (service) {
236
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.SERVICE, service);
237
- }
238
- if (project) {
239
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.PROJECT, project);
240
- }
241
- // Create CloudFormation output if enabled
242
- if (createOutput) {
243
- new cdk.CfnOutput(this, "BucketNameOutput", {
244
- description: outputDescription,
245
- exportName,
246
- value: this.bucket.bucketName,
247
- });
248
- }
249
- }
250
- }
251
-
252
- function addDatadogLayers(lambdaFunction, options = {}) {
253
- const datadogApiKeyArn = options?.datadogApiKeyArn;
254
- const resolvedDatadogApiKeyArn = datadogApiKeyArn ||
255
- process.env.DATADOG_API_KEY_ARN ||
256
- process.env.CDK_ENV_DATADOG_API_KEY_ARN;
257
- if (!resolvedDatadogApiKeyArn) {
258
- return false;
259
- }
260
- // Define Datadog environment variables
261
- const datadogEnvVars = {
262
- DD_API_KEY_SECRET_ARN: resolvedDatadogApiKeyArn,
263
- DD_ENHANCED_METRICS: "true",
264
- DD_ENV: process.env.PROJECT_ENV || "",
265
- DD_PROFILING_ENABLED: "false",
266
- DD_SERVERLESS_APPSEC_ENABLED: "false",
267
- DD_SERVICE: process.env.PROJECT_SERVICE || "",
268
- DD_SITE: CDK$2.DATADOG.SITE,
269
- DD_TAGS: `${CDK$2.TAG.SPONSOR}:${process.env.PROJECT_SPONSOR || ""}`,
270
- DD_TRACE_OTEL_ENABLED: "false",
271
- };
272
- // Add environment variables only if they don't already exist
273
- Object.entries(datadogEnvVars).forEach(([key, value]) => {
274
- lambdaFunction.addEnvironment(key, value);
275
- });
276
- const datadogApiKeySecret = secretsmanager.Secret.fromSecretCompleteArn(lambdaFunction, "DatadogApiKey", resolvedDatadogApiKeyArn);
277
- const datadogLambda = new DatadogLambda(lambdaFunction, "DatadogLambda", {
278
- apiKeySecret: datadogApiKeySecret, // apiKeySecret auto-grants secret access to the added lambdas
279
- nodeLayerVersion: CDK$2.DATADOG.LAYER.NODE,
280
- extensionLayerVersion: CDK$2.DATADOG.LAYER.EXTENSION,
281
- env: process.env.PROJECT_ENV,
282
- service: process.env.PROJECT_SERVICE,
283
- version: process.env.PROJECT_VERSION,
284
- });
285
- datadogLambda.addLambdaFunctions([lambdaFunction]);
286
- return true;
287
- }
288
-
289
- function constructEnvName(name, opts) {
290
- const env = opts?.env ?? process.env.PROJECT_ENV ?? "build";
291
- const key = opts?.key ?? process.env.PROJECT_KEY ?? "project";
292
- const nonce = opts?.nonce ?? process.env.PROJECT_NONCE ?? "cfe2"; // This default is intentionally short. It is not a special value but should not be changed.
293
- return `${env}-${key}-${name}-${nonce}`;
294
- }
295
-
296
- function constructStackName(key) {
297
- if (!key) {
298
- return `cdk-${process.env.PROJECT_SPONSOR}-${process.env.PROJECT_KEY}-${process.env.PROJECT_ENV}-${process.env.PROJECT_NONCE}`;
299
- }
300
- else {
301
- return `cdk-${process.env.PROJECT_SPONSOR}-${process.env.PROJECT_KEY}-${process.env.PROJECT_ENV}-${process.env.PROJECT_NONCE}-${key}`;
302
- }
303
- }
304
-
305
- const CDK$1 = {
306
- CREATION: {
307
- CDK: "cdk",
308
- },
309
- ROLE: {
310
- STACK: "stack",
311
- },
312
- TAG: {
313
- BUILD_DATE: "buildDate",
314
- BUILD_HEX: "buildHex",
315
- BUILD_TIME: "buildTime",
316
- COMMIT: "commit",
317
- CREATION: "creation",
318
- ENV: "env",
319
- NONCE: "nonce",
320
- PROJECT: "project",
321
- ROLE: "role",
322
- SERVICE: "service",
323
- SPONSOR: "sponsor",
324
- STACK: "stack",
325
- VERSION: "version",
326
- },
327
- };
328
- function constructTagger(construct, { name } = {}) {
329
- const stackName = name || constructStackName();
330
- const version = process.env.npm_package_version || process.env.PROJECT_VERSION || null;
331
- if (process.env.PROJECT_COMMIT && process.env.PROJECT_COMMIT.length > 8) {
332
- Tags.of(construct).add(CDK$1.TAG.BUILD_HEX, process.env.PROJECT_COMMIT.slice(0, 8));
333
- }
334
- Tags.of(construct).add(CDK$1.TAG.BUILD_DATE, new Date().toISOString());
335
- Tags.of(construct).add(CDK$1.TAG.BUILD_TIME, Date.now().toString());
336
- if (process.env.PROJECT_COMMIT)
337
- Tags.of(construct).add(CDK$1.TAG.COMMIT, process.env.PROJECT_COMMIT);
338
- Tags.of(construct).add(CDK$1.TAG.CREATION, CDK$1.CREATION.CDK);
339
- if (process.env.PROJECT_ENV)
340
- Tags.of(construct).add(CDK$1.TAG.ENV, process.env.PROJECT_ENV);
341
- if (process.env.PROJECT_NONCE)
342
- Tags.of(construct).add(CDK$1.TAG.NONCE, process.env.PROJECT_NONCE);
343
- if (process.env.PROJECT_KEY)
344
- Tags.of(construct).add(CDK$1.TAG.PROJECT, process.env.PROJECT_KEY);
345
- Tags.of(construct).add(CDK$1.TAG.ROLE, CDK$1.ROLE.STACK);
346
- if (process.env.PROJECT_SERVICE)
347
- Tags.of(construct).add(CDK$1.TAG.SERVICE, process.env.PROJECT_SERVICE);
348
- if (process.env.PROJECT_SPONSOR)
349
- Tags.of(construct).add(CDK$1.TAG.SPONSOR, process.env.PROJECT_SPONSOR);
350
- if (stackName)
351
- Tags.of(construct).add(CDK$1.TAG.STACK, stackName);
352
- if (version)
353
- Tags.of(construct).add(CDK$1.TAG.VERSION, version);
354
- return true;
355
- }
356
-
357
- function envHostname({ component, domain, env, subdomain, } = {}) {
358
- const resolvedDomain = domain || process.env.CDK_ENV_DOMAIN || process.env.CDK_ENV_HOSTED_ZONE;
359
- if (!resolvedDomain) {
360
- throw new ConfigurationError("No hostname `domain` provided. Set CDK_ENV_DOMAIN or CDK_ENV_HOSTED_ZONE to use environment domain");
361
- }
362
- const resolvedComponent = component === "@" || component === "" ? undefined : component;
363
- const resolvedSubdomain = subdomain || process.env.CDK_ENV_SUBDOMAIN;
364
- const resolvedEnv = env || process.env.PROJECT_ENV;
365
- const filteredEnv = resolvedEnv === CDK$2.ENV.PRODUCTION ? undefined : resolvedEnv;
366
- const parts = [
367
- resolvedComponent,
368
- resolvedSubdomain,
369
- filteredEnv,
370
- resolvedDomain,
371
- ].filter((part) => part);
372
- return parts.join(".");
373
- }
374
-
375
- /**
376
- * Extends the Datadog IAM role with additional permissions
377
- *
378
- * Checks for CDK_ENV_DATADOG_ROLE_ARN environment variable.
379
- * If found, creates a custom policy with:
380
- * - budgets:ViewBudget
381
- * - logs:DescribeLogGroups
382
- *
383
- * @param scope - The construct scope
384
- * @param options - Configuration options
385
- * @returns The created Policy, or undefined if CDK_ENV_DATADOG_ROLE_ARN is not set
386
- */
387
- function extendDatadogRole(scope, options) {
388
- const datadogRoleArn = process.env.CDK_ENV_DATADOG_ROLE_ARN;
389
- // Early return if no Datadog role ARN is configured
390
- if (!datadogRoleArn) {
391
- return undefined;
392
- }
393
- const { id = "DatadogCustomPolicy", project, service = CDK$2.SERVICE.DATADOG, } = options || {};
394
- // Lookup the Datadog role
395
- const datadogRole = Role.fromRoleArn(scope, "DatadogRole", datadogRoleArn);
396
- // Build policy statements
397
- const statements = [
398
- // Allow view budget
399
- new PolicyStatement({
400
- actions: ["budgets:ViewBudget"],
401
- resources: ["*"],
402
- }),
403
- // Allow describe log groups
404
- new PolicyStatement({
405
- actions: ["logs:DescribeLogGroups"],
406
- resources: ["*"],
407
- }),
408
- ];
409
- // Create the custom policy
410
- const datadogCustomPolicy = new Policy(scope, id, {
411
- roles: [datadogRole],
412
- statements,
413
- });
414
- // Add tags
415
- cdk.Tags.of(datadogCustomPolicy).add(CDK$2.TAG.SERVICE, service);
416
- cdk.Tags.of(datadogCustomPolicy).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
417
- cdk.Tags.of(datadogCustomPolicy).add(CDK$2.TAG.VENDOR, CDK$2.VENDOR.DATADOG);
418
- if (project) {
419
- cdk.Tags.of(datadogCustomPolicy).add(CDK$2.TAG.PROJECT, project);
420
- }
421
- return datadogCustomPolicy;
422
- }
423
-
424
- /**
425
- * Check if the current environment matches the given environment
426
- */
427
- function isEnv(env) {
428
- return process.env.PROJECT_ENV === env;
429
- }
430
- /**
431
- * Check if the current environment is production
432
- */
433
- function isProductionEnv() {
434
- return isEnv(CDK$2.ENV.PRODUCTION);
435
- }
436
- /**
437
- * Check if the current environment is sandbox
438
- */
439
- function isSandboxEnv() {
440
- return isEnv(CDK$2.ENV.SANDBOX);
441
- }
442
-
443
- // In short the RFC 1035 standard for valid hostnames is:
444
- // 1. Must be less than 253 characters
445
- // 2. Must start with a letter
446
- // 3. Must end with a letter or number
447
- // 4. Can only contain letters, numbers, and hyphens
448
- // 5. Last part of the domain must be at least 2 characters
449
- function validPart$1(part) {
450
- if (!part.match(/^[a-z]/))
451
- return false;
452
- if (!part.match(/[a-z0-9]$/))
453
- return false;
454
- return /^[a-zA-Z0-9-]+$/.test(part);
455
- }
456
- function isValidHostname$1(hostname) {
457
- // Check hostname is a string
458
- if (typeof hostname !== "string")
459
- return false;
460
- // Convert hostname to lowercase
461
- const check = hostname.toString().toLowerCase();
462
- // Check hostname is less than 253 characters
463
- if (check.length > 253)
464
- return false;
465
- // Split on dots
466
- const parts = check.split(".");
467
- // Check each part is validPart
468
- const validParts = parts.map(validPart$1);
469
- // Confirm all parts are valid
470
- if (!validParts.every((part) => part))
471
- return false;
472
- // Confirm last part is at least 2 characters
473
- const lastPart = parts[parts.length - 1];
474
- if (lastPart.length < 2)
475
- return false;
476
- // Confirm last part is all letters
477
- if (!lastPart.match(/^[a-z]+$/))
478
- return false;
479
- // This is a valid hostname
480
- return true;
481
- }
482
-
483
- function validPart(part) {
484
- if (!part.match(/^[a-z]/))
485
- return false;
486
- if (!part.match(/[a-z0-9]$/))
487
- return false;
488
- return /^[a-zA-Z0-9-]+$/.test(part);
489
- }
490
- function isValidSubdomain(subdomain) {
491
- // Check subdomain is a string
492
- if (typeof subdomain !== "string")
493
- return false;
494
- // Special case for apex
495
- if (subdomain === CDK$2.HOST.APEX)
496
- return true;
497
- // Convert subdomain to lowercase
498
- const check = subdomain.toString().toLowerCase();
499
- // Check subdomain is less than 250 characters
500
- // We use 250 instead of 253 because we need to leave room for the dot top-level domain
501
- if (check.length > 250)
502
- return false;
503
- // Split on dots
504
- const parts = check.split(".");
505
- // Check each part is validPart
506
- const validParts = parts.map(validPart);
507
- // Confirm all parts are valid
508
- if (!validParts.every((part) => part))
509
- return false;
510
- // Do not care if last part is at least 2 characters
511
- // Do not care if last part is all letters
512
- // This is a valid subdomain
513
- return true;
514
- }
515
-
516
- function jaypieLambdaEnv(options = {}) {
517
- const { initialEnvironment = {} } = options;
518
- // Start with empty environment - we'll only add valid values
519
- let environment = {};
520
- // First, add all valid string values from initialEnvironment
521
- Object.entries(initialEnvironment).forEach(([key, value]) => {
522
- if (typeof value === "string") {
523
- environment[key] = value;
524
- }
525
- });
526
- // Default environment values
527
- const defaultEnvValues = {
528
- AWS_LAMBDA_NODEJS_DISABLE_CALLBACK_WARNING: "true",
529
- };
530
- // Apply default environment values with user overrides
531
- Object.entries(defaultEnvValues).forEach(([key, defaultValue]) => {
532
- if (key in initialEnvironment) {
533
- const userValue = initialEnvironment[key];
534
- // If user passes a string, it's already added above
535
- // If user passes non-string falsy value, omit the key
536
- if (!userValue) {
537
- delete environment[key];
538
- }
539
- // Ignore non-string truthy values (key not added)
540
- }
541
- else {
542
- // No user override, use default value
543
- environment[key] = defaultValue;
544
- }
545
- });
546
- // Default environment variables from process.env if present
547
- const defaultEnvVars = [
548
- "DATADOG_API_KEY_ARN",
549
- "LOG_LEVEL",
550
- "MODULE_LOGGER",
551
- "MODULE_LOG_LEVEL",
552
- "PROJECT_CHAOS",
553
- "PROJECT_COMMIT",
554
- "PROJECT_ENV",
555
- "PROJECT_KEY",
556
- "PROJECT_SECRET",
557
- "PROJECT_SERVICE",
558
- "PROJECT_SPONSOR",
559
- "PROJECT_VERSION",
560
- ];
561
- // Add default environment variables if they exist in process.env
562
- defaultEnvVars.forEach((envVar) => {
563
- if (process.env[envVar] && !environment[envVar]) {
564
- environment[envVar] = process.env[envVar];
565
- }
566
- });
567
- return environment;
568
- }
569
-
570
- function mergeDomain(subDomain, hostedZone) {
571
- if (!hostedZone) {
572
- throw new ConfigurationError("hostedZone is required");
573
- }
574
- if (!subDomain) {
575
- // Return hostedZone if subDomain is not passed
576
- // Pass CDK.HOST.APEX to explicitly indicate apex domain
577
- return hostedZone;
578
- }
579
- if (subDomain === CDK$2.HOST.APEX) {
580
- return hostedZone;
581
- }
582
- return `${subDomain}.${hostedZone}`;
583
- }
584
-
585
- const DEFAULT_FUNCTION_NAME$1 = "DatadogForwarderFunction";
586
- // Cache to store resolved functions
587
- // Using nested structure to support multiple functions per scope with automatic GC
588
- const functionCache = new WeakMap();
589
- function resolveDatadogForwarderFunction(scope, options) {
590
- const { import: importValue, name } = options || {};
591
- const functionName = name || DEFAULT_FUNCTION_NAME$1;
592
- const importKey = importValue || CDK$2.IMPORT.DATADOG_LOG_FORWARDER;
593
- // Create a cache key based on name and import
594
- const cacheKey = `${functionName}:${importKey}`;
595
- // Get or create scope cache
596
- let scopeCache = functionCache.get(scope);
597
- if (!scopeCache) {
598
- scopeCache = new Map();
599
- functionCache.set(scope, scopeCache);
600
- }
601
- // Return cached function if it exists
602
- const cachedFunction = scopeCache.get(cacheKey);
603
- if (cachedFunction) {
604
- return cachedFunction;
605
- }
606
- // Create and cache the function
607
- const func = lambda.Function.fromFunctionArn(scope, functionName, cdk.Fn.importValue(importKey));
608
- scopeCache.set(cacheKey, func);
609
- return func;
610
- }
611
-
612
- function resolveDatadogLayers(scope, options = {}) {
613
- const { datadogApiKeyArn, uniqueId } = options;
614
- let resolvedRegion = Stack.of(scope).region || "us-east-1";
615
- // Resolve the Datadog API key ARN from multiple sources
616
- const resolvedDatadogApiKeyArn = datadogApiKeyArn ||
617
- process.env.DATADOG_API_KEY_ARN ||
618
- process.env.CDK_ENV_DATADOG_API_KEY_ARN;
619
- // Return null if no API key is found
620
- if (!resolvedDatadogApiKeyArn) {
621
- return undefined;
622
- }
623
- const layerIdSuffix = uniqueId || process.env.PROJECT_NONCE || Date.now().toString();
624
- // Create Datadog Node.js layer
625
- const datadogNodeLayer = lambda.LayerVersion.fromLayerVersionArn(scope, `DatadogNodeLayer-${layerIdSuffix}`, `arn:aws:lambda:${resolvedRegion}:464622532012:layer:Datadog-Node20-x:${CDK$2.DATADOG.LAYER.NODE}`);
626
- // Create Datadog Extension layer
627
- const datadogExtensionLayer = lambda.LayerVersion.fromLayerVersionArn(scope, `DatadogExtensionLayer-${layerIdSuffix}`, `arn:aws:lambda:${resolvedRegion}:464622532012:layer:Datadog-Extension:${CDK$2.DATADOG.LAYER.EXTENSION}`);
628
- return [datadogNodeLayer, datadogExtensionLayer];
629
- }
630
-
631
- const DEFAULT_FUNCTION_NAME = "DatadogForwarderFunction";
632
- // Cache to store resolved logging destinations
633
- // Using nested structure to support multiple destinations per scope with automatic GC
634
- const destinationCache = new WeakMap();
635
- function resolveDatadogLoggingDestination(scope, options) {
636
- const { import: importValue, name } = options || {};
637
- // Create a cache key based on name and import (same as forwarder function)
638
- const functionName = name || DEFAULT_FUNCTION_NAME;
639
- const importKey = importValue || CDK$2.IMPORT.DATADOG_LOG_FORWARDER;
640
- const cacheKey = `${functionName}:${importKey}`;
641
- // Get or create scope cache
642
- let scopeCache = destinationCache.get(scope);
643
- if (!scopeCache) {
644
- scopeCache = new Map();
645
- destinationCache.set(scope, scopeCache);
646
- }
647
- // Return cached destination if it exists
648
- const cachedDestination = scopeCache.get(cacheKey);
649
- if (cachedDestination) {
650
- return cachedDestination;
651
- }
652
- // Resolve the Datadog forwarder function
653
- const datadogForwarderFunction = resolveDatadogForwarderFunction(scope, options);
654
- // Create and cache the logging destination
655
- const datadogLoggingDestination = new logDestinations.LambdaDestination(datadogForwarderFunction);
656
- scopeCache.set(cacheKey, datadogLoggingDestination);
657
- return datadogLoggingDestination;
658
- }
659
-
660
- function resolveHostedZone(scope, { name = "HostedZone", zone = process.env.CDK_ENV_HOSTED_ZONE, } = {}) {
661
- if (!zone) {
662
- throw new ConfigurationError("No `zone` provided. Set CDK_ENV_HOSTED_ZONE to use environment zone");
663
- }
664
- if (typeof zone === "string") {
665
- return route53.HostedZone.fromLookup(scope, name, {
666
- domainName: zone,
667
- });
668
- }
669
- return zone;
670
- }
671
-
672
- const resolveParamsAndSecrets = ({ paramsAndSecrets, options, } = {}) => {
673
- if (paramsAndSecrets === false) {
674
- return;
675
- }
676
- let resolvedParamsAndSecrets;
677
- if (paramsAndSecrets instanceof lambda.ParamsAndSecretsLayerVersion) {
678
- resolvedParamsAndSecrets = paramsAndSecrets;
679
- }
680
- else {
681
- const resolvedOptions = options || {};
682
- resolvedParamsAndSecrets = lambda.ParamsAndSecretsLayerVersion.fromVersion(lambda.ParamsAndSecretsVersions.V1_0_103, {
683
- cacheSize: resolvedOptions.cacheSize,
684
- logLevel: resolvedOptions.logLevel || lambda.ParamsAndSecretsLogLevel.WARN,
685
- parameterStoreTtl: resolvedOptions.parameterStoreTtl,
686
- secretsManagerTtl: resolvedOptions.secretsManagerTtl,
687
- });
688
- }
689
- return resolvedParamsAndSecrets;
690
- };
691
-
692
- class JaypieApiGateway extends Construct {
693
- constructor(scope, id, props) {
694
- super(scope, id);
695
- const { certificate = true, handler, host: propsHost, name, roleTag = CDK$2.ROLE.API, zone: propsZone, } = props;
696
- // Determine zone from props or environment
697
- let zone = propsZone;
698
- if (!zone && process.env.CDK_ENV_API_HOSTED_ZONE) {
699
- zone = process.env.CDK_ENV_API_HOSTED_ZONE;
700
- }
701
- // Determine host from props or environment
702
- let host = propsHost;
703
- if (!host) {
704
- if (process.env.CDK_ENV_API_HOST_NAME) {
705
- host = process.env.CDK_ENV_API_HOST_NAME;
706
- }
707
- else if (process.env.CDK_ENV_API_SUBDOMAIN &&
708
- process.env.CDK_ENV_API_HOSTED_ZONE) {
709
- host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE);
710
- }
711
- }
712
- const apiGatewayName = name || constructEnvName("ApiGateway");
713
- const certificateName = constructEnvName("Certificate");
714
- const apiDomainName = constructEnvName("ApiDomainName");
715
- let hostedZone;
716
- let certificateToUse;
717
- if (host && zone) {
718
- hostedZone = resolveHostedZone(this, { zone });
719
- if (certificate === true) {
720
- certificateToUse = new acm.Certificate(this, certificateName, {
721
- domainName: host,
722
- validation: acm.CertificateValidation.fromDns(hostedZone),
723
- });
724
- Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, CDK$2.ROLE.HOSTING);
725
- }
726
- else if (typeof certificate === "object") {
727
- certificateToUse = certificate;
728
- }
729
- this._certificate = certificateToUse;
730
- this._host = host;
731
- }
732
- const {
733
- // * `...lambdaRestApiProps` cannot be moved to the first const destructuring because it needs to exclude the custom properties first.
734
- // Ignore the variables we already assigned to other properties
735
- /* eslint-disable @typescript-eslint/no-unused-vars */
736
- certificate: _certificate, host: _host, name: _name, roleTag: _roleTag, zone: _zone, handler: _handler,
737
- /* eslint-enable @typescript-eslint/no-unused-vars */
738
- ...lambdaRestApiProps } = props;
739
- this._api = new apiGateway.LambdaRestApi(this, apiGatewayName, {
740
- handler,
741
- ...lambdaRestApiProps,
742
- });
743
- Tags.of(this._api).add(CDK$2.TAG.ROLE, roleTag);
744
- if (host && certificateToUse && hostedZone) {
745
- this._domainName = this._api.addDomainName(apiDomainName, {
746
- domainName: host,
747
- certificate: certificateToUse,
748
- });
749
- Tags.of(this._domainName).add(CDK$2.TAG.ROLE, roleTag);
750
- const record = new route53.ARecord(this, "AliasRecord", {
751
- recordName: host,
752
- target: route53.RecordTarget.fromAlias(new route53Targets.ApiGatewayDomain(this._domainName)),
753
- zone: hostedZone,
754
- });
755
- Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
756
- }
757
- }
758
- get api() {
759
- return this._api;
760
- }
761
- get url() {
762
- return this._api.url;
763
- }
764
- get certificateArn() {
765
- return this._certificate?.certificateArn;
766
- }
767
- get domainName() {
768
- return this._domainName?.domainName;
769
- }
770
- get host() {
771
- return this._host;
772
- }
773
- get restApiId() {
774
- return this._api.restApiId;
775
- }
776
- get restApiName() {
777
- return this._api.restApiName;
778
- }
779
- get restApiRootResourceId() {
780
- return this._api.restApiRootResourceId;
781
- }
782
- get deploymentStage() {
783
- return this._api.deploymentStage;
784
- }
785
- get domainNameAliasDomainName() {
786
- return this._domainName?.domainNameAliasDomainName;
787
- }
788
- get domainNameAliasHostedZoneId() {
789
- return this._domainName?.domainNameAliasHostedZoneId;
790
- }
791
- get root() {
792
- return this._api.root;
793
- }
794
- get env() {
795
- return {
796
- account: Stack.of(this).account,
797
- region: Stack.of(this).region,
798
- };
799
- }
800
- get stack() {
801
- return this._api.stack;
802
- }
803
- arnForExecuteApi(method, path, stage) {
804
- return this._api.arnForExecuteApi(method, path, stage);
805
- }
806
- metric(metricName, props) {
807
- return this._api.metric(metricName, props);
808
- }
809
- metricCacheHitCount(props) {
810
- return this._api.metricCacheHitCount(props);
811
- }
812
- metricCacheMissCount(props) {
813
- return this._api.metricCacheMissCount(props);
814
- }
815
- metricClientError(props) {
816
- return this._api.metricClientError(props);
817
- }
818
- metricCount(props) {
819
- return this._api.metricCount(props);
820
- }
821
- metricIntegrationLatency(props) {
822
- return this._api.metricIntegrationLatency(props);
823
- }
824
- metricLatency(props) {
825
- return this._api.metricLatency(props);
826
- }
827
- metricServerError(props) {
828
- return this._api.metricServerError(props);
829
- }
830
- applyRemovalPolicy(policy) {
831
- this._api.applyRemovalPolicy(policy);
832
- }
833
- get restApiRef() {
834
- return {
835
- restApiId: this._api.restApiId,
836
- };
837
- }
838
- }
839
-
840
- class JaypieStack extends Stack {
841
- constructor(scope, id, props = {}) {
842
- const { key, ...stackProps } = props;
843
- // Handle stackName
844
- if (!stackProps.stackName) {
845
- stackProps.stackName = constructStackName(key);
846
- }
847
- // Handle env
848
- stackProps.env = {
849
- account: process.env.CDK_DEFAULT_ACCOUNT,
850
- region: process.env.CDK_DEFAULT_REGION,
851
- ...stackProps.env,
852
- };
853
- super(scope, id, stackProps);
854
- // Apply tags
855
- constructTagger(this, { name: stackProps.stackName });
856
- }
857
- }
858
-
859
- class JaypieAppStack extends JaypieStack {
860
- constructor(scope, id, props = {}) {
861
- const { key = "app", ...stackProps } = props;
862
- // Handle stackName
863
- if (!stackProps.stackName) {
864
- stackProps.stackName = constructStackName(key);
865
- }
866
- super(scope, id, { key, ...stackProps });
867
- }
868
- }
869
-
870
- class JaypieLambda extends Construct {
871
- constructor(scope, id, props) {
872
- super(scope, id);
873
- const { allowAllOutbound, allowPublicSubnet, architecture = lambda.Architecture.X86_64, code, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, environment: initialEnvironment = {}, envSecrets = {}, ephemeralStorageSize, filesystem, handler = "index.handler", initialPolicy, layers = [], logGroup, logRetention = CDK$2.LAMBDA.LOG_RETENTION, maxEventAge, memorySize = CDK$2.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, profiling, profilingGroup, provisionedConcurrentExecutions, reservedConcurrentExecutions, retryAttempts, roleTag = CDK$2.ROLE.PROCESSING, runtime = lambda.Runtime.NODEJS_22_X, runtimeManagementMode, secrets = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
874
- // Get base environment with defaults
875
- const environment = jaypieLambdaEnv({ initialEnvironment });
876
- const codeAsset = typeof code === "string" ? lambda.Code.fromAsset(code) : code;
877
- // Create a working copy of layers
878
- const resolvedLayers = [...layers];
879
- // Process secrets environment variables
880
- const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
881
- ...acc,
882
- [`SECRET_${key}`]: secret.secretName,
883
- }), {});
884
- // Process JaypieEnvSecret array
885
- const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
886
- if (secret.envKey) {
887
- return {
888
- ...acc,
889
- [`SECRET_${secret.envKey}`]: secret.secretName,
890
- };
891
- }
892
- return acc;
893
- }, {});
894
- // Add ParamsAndSecrets layer if configured
895
- const resolvedParamsAndSecrets = resolveParamsAndSecrets({
896
- paramsAndSecrets,
897
- options: paramsAndSecretsOptions,
898
- });
899
- // Create LogGroup if not provided
900
- const resolvedLogGroup = logGroup ??
901
- new logs.LogGroup(this, "LogGroup", {
902
- retention: logRetention,
903
- removalPolicy: RemovalPolicy.DESTROY,
904
- });
905
- // Create Lambda Function
906
- this._lambda = new lambda.Function(this, "Function", {
907
- allowAllOutbound,
908
- allowPublicSubnet,
909
- architecture,
910
- code: codeAsset,
911
- deadLetterQueue,
912
- deadLetterQueueEnabled,
913
- deadLetterTopic,
914
- description,
915
- environment: {
916
- ...environment,
917
- ...secretsEnvironment,
918
- ...jaypieSecretsEnvironment,
919
- },
920
- ephemeralStorageSize,
921
- filesystem,
922
- handler,
923
- initialPolicy,
924
- layers: resolvedLayers,
925
- logGroup: resolvedLogGroup,
926
- maxEventAge,
927
- memorySize,
928
- paramsAndSecrets: resolvedParamsAndSecrets,
929
- profiling,
930
- profilingGroup,
931
- reservedConcurrentExecutions,
932
- retryAttempts,
933
- runtime,
934
- runtimeManagementMode,
935
- securityGroups,
936
- timeout: typeof timeout === "number" ? Duration.seconds(timeout) : timeout,
937
- tracing,
938
- vpc,
939
- vpcSubnets,
940
- // Enable auto-publishing of versions when using provisioned concurrency
941
- currentVersionOptions: provisionedConcurrentExecutions !== undefined
942
- ? {
943
- removalPolicy: RemovalPolicy.RETAIN,
944
- description: "Auto-published version for provisioned concurrency",
945
- // Don't set provisioned concurrency here - it will be set on the alias
946
- }
947
- : undefined,
948
- });
949
- addDatadogLayers(this._lambda, { datadogApiKeyArn });
950
- // Grant secret read permissions
951
- Object.values(envSecrets).forEach((secret) => {
952
- secret.grantRead(this._lambda);
953
- });
954
- // Grant read permissions for JaypieEnvSecrets
955
- secrets.forEach((secret) => {
956
- secret.grantRead(this._lambda);
957
- });
958
- // Configure provisioned concurrency if specified
959
- if (provisionedConcurrentExecutions !== undefined) {
960
- // Use currentVersion which is auto-published with proper configuration
961
- const version = this._lambda.currentVersion;
962
- // Create alias for provisioned concurrency
963
- this._provisioned = new lambda.Alias(this, "ProvisionedAlias", {
964
- aliasName: "provisioned",
965
- version,
966
- provisionedConcurrentExecutions,
967
- });
968
- // Add explicit dependencies to ensure proper creation order
969
- this._provisioned.node.addDependency(version);
970
- }
971
- if (roleTag) {
972
- Tags.of(this._lambda).add(CDK$2.TAG.ROLE, roleTag);
973
- }
974
- if (vendorTag) {
975
- Tags.of(this._lambda).add(CDK$2.TAG.VENDOR, vendorTag);
976
- }
977
- // Assign _reference based on provisioned state
978
- this._reference =
979
- this._provisioned !== undefined ? this._provisioned : this._lambda;
980
- }
981
- // Public accessors
982
- get lambda() {
983
- return this._lambda;
984
- }
985
- get provisioned() {
986
- return this._provisioned;
987
- }
988
- get reference() {
989
- return this._reference;
990
- }
991
- // IFunction implementation
992
- get functionArn() {
993
- return this._reference.functionArn;
994
- }
995
- get functionName() {
996
- return this._reference.functionName;
997
- }
998
- get grantPrincipal() {
999
- return this._reference.grantPrincipal;
1000
- }
1001
- get role() {
1002
- return this._reference.role;
1003
- }
1004
- get architecture() {
1005
- return this._reference.architecture;
1006
- }
1007
- get connections() {
1008
- return this._reference.connections;
1009
- }
1010
- get isBoundToVpc() {
1011
- return this._reference.isBoundToVpc;
1012
- }
1013
- get latestVersion() {
1014
- return this._reference.latestVersion;
1015
- }
1016
- get permissionsNode() {
1017
- return this._reference.permissionsNode;
1018
- }
1019
- get resourceArnsForGrantInvoke() {
1020
- return this._reference.resourceArnsForGrantInvoke;
1021
- }
1022
- get functionRef() {
1023
- return {
1024
- functionArn: this._reference.functionArn,
1025
- functionName: this._reference.functionName,
1026
- };
1027
- }
1028
- addEventSource(source) {
1029
- this._reference.addEventSource(source);
1030
- }
1031
- addEventSourceMapping(id, options) {
1032
- return this._reference.addEventSourceMapping(id, options);
1033
- }
1034
- addFunctionUrl(options) {
1035
- return this._reference.addFunctionUrl(options);
1036
- }
1037
- addPermission(id, permission) {
1038
- this._reference.addPermission(id, permission);
1039
- }
1040
- addToRolePolicy(statement) {
1041
- this._reference.addToRolePolicy(statement);
1042
- }
1043
- configureAsyncInvoke(options) {
1044
- this._reference.configureAsyncInvoke(options);
1045
- }
1046
- grantInvoke(grantee) {
1047
- return this._reference.grantInvoke(grantee);
1048
- }
1049
- grantInvokeCompositePrincipal(compositePrincipal) {
1050
- return this._reference.grantInvokeCompositePrincipal(compositePrincipal);
1051
- }
1052
- grantInvokeUrl(grantee) {
1053
- return this._reference.grantInvokeUrl(grantee);
1054
- }
1055
- grantInvokeLatestVersion(grantee) {
1056
- return this._reference.grantInvokeLatestVersion(grantee);
1057
- }
1058
- grantInvokeVersion(grantee, version) {
1059
- return this._reference.grantInvokeVersion(grantee, version);
1060
- }
1061
- metric(metricName, props) {
1062
- return this._reference.metric(metricName, props);
1063
- }
1064
- metricDuration(props) {
1065
- return this._reference.metricDuration(props);
1066
- }
1067
- metricErrors(props) {
1068
- return this._reference.metricErrors(props);
1069
- }
1070
- metricInvocations(props) {
1071
- return this._reference.metricInvocations(props);
1072
- }
1073
- metricThrottles(props) {
1074
- return this._reference.metricThrottles(props);
1075
- }
1076
- get env() {
1077
- return {
1078
- account: Stack.of(this).account,
1079
- region: Stack.of(this).region,
1080
- };
1081
- }
1082
- get stack() {
1083
- return this._reference.stack;
1084
- }
1085
- applyRemovalPolicy(policy) {
1086
- this._reference.applyRemovalPolicy(policy);
1087
- }
1088
- addEnvironment(key, value) {
1089
- this._lambda.addEnvironment(key, value);
1090
- }
1091
- }
1092
-
1093
- class JaypieQueuedLambda extends Construct {
1094
- constructor(scope, id, props) {
1095
- super(scope, id);
1096
- const { allowAllOutbound, allowPublicSubnet, architecture, batchSize = 1, code, datadogApiKeyArn, deadLetterQueue, deadLetterQueueEnabled, deadLetterTopic, description, environment = {}, envSecrets = {}, ephemeralStorageSize, fifo = true, filesystem, handler = "index.handler", initialPolicy, layers = [], logGroup, logRetention = CDK$2.LAMBDA.LOG_RETENTION, maxEventAge, memorySize = CDK$2.LAMBDA.MEMORY_SIZE, paramsAndSecrets, paramsAndSecretsOptions, profiling, profilingGroup, provisionedConcurrentExecutions, reservedConcurrentExecutions, retryAttempts, roleTag, runtime = lambda.Runtime.NODEJS_22_X, runtimeManagementMode, secrets = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, visibilityTimeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), vpc, vpcSubnets, } = props;
1097
- // Create SQS Queue
1098
- this._queue = new sqs.Queue(this, "Queue", {
1099
- fifo,
1100
- visibilityTimeout: typeof visibilityTimeout === "number"
1101
- ? Duration.seconds(visibilityTimeout)
1102
- : visibilityTimeout,
1103
- });
1104
- if (roleTag) {
1105
- Tags.of(this._queue).add(CDK$2.TAG.ROLE, roleTag);
1106
- }
1107
- if (vendorTag) {
1108
- Tags.of(this._queue).add(CDK$2.TAG.VENDOR, vendorTag);
1109
- }
1110
- // Create Lambda with JaypieLambda
1111
- this._lambdaConstruct = new JaypieLambda(this, "Function", {
1112
- allowAllOutbound,
1113
- allowPublicSubnet,
1114
- architecture,
1115
- code,
1116
- datadogApiKeyArn,
1117
- deadLetterQueue,
1118
- deadLetterQueueEnabled,
1119
- deadLetterTopic,
1120
- description,
1121
- environment: {
1122
- ...environment,
1123
- CDK_ENV_QUEUE_URL: this._queue.queueUrl,
1124
- },
1125
- envSecrets,
1126
- ephemeralStorageSize,
1127
- filesystem,
1128
- handler,
1129
- initialPolicy,
1130
- layers,
1131
- logGroup,
1132
- logRetention,
1133
- maxEventAge,
1134
- memorySize,
1135
- paramsAndSecrets,
1136
- paramsAndSecretsOptions,
1137
- profiling,
1138
- profilingGroup,
1139
- provisionedConcurrentExecutions,
1140
- reservedConcurrentExecutions,
1141
- retryAttempts,
1142
- roleTag,
1143
- runtime,
1144
- runtimeManagementMode,
1145
- secrets,
1146
- securityGroups,
1147
- timeout,
1148
- tracing,
1149
- vendorTag,
1150
- vpc,
1151
- vpcSubnets,
1152
- });
1153
- // Set up queue and lambda integration
1154
- this._queue.grantConsumeMessages(this._lambdaConstruct);
1155
- this._queue.grantSendMessages(this._lambdaConstruct);
1156
- this._lambdaConstruct.addEventSource(new lambdaEventSources.SqsEventSource(this._queue, {
1157
- batchSize,
1158
- }));
1159
- }
1160
- // Public accessors
1161
- get queue() {
1162
- return this._queue;
1163
- }
1164
- get lambda() {
1165
- return this._lambdaConstruct.lambda;
1166
- }
1167
- // IFunction implementation
1168
- get functionArn() {
1169
- return this._lambdaConstruct.functionArn;
1170
- }
1171
- get functionName() {
1172
- return this._lambdaConstruct.functionName;
1173
- }
1174
- get grantPrincipal() {
1175
- return this._lambdaConstruct.grantPrincipal;
1176
- }
1177
- get role() {
1178
- return this._lambdaConstruct.role;
1179
- }
1180
- get architecture() {
1181
- return this._lambdaConstruct.architecture;
1182
- }
1183
- get connections() {
1184
- return this._lambdaConstruct.connections;
1185
- }
1186
- get isBoundToVpc() {
1187
- return this._lambdaConstruct.isBoundToVpc;
1188
- }
1189
- get latestVersion() {
1190
- return this._lambdaConstruct.latestVersion;
1191
- }
1192
- get permissionsNode() {
1193
- return this._lambdaConstruct.permissionsNode;
1194
- }
1195
- get resourceArnsForGrantInvoke() {
1196
- return this._lambdaConstruct.resourceArnsForGrantInvoke;
1197
- }
1198
- get functionRef() {
1199
- return this._lambdaConstruct.functionRef;
1200
- }
1201
- addEventSource(source) {
1202
- this._lambdaConstruct.addEventSource(source);
1203
- }
1204
- addEventSourceMapping(id, options) {
1205
- return this._lambdaConstruct.addEventSourceMapping(id, options);
1206
- }
1207
- addFunctionUrl(options) {
1208
- return this._lambdaConstruct.addFunctionUrl(options);
1209
- }
1210
- addPermission(id, permission) {
1211
- this._lambdaConstruct.addPermission(id, permission);
1212
- }
1213
- addToRolePolicy(statement) {
1214
- this._lambdaConstruct.addToRolePolicy(statement);
1215
- }
1216
- configureAsyncInvoke(options) {
1217
- this._lambdaConstruct.configureAsyncInvoke(options);
1218
- }
1219
- grantInvoke(grantee) {
1220
- return this._lambdaConstruct.grantInvoke(grantee);
1221
- }
1222
- grantInvokeCompositePrincipal(compositePrincipal) {
1223
- return this._lambdaConstruct.grantInvokeCompositePrincipal(compositePrincipal);
1224
- }
1225
- grantInvokeUrl(grantee) {
1226
- return this._lambdaConstruct.grantInvokeUrl(grantee);
1227
- }
1228
- metric(metricName, props) {
1229
- return this._lambdaConstruct.metric(metricName, props);
1230
- }
1231
- metricDuration(props) {
1232
- return this._lambdaConstruct.metricDuration(props);
1233
- }
1234
- metricErrors(props) {
1235
- return this._lambdaConstruct.metricErrors(props);
1236
- }
1237
- metricInvocations(props) {
1238
- return this._lambdaConstruct.metricInvocations(props);
1239
- }
1240
- metricThrottles(props) {
1241
- return this._lambdaConstruct.metricThrottles(props);
1242
- }
1243
- // Additional IFunction implementation
1244
- grantInvokeLatestVersion(grantee) {
1245
- return this._lambdaConstruct.grantInvokeLatestVersion(grantee);
1246
- }
1247
- grantInvokeVersion(grantee, version) {
1248
- return this._lambdaConstruct.grantInvokeVersion(grantee, version);
1249
- }
1250
- get env() {
1251
- return {
1252
- account: Stack.of(this).account,
1253
- region: Stack.of(this).region,
1254
- };
1255
- }
1256
- get stack() {
1257
- return Stack.of(this);
1258
- }
1259
- applyRemovalPolicy(policy) {
1260
- this._lambdaConstruct.applyRemovalPolicy(policy);
1261
- this._queue.applyRemovalPolicy(policy);
1262
- }
1263
- // IQueue implementation
1264
- get fifo() {
1265
- return this._queue.fifo;
1266
- }
1267
- get queueArn() {
1268
- return this._queue.queueArn;
1269
- }
1270
- get queueName() {
1271
- return this._queue.queueName;
1272
- }
1273
- get queueUrl() {
1274
- return this._queue.queueUrl;
1275
- }
1276
- get encryptionMasterKey() {
1277
- return this._queue.encryptionMasterKey;
1278
- }
1279
- addToResourcePolicy(statement) {
1280
- return this._queue.addToResourcePolicy(statement);
1281
- }
1282
- grant(grantee, ...actions) {
1283
- return this._queue.grant(grantee, ...actions);
1284
- }
1285
- grantConsumeMessages(grantee) {
1286
- return this._queue.grantConsumeMessages(grantee);
1287
- }
1288
- grantPurge(grantee) {
1289
- return this._queue.grantPurge(grantee);
1290
- }
1291
- grantSendMessages(grantee) {
1292
- return this._queue.grantSendMessages(grantee);
1293
- }
1294
- // Queue metrics
1295
- metricApproximateAgeOfOldestMessage(props) {
1296
- return this._queue.metricApproximateAgeOfOldestMessage(props);
1297
- }
1298
- metricApproximateNumberOfMessagesDelayed(props) {
1299
- return this._queue.metricApproximateNumberOfMessagesDelayed(props);
1300
- }
1301
- metricApproximateNumberOfMessagesNotVisible(props) {
1302
- return this._queue.metricApproximateNumberOfMessagesNotVisible(props);
1303
- }
1304
- metricApproximateNumberOfMessagesVisible(props) {
1305
- return this._queue.metricApproximateNumberOfMessagesVisible(props);
1306
- }
1307
- metricNumberOfEmptyReceives(props) {
1308
- return this._queue.metricNumberOfEmptyReceives(props);
1309
- }
1310
- metricNumberOfMessagesDeleted(props) {
1311
- return this._queue.metricNumberOfMessagesDeleted(props);
1312
- }
1313
- metricNumberOfMessagesReceived(props) {
1314
- return this._queue.metricNumberOfMessagesReceived(props);
1315
- }
1316
- metricNumberOfMessagesSent(props) {
1317
- return this._queue.metricNumberOfMessagesSent(props);
1318
- }
1319
- metricSentMessageSize(props) {
1320
- return this._queue.metricSentMessageSize(props);
1321
- }
1322
- addEnvironment(key, value) {
1323
- this._lambdaConstruct.addEnvironment(key, value);
1324
- }
1325
- }
1326
-
1327
- class JaypieBucketQueuedLambda extends JaypieQueuedLambda {
1328
- constructor(scope, id, props) {
1329
- props.fifo = false; // S3 event notifications are not supported for FIFO queues
1330
- super(scope, id, props);
1331
- const { bucketName, roleTag, vendorTag, bucketOptions = {} } = props;
1332
- // Create S3 Bucket
1333
- this._bucket = new s3.Bucket(this, "Bucket", {
1334
- bucketName: bucketOptions.bucketName || bucketName,
1335
- removalPolicy: bucketOptions.removalPolicy || RemovalPolicy.RETAIN,
1336
- ...bucketOptions,
1337
- });
1338
- // Add tags to bucket
1339
- if (roleTag) {
1340
- Tags.of(this._bucket).add(CDK$2.TAG.ROLE, roleTag);
1341
- }
1342
- if (vendorTag) {
1343
- Tags.of(this._bucket).add(CDK$2.TAG.VENDOR, vendorTag);
1344
- }
1345
- // Add an event notification from the bucket to the queue
1346
- this._bucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3n.SqsDestination(this.queue));
1347
- // Grant the lambda access to the bucket
1348
- this._bucket.grantReadWrite(this);
1349
- // Add environment variable for bucket name
1350
- this.lambda.addEnvironment("CDK_ENV_BUCKET_NAME", this._bucket.bucketName);
1351
- }
1352
- // Public accessors
1353
- get bucket() {
1354
- return this._bucket;
1355
- }
1356
- // IBucket implementation
1357
- get bucketArn() {
1358
- return this._bucket.bucketArn;
1359
- }
1360
- get bucketDomainName() {
1361
- return this._bucket.bucketDomainName;
1362
- }
1363
- get bucketDualStackDomainName() {
1364
- return this._bucket.bucketDualStackDomainName;
1365
- }
1366
- get bucketName() {
1367
- return this._bucket.bucketName;
1368
- }
1369
- get bucketRegionalDomainName() {
1370
- return this._bucket.bucketRegionalDomainName;
1371
- }
1372
- get bucketWebsiteDomainName() {
1373
- return this._bucket.bucketWebsiteDomainName;
1374
- }
1375
- get bucketWebsiteUrl() {
1376
- return this._bucket.bucketWebsiteUrl;
1377
- }
1378
- get encryptionKey() {
1379
- return this._bucket.encryptionKey;
1380
- }
1381
- get isWebsite() {
1382
- return this._bucket.isWebsite || false;
1383
- }
1384
- get policy() {
1385
- return this._bucket.policy;
1386
- }
1387
- addEventNotification(event, dest, ...filters) {
1388
- this._bucket.addEventNotification(event, dest, ...filters);
1389
- }
1390
- addObjectCreatedNotification(dest, ...filters) {
1391
- this._bucket.addObjectCreatedNotification(dest, ...filters);
1392
- }
1393
- addObjectRemovedNotification(dest, ...filters) {
1394
- this._bucket.addObjectRemovedNotification(dest, ...filters);
1395
- }
1396
- addToResourcePolicy(permission) {
1397
- return this._bucket.addToResourcePolicy(permission);
1398
- }
1399
- arnForObjects(objectKeyPattern) {
1400
- return this._bucket.arnForObjects(objectKeyPattern);
1401
- }
1402
- enableEventBridgeNotification() {
1403
- this._bucket.enableEventBridgeNotification();
1404
- }
1405
- grantDelete(grantee, objectsKeyPattern) {
1406
- return this._bucket.grantDelete(grantee, objectsKeyPattern);
1407
- }
1408
- grantPublicAccess(keyPrefix, ...allowedActions) {
1409
- return this._bucket.grantPublicAccess(keyPrefix, ...allowedActions);
1410
- }
1411
- grantPut(grantee, objectsKeyPattern) {
1412
- return this._bucket.grantPut(grantee, objectsKeyPattern);
1413
- }
1414
- grantPutAcl(grantee, objectsKeyPattern) {
1415
- return this._bucket.grantPutAcl(grantee, objectsKeyPattern);
1416
- }
1417
- grantRead(grantee, objectsKeyPattern) {
1418
- return this._bucket.grantRead(grantee, objectsKeyPattern);
1419
- }
1420
- grantReadWrite(grantee, objectsKeyPattern) {
1421
- return this._bucket.grantReadWrite(grantee, objectsKeyPattern);
1422
- }
1423
- grantWrite(grantee, objectsKeyPattern) {
1424
- return this._bucket.grantWrite(grantee, objectsKeyPattern);
1425
- }
1426
- onCloudTrailEvent(id, options) {
1427
- return this._bucket.onCloudTrailEvent(id, options);
1428
- }
1429
- onCloudTrailPutObject(id, options) {
1430
- return this._bucket.onCloudTrailPutObject(id, options);
1431
- }
1432
- onCloudTrailWriteObject(id, options) {
1433
- return this._bucket.onCloudTrailWriteObject(id, options);
1434
- }
1435
- s3UrlForObject(key) {
1436
- return this._bucket.s3UrlForObject(key);
1437
- }
1438
- transferAccelerationUrlForObject(key, options) {
1439
- return this._bucket.transferAccelerationUrlForObject(key, options);
1440
- }
1441
- urlForObject(key) {
1442
- return this._bucket.urlForObject(key);
1443
- }
1444
- virtualHostedUrlForObject(key, options) {
1445
- return this._bucket.virtualHostedUrlForObject(key, options);
1446
- }
1447
- grantReplicationPermission(identity, props) {
1448
- return this._bucket.grantReplicationPermission(identity, props);
1449
- }
1450
- addReplicationPolicy(policy) {
1451
- this._bucket.addReplicationPolicy(policy);
1452
- }
1453
- get bucketRef() {
1454
- return {
1455
- bucketArn: this._bucket.bucketArn,
1456
- bucketName: this._bucket.bucketName,
1457
- };
1458
- }
1459
- // Override applyRemovalPolicy to apply to all resources
1460
- applyRemovalPolicy(policy) {
1461
- super.applyRemovalPolicy(policy);
1462
- this._bucket.applyRemovalPolicy(policy);
1463
- }
1464
- }
1465
-
1466
- class JaypieDatadogBucket extends Construct {
1467
- /**
1468
- * Create a new S3 bucket for Datadog log archiving with automatic IAM permissions
1469
- */
1470
- constructor(scope, idOrProps, propsOrUndefined) {
1471
- // Handle overloaded constructor signatures
1472
- let props;
1473
- let id;
1474
- if (typeof idOrProps === "string") {
1475
- // First param is ID, second is props
1476
- props = propsOrUndefined || {};
1477
- id = idOrProps;
1478
- }
1479
- else {
1480
- // First param is props
1481
- props = idOrProps || {};
1482
- id = props.id || "JaypieDatadogBucket";
1483
- }
1484
- super(scope, id);
1485
- // Extract Jaypie-specific options
1486
- const { bucketId = "DatadogArchiveBucket", bucketScope, grantDatadogAccess = true, project, service = CDK$2.SERVICE.DATADOG, ...bucketProps } = props;
1487
- // Create the bucket using bucketScope (defaults to this) and bucketId
1488
- const effectiveBucketScope = bucketScope || this;
1489
- this.bucket = new Bucket(effectiveBucketScope, bucketId, bucketProps);
1490
- // Add tags to bucket
1491
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.SERVICE, service);
1492
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1493
- if (project) {
1494
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.PROJECT, project);
1495
- }
1496
- // Grant Datadog role access to bucket if enabled
1497
- if (grantDatadogAccess) {
1498
- this.policy = this.grantDatadogRoleBucketAccess({ project, service });
1499
- }
1500
- }
1501
- /**
1502
- * Grants the Datadog IAM role access to this bucket
1503
- *
1504
- * Checks for CDK_ENV_DATADOG_ROLE_ARN environment variable.
1505
- * If found, creates a custom policy with:
1506
- * - s3:ListBucket on bucket
1507
- * - s3:GetObject and s3:PutObject on bucket/*
1508
- *
1509
- * @param options - Configuration options
1510
- * @returns The created Policy, or undefined if CDK_ENV_DATADOG_ROLE_ARN is not set
1511
- */
1512
- grantDatadogRoleBucketAccess(options) {
1513
- const datadogRoleArn = process.env.CDK_ENV_DATADOG_ROLE_ARN;
1514
- // Early return if no Datadog role ARN is configured
1515
- if (!datadogRoleArn) {
1516
- return undefined;
1517
- }
1518
- const { project, service = CDK$2.SERVICE.DATADOG } = options || {};
1519
- // Lookup the Datadog role
1520
- const datadogRole = Role.fromRoleArn(this, "DatadogRole", datadogRoleArn);
1521
- // Build policy statements for bucket access
1522
- const statements = [
1523
- // Allow list bucket
1524
- new PolicyStatement({
1525
- actions: ["s3:ListBucket"],
1526
- resources: [this.bucket.bucketArn],
1527
- }),
1528
- // Allow read and write to the bucket
1529
- new PolicyStatement({
1530
- actions: ["s3:GetObject", "s3:PutObject"],
1531
- resources: [`${this.bucket.bucketArn}/*`],
1532
- }),
1533
- ];
1534
- // Create the custom policy
1535
- const datadogBucketPolicy = new Policy(this, "DatadogBucketPolicy", {
1536
- roles: [datadogRole],
1537
- statements,
1538
- });
1539
- // Add tags
1540
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.SERVICE, service);
1541
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1542
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.VENDOR, CDK$2.VENDOR.DATADOG);
1543
- if (project) {
1544
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.PROJECT, project);
1545
- }
1546
- return datadogBucketPolicy;
1547
- }
1548
- }
1549
-
1550
- const DATADOG_FORWARDER_TEMPLATE_URL = "https://datadog-cloudformation-template.s3.amazonaws.com/aws/forwarder/latest.yaml";
1551
- const DEFAULT_RESERVED_CONCURRENCY = "10";
1552
- class JaypieDatadogForwarder extends Construct {
1553
- /**
1554
- * Create a new Datadog forwarder with CloudFormation nested stack
1555
- */
1556
- constructor(scope, idOrProps, propsOrUndefined) {
1557
- // Handle overloaded constructor signatures
1558
- let props;
1559
- let id;
1560
- if (typeof idOrProps === "string") {
1561
- // First param is ID, second is props
1562
- props = propsOrUndefined || {};
1563
- id = idOrProps;
1564
- }
1565
- else {
1566
- // First param is props
1567
- props = idOrProps || {};
1568
- id = props.id || "DatadogForwarder";
1569
- }
1570
- super(scope, id);
1571
- // Resolve options with defaults
1572
- const { account = process.env.CDK_ENV_ACCOUNT, additionalTags, createOutput = true, datadogApiKey = process.env.CDK_ENV_DATADOG_API_KEY, enableCloudFormationEvents = true, enableRoleExtension = true, exportName = CDK$2.IMPORT.DATADOG_LOG_FORWARDER, project, reservedConcurrency = DEFAULT_RESERVED_CONCURRENCY, service = CDK$2.VENDOR.DATADOG, templateUrl = DATADOG_FORWARDER_TEMPLATE_URL, } = props;
1573
- // Validate required parameters
1574
- if (!datadogApiKey) {
1575
- throw new Error("Datadog API key is required. Provide via datadogApiKey prop or CDK_ENV_DATADOG_API_KEY environment variable.");
1576
- }
1577
- // Build Datadog tags
1578
- let ddTags = account ? `account:${account}` : "";
1579
- if (additionalTags) {
1580
- ddTags = ddTags ? `${ddTags},${additionalTags}` : additionalTags;
1581
- }
1582
- // Deploy Datadog CloudFormation stack
1583
- this.cfnStack = new CfnStack(this, "Stack", {
1584
- parameters: {
1585
- DdApiKey: datadogApiKey,
1586
- DdTags: ddTags,
1587
- ReservedConcurrency: reservedConcurrency,
1588
- },
1589
- templateUrl,
1590
- });
1591
- // Add tags to stack
1592
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1593
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.SERVICE, service);
1594
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.VENDOR, CDK$2.VENDOR.DATADOG);
1595
- if (project) {
1596
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.PROJECT, project);
1597
- }
1598
- // Extract forwarder function from stack outputs
1599
- this.forwarderFunction = lambda.Function.fromFunctionArn(this, "Function", this.cfnStack.getAtt("Outputs.DatadogForwarderArn").toString());
1600
- // Extend Datadog role with custom permissions if enabled
1601
- if (enableRoleExtension) {
1602
- extendDatadogRole(this, { project, service });
1603
- }
1604
- // Create CloudFormation events rule if enabled
1605
- if (enableCloudFormationEvents) {
1606
- this.eventsRule = new Rule(this, "CloudFormationEventsRule", {
1607
- eventPattern: {
1608
- source: ["aws.cloudformation"],
1609
- },
1610
- targets: [
1611
- new LambdaFunction(this.forwarderFunction, {
1612
- event: RuleTargetInput.fromEventPath("$"),
1613
- }),
1614
- ],
1615
- });
1616
- // Add tags to events rule
1617
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1618
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.SERVICE, service);
1619
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.VENDOR, CDK$2.VENDOR.DATADOG);
1620
- if (project) {
1621
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.PROJECT, project);
1622
- }
1623
- }
1624
- // Create CloudFormation output if enabled
1625
- if (createOutput) {
1626
- new cdk.CfnOutput(this, "ForwarderArnOutput", {
1627
- description: "Datadog Log Forwarder Lambda ARN",
1628
- exportName,
1629
- value: this.cfnStack.getAtt("Outputs.DatadogForwarderArn").toString(),
1630
- });
1631
- }
1632
- }
1633
- }
1634
-
1635
- class JaypieDistribution extends Construct {
1636
- constructor(scope, id, props) {
1637
- super(scope, id);
1638
- const { certificate: certificateProp = true, defaultBehavior: propsDefaultBehavior, destination: destinationProp = true, handler, host: propsHost, invokeMode = lambda.InvokeMode.BUFFERED, roleTag = CDK$2.ROLE.API, zone: propsZone, ...distributionProps } = props;
1639
- // Validate environment variables
1640
- if (process.env.CDK_ENV_API_SUBDOMAIN &&
1641
- !isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
1642
- throw new Error("CDK_ENV_API_SUBDOMAIN is not a valid subdomain");
1643
- }
1644
- if (process.env.CDK_ENV_API_HOSTED_ZONE &&
1645
- !isValidHostname$1(process.env.CDK_ENV_API_HOSTED_ZONE)) {
1646
- throw new Error("CDK_ENV_API_HOSTED_ZONE is not a valid hostname");
1647
- }
1648
- if (process.env.CDK_ENV_HOSTED_ZONE &&
1649
- !isValidHostname$1(process.env.CDK_ENV_HOSTED_ZONE)) {
1650
- throw new Error("CDK_ENV_HOSTED_ZONE is not a valid hostname");
1651
- }
1652
- // Determine host from props or environment
1653
- let host = propsHost;
1654
- if (!host) {
1655
- try {
1656
- if (process.env.CDK_ENV_API_HOST_NAME) {
1657
- host = process.env.CDK_ENV_API_HOST_NAME;
1658
- }
1659
- else if (process.env.CDK_ENV_API_SUBDOMAIN) {
1660
- host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE ||
1661
- process.env.CDK_ENV_HOSTED_ZONE ||
1662
- "");
1663
- }
1664
- }
1665
- catch {
1666
- host = undefined;
1667
- }
1668
- }
1669
- if (host && !isValidHostname$1(host)) {
1670
- throw new Error("Host is not a valid hostname");
1671
- }
1672
- this.host = host;
1673
- // Determine zone from props or environment
1674
- const zone = propsZone || process.env.CDK_ENV_HOSTED_ZONE;
1675
- // Resolve the origin from handler
1676
- // Check order matters: IFunctionUrl before IOrigin (FunctionUrl also has bind method)
1677
- // IFunction before IFunctionUrl (IFunction doesn't have functionUrlId)
1678
- let origin;
1679
- if (handler) {
1680
- if (this.isIFunction(handler)) {
1681
- // Create FunctionUrl for the Lambda function
1682
- const functionUrl = new lambda.FunctionUrl(this, "FunctionUrl", {
1683
- function: handler,
1684
- authType: lambda.FunctionUrlAuthType.NONE,
1685
- invokeMode,
1686
- });
1687
- this.functionUrl = functionUrl;
1688
- origin = new origins.FunctionUrlOrigin(functionUrl);
1689
- }
1690
- else if (this.isIFunctionUrl(handler)) {
1691
- origin = new origins.FunctionUrlOrigin(handler);
1692
- }
1693
- else if (this.isIOrigin(handler)) {
1694
- origin = handler;
1695
- }
1696
- }
1697
- // Build default behavior
1698
- let defaultBehavior;
1699
- if (propsDefaultBehavior) {
1700
- defaultBehavior = propsDefaultBehavior;
1701
- }
1702
- else if (origin) {
1703
- defaultBehavior = {
1704
- allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
1705
- cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
1706
- origin,
1707
- originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
1708
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
1709
- };
1710
- }
1711
- else {
1712
- throw new Error("Either handler or defaultBehavior must be provided to JaypieDistribution");
1713
- }
1714
- // Resolve hosted zone and certificate
1715
- // Only resolve zone when we need it (for certificate or DNS)
1716
- let hostedZone;
1717
- let certificateToUse;
1718
- if (host && zone && certificateProp !== false) {
1719
- hostedZone = resolveHostedZone(this, { zone });
1720
- if (certificateProp === true) {
1721
- certificateToUse = new acm.Certificate(this, constructEnvName("Certificate"), {
1722
- domainName: host,
1723
- validation: acm.CertificateValidation.fromDns(hostedZone),
1724
- });
1725
- Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, roleTag);
1726
- }
1727
- else if (typeof certificateProp === "object") {
1728
- certificateToUse = certificateProp;
1729
- }
1730
- this.certificate = certificateToUse;
1731
- }
1732
- // Create log bucket if logging is enabled
1733
- let logBucket;
1734
- if (destinationProp !== false) {
1735
- logBucket = new s3.Bucket(this, constructEnvName("LogBucket"), {
1736
- objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
1737
- removalPolicy: RemovalPolicy.DESTROY,
1738
- autoDeleteObjects: true,
1739
- lifecycleRules: [
1740
- {
1741
- expiration: Duration.days(90),
1742
- transitions: [
1743
- {
1744
- storageClass: s3.StorageClass.INFREQUENT_ACCESS,
1745
- transitionAfter: Duration.days(30),
1746
- },
1747
- ],
1748
- },
1749
- ],
1750
- });
1751
- Tags.of(logBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
1752
- // Add S3 notification to Datadog forwarder
1753
- const lambdaDestination = destinationProp === true
1754
- ? new LambdaDestination(resolveDatadogForwarderFunction(this))
1755
- : destinationProp;
1756
- logBucket.addEventNotification(s3.EventType.OBJECT_CREATED, lambdaDestination);
1757
- this.logBucket = logBucket;
1758
- }
1759
- // Create the CloudFront distribution
1760
- this.distribution = new cloudfront.Distribution(this, constructEnvName("Distribution"), {
1761
- defaultBehavior,
1762
- ...(host && certificateToUse
1763
- ? {
1764
- certificate: certificateToUse,
1765
- domainNames: [host],
1766
- }
1767
- : {}),
1768
- ...(logBucket
1769
- ? {
1770
- enableLogging: true,
1771
- logBucket,
1772
- logFilePrefix: "cloudfront-logs/",
1773
- }
1774
- : {}),
1775
- ...distributionProps,
1776
- });
1777
- Tags.of(this.distribution).add(CDK$2.TAG.ROLE, roleTag);
1778
- this.distributionArn = `arn:aws:cloudfront::${Stack.of(this).account}:distribution/${this.distribution.distributionId}`;
1779
- this.distributionDomainName = this.distribution.distributionDomainName;
1780
- this.distributionId = this.distribution.distributionId;
1781
- this.domainName = this.distribution.domainName;
1782
- // Create DNS records if we have host and zone
1783
- if (host && hostedZone) {
1784
- const aRecord = new route53.ARecord(this, "AliasRecord", {
1785
- recordName: host,
1786
- target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
1787
- zone: hostedZone,
1788
- });
1789
- Tags.of(aRecord).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
1790
- const aaaaRecord = new route53.AaaaRecord(this, "AaaaAliasRecord", {
1791
- recordName: host,
1792
- target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
1793
- zone: hostedZone,
1794
- });
1795
- Tags.of(aaaaRecord).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
1796
- }
1797
- }
1798
- // Type guards for handler types
1799
- isIOrigin(handler) {
1800
- return (typeof handler === "object" &&
1801
- handler !== null &&
1802
- "bind" in handler &&
1803
- typeof handler.bind === "function");
1804
- }
1805
- isIFunctionUrl(handler) {
1806
- // FunctionUrl has 'url' property which is the function URL string
1807
- // IFunction does not have 'url' property
1808
- return (typeof handler === "object" &&
1809
- handler !== null &&
1810
- "url" in handler &&
1811
- "functionArn" in handler);
1812
- }
1813
- isIFunction(handler) {
1814
- // IFunction has functionArn and functionName but NOT 'url'
1815
- // (FunctionUrl also has functionArn but also has 'url')
1816
- return (typeof handler === "object" &&
1817
- handler !== null &&
1818
- "functionArn" in handler &&
1819
- "functionName" in handler &&
1820
- !("url" in handler));
1821
- }
1822
- // Implement IDistribution interface
1823
- get env() {
1824
- return {
1825
- account: Stack.of(this).account,
1826
- region: Stack.of(this).region,
1827
- };
1828
- }
1829
- get stack() {
1830
- return this.distribution.stack;
1831
- }
1832
- applyRemovalPolicy(policy) {
1833
- this.distribution.applyRemovalPolicy(policy);
1834
- }
1835
- grant(identity, ...actions) {
1836
- return this.distribution.grant(identity, ...actions);
1837
- }
1838
- grantCreateInvalidation(identity) {
1839
- return this.distribution.grantCreateInvalidation(identity);
1840
- }
1841
- get distributionRef() {
1842
- return {
1843
- distributionId: this.distribution.distributionId,
1844
- };
1845
- }
1846
- }
1847
-
1848
- // It is a consumer if the environment is ephemeral
1849
- function checkEnvIsConsumer(env = process.env) {
1850
- return (env.PROJECT_ENV === CDK$2.ENV.PERSONAL ||
1851
- !!env.CDK_ENV_PERSONAL ||
1852
- /** @deprecated */ env.PROJECT_ENV === "ephemeral" ||
1853
- /** @deprecated */ !!env.CDK_ENV_EPHEMERAL);
1854
- }
1855
- function checkEnvIsProvider(env = process.env) {
1856
- return env.PROJECT_ENV === CDK$2.ENV.SANDBOX;
1857
- }
1858
- function cleanName(name) {
1859
- return name.replace(/[^a-zA-Z0-9:-]/g, "");
1860
- }
1861
- function exportEnvName(name, env = process.env) {
1862
- let rawName;
1863
- if (checkEnvIsProvider(env)) {
1864
- rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
1865
- // Clean the entire name to only allow alphanumeric, colons, and hyphens
1866
- return cleanName(rawName);
1867
- }
1868
- else {
1869
- if (checkEnvIsConsumer(env)) {
1870
- rawName = `env-${CDK$2.ENV.SANDBOX}-${env.PROJECT_KEY}-${name}`;
1871
- }
1872
- else {
1873
- rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
1874
- }
1875
- }
1876
- return cleanName(rawName);
1877
- }
1878
- class JaypieEnvSecret extends Construct {
1879
- constructor(scope, idOrEnvKey, props) {
1880
- // Check if idOrEnvKey should be treated as envKey:
1881
- // - No props provided OR props.envKey is not set
1882
- // - AND idOrEnvKey exists as a non-empty string in process.env
1883
- const treatAsEnvKey = (!props || props.envKey === undefined) &&
1884
- typeof process.env[idOrEnvKey] === "string" &&
1885
- process.env[idOrEnvKey] !== "";
1886
- const id = treatAsEnvKey ? `EnvSecret_${idOrEnvKey}` : idOrEnvKey;
1887
- super(scope, id);
1888
- const { consumer = checkEnvIsConsumer(), envKey: envKeyProp, export: exportParam, generateSecretString, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
1889
- const envKey = treatAsEnvKey ? idOrEnvKey : envKeyProp;
1890
- this._envKey = envKey;
1891
- let exportName;
1892
- if (!exportParam) {
1893
- exportName = exportEnvName(id);
1894
- }
1895
- else {
1896
- exportName = cleanName(exportParam);
1897
- }
1898
- if (consumer) {
1899
- const secretName = Fn.importValue(exportName);
1900
- this._secret = secretsmanager.Secret.fromSecretNameV2(this, id, secretName);
1901
- // Add CfnOutput for consumer secrets
1902
- new CfnOutput(this, `ConsumedName`, {
1903
- value: this._secret.secretName,
1904
- });
1905
- }
1906
- else {
1907
- const secretValue = envKey && process.env[envKey] ? process.env[envKey] : value;
1908
- const secretProps = {
1909
- generateSecretString,
1910
- secretStringValue: !generateSecretString && secretValue
1911
- ? SecretValue.unsafePlainText(secretValue)
1912
- : undefined,
1913
- };
1914
- this._secret = new secretsmanager.Secret(this, id, secretProps);
1915
- if (roleTag) {
1916
- Tags.of(this._secret).add(CDK$2.TAG.ROLE, roleTag);
1917
- }
1918
- if (vendorTag) {
1919
- Tags.of(this._secret).add(CDK$2.TAG.VENDOR, vendorTag);
1920
- }
1921
- if (provider) {
1922
- new CfnOutput(this, `ProvidedName`, {
1923
- value: this._secret.secretName,
1924
- exportName,
1925
- });
1926
- }
1927
- else {
1928
- new CfnOutput(this, `CreatedName`, {
1929
- value: this._secret.secretName,
1930
- });
1931
- }
1932
- }
1933
- }
1934
- // IResource implementation
1935
- get stack() {
1936
- return Stack.of(this);
1937
- }
1938
- get env() {
1939
- return {
1940
- account: Stack.of(this).account,
1941
- region: Stack.of(this).region,
1942
- };
1943
- }
1944
- applyRemovalPolicy(policy) {
1945
- this._secret.applyRemovalPolicy(policy);
1946
- }
1947
- // ISecret implementation
1948
- get secretArn() {
1949
- return this._secret.secretArn;
1950
- }
1951
- get secretName() {
1952
- return this._secret.secretName;
1953
- }
1954
- get secretFullArn() {
1955
- return this._secret.secretFullArn;
1956
- }
1957
- get encryptionKey() {
1958
- return this._secret.encryptionKey;
1959
- }
1960
- get secretValue() {
1961
- return this._secret.secretValue;
1962
- }
1963
- secretValueFromJson(key) {
1964
- return this._secret.secretValueFromJson(key);
1965
- }
1966
- grantRead(grantee, versionStages) {
1967
- return this._secret.grantRead(grantee, versionStages);
1968
- }
1969
- grantWrite(grantee) {
1970
- return this._secret.grantWrite(grantee);
1971
- }
1972
- addRotationSchedule(id, options) {
1973
- return this._secret.addRotationSchedule(id, options);
1974
- }
1975
- addToResourcePolicy(statement) {
1976
- return this._secret.addToResourcePolicy(statement);
1977
- }
1978
- denyAccountRootDelete() {
1979
- this._secret.denyAccountRootDelete();
1980
- }
1981
- attach(target) {
1982
- return this._secret.attach(target);
1983
- }
1984
- get envKey() {
1985
- return this._envKey;
1986
- }
1987
- }
1988
-
1989
- class JaypieDatadogSecret extends JaypieEnvSecret {
1990
- constructor(scope, id = "MongoConnectionString", props) {
1991
- const defaultProps = {
1992
- envKey: "DATADOG_API_KEY",
1993
- roleTag: CDK$2.ROLE.MONITORING,
1994
- vendorTag: CDK$2.VENDOR.DATADOG,
1995
- ...props,
1996
- };
1997
- super(scope, id, defaultProps);
1998
- }
1999
- }
2000
-
2001
- class JaypieDnsRecord extends Construct {
2002
- constructor(scope, id, props) {
2003
- super(scope, id);
2004
- const { comment, recordName, type, values } = props;
2005
- const ttl = props.ttl || cdk.Duration.seconds(CDK$2.DNS.CONFIG.TTL);
2006
- // Resolve the hosted zone (supports both string and IHostedZone)
2007
- const zone = resolveHostedZone(scope, {
2008
- name: `${id}HostedZone`,
2009
- zone: props.zone,
2010
- });
2011
- // Common properties for all record types
2012
- const baseProps = {
2013
- comment,
2014
- recordName,
2015
- ttl,
2016
- zone,
2017
- };
2018
- // Create the appropriate record based on type
2019
- switch (type) {
2020
- case CDK$2.DNS.RECORD.A: {
2021
- if (!Array.isArray(values) || values.length === 0) {
2022
- throw new ConfigurationError("A record requires at least one IP address");
2023
- }
2024
- this.record = new ARecord(this, "Record", {
2025
- ...baseProps,
2026
- target: RecordTarget.fromIpAddresses(...values),
2027
- });
2028
- break;
2029
- }
2030
- case CDK$2.DNS.RECORD.CNAME: {
2031
- if (!Array.isArray(values) || values.length === 0) {
2032
- throw new ConfigurationError("CNAME record requires a domain name");
2033
- }
2034
- this.record = new CnameRecord(this, "Record", {
2035
- ...baseProps,
2036
- domainName: values[0],
2037
- });
2038
- break;
2039
- }
2040
- case CDK$2.DNS.RECORD.MX: {
2041
- if (!Array.isArray(values) || values.length === 0) {
2042
- throw new ConfigurationError("MX record requires at least one mail server");
2043
- }
2044
- this.record = new MxRecord(this, "Record", {
2045
- ...baseProps,
2046
- values: values,
2047
- });
2048
- break;
2049
- }
2050
- case CDK$2.DNS.RECORD.NS: {
2051
- if (!Array.isArray(values) || values.length === 0) {
2052
- throw new ConfigurationError("NS record requires at least one name server");
2053
- }
2054
- this.record = new NsRecord(this, "Record", {
2055
- ...baseProps,
2056
- values: values,
2057
- });
2058
- break;
2059
- }
2060
- case CDK$2.DNS.RECORD.TXT: {
2061
- if (!Array.isArray(values) || values.length === 0) {
2062
- throw new ConfigurationError("TXT record requires at least one value");
2063
- }
2064
- this.record = new TxtRecord(this, "Record", {
2065
- ...baseProps,
2066
- values: values,
2067
- });
2068
- break;
2069
- }
2070
- default:
2071
- throw new ConfigurationError(`Unsupported DNS record type: ${type}. Supported types: A, CNAME, MX, NS, TXT`);
2072
- }
2073
- // Add standard tags to the DNS record
2074
- cdk.Tags.of(this.record).add(CDK$2.TAG.SERVICE, CDK$2.SERVICE.INFRASTRUCTURE);
2075
- cdk.Tags.of(this.record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
2076
- }
2077
- }
2078
-
2079
- class JaypieEventsRule extends Construct {
2080
- /**
2081
- * Create a new EventBridge rule that targets a Lambda function
2082
- */
2083
- constructor(scope, idOrSourceOrProps, propsOrUndefined) {
2084
- // Handle overloaded constructor signatures
2085
- let props;
2086
- let id;
2087
- if (typeof idOrSourceOrProps === "string") {
2088
- // Check if it looks like an AWS source (starts with "aws.")
2089
- if (idOrSourceOrProps.startsWith("aws.")) {
2090
- // First param is source, second is props
2091
- props = propsOrUndefined || {};
2092
- props.source = idOrSourceOrProps;
2093
- // Generate ID from source
2094
- const sourceName = idOrSourceOrProps
2095
- .replace("aws.", "")
2096
- .split(".")
2097
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
2098
- .join("");
2099
- id = props.id || `${sourceName}EventsRule`;
2100
- }
2101
- else {
2102
- // First param is ID, second is props
2103
- props = propsOrUndefined || {};
2104
- id = idOrSourceOrProps;
2105
- }
2106
- }
2107
- else {
2108
- // First param is props
2109
- props = idOrSourceOrProps || {};
2110
- if (props.source) {
2111
- const sourceName = typeof props.source === "string"
2112
- ? props.source
2113
- .replace("aws.", "")
2114
- .split(".")
2115
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
2116
- .join("")
2117
- : "Events";
2118
- id = props.id || `${sourceName}EventsRule`;
2119
- }
2120
- else {
2121
- id = props.id || "EventsRule";
2122
- }
2123
- }
2124
- super(scope, id);
2125
- // Extract Jaypie-specific options
2126
- const { id: _id, project, service = CDK$2.SERVICE.DATADOG, source, targetFunction, vendor = CDK$2.VENDOR.DATADOG, ...ruleProps } = props;
2127
- // Resolve target function
2128
- this.targetFunction =
2129
- targetFunction || resolveDatadogForwarderFunction(scope);
2130
- // Build event pattern if source is specified
2131
- const eventPattern = source
2132
- ? {
2133
- ...ruleProps.eventPattern,
2134
- source: Array.isArray(source) ? source : [source],
2135
- }
2136
- : ruleProps.eventPattern;
2137
- // Build rule props
2138
- const finalRuleProps = {
2139
- ...ruleProps,
2140
- eventPattern,
2141
- targets: [
2142
- new LambdaFunction(this.targetFunction, {
2143
- event: RuleTargetInput.fromEventPath("$"),
2144
- }),
2145
- ],
2146
- };
2147
- // Create the rule
2148
- this.rule = new Rule(this, "Rule", finalRuleProps);
2149
- // Add tags
2150
- cdk.Tags.of(this.rule).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
2151
- cdk.Tags.of(this.rule).add(CDK$2.TAG.SERVICE, service);
2152
- cdk.Tags.of(this.rule).add(CDK$2.TAG.VENDOR, vendor);
2153
- if (project) {
2154
- cdk.Tags.of(this.rule).add(CDK$2.TAG.PROJECT, project);
2155
- }
2156
- }
2157
- }
2158
-
2159
- class JaypieGitHubDeployRole extends Construct {
2160
- constructor(scope, id = "GitHubDeployRole", props = {}) {
2161
- super(scope, id);
2162
- const { oidcProviderArn = Fn.importValue(CDK$2.IMPORT.OIDC_PROVIDER), output = true, repoRestriction: propsRepoRestriction, } = props;
2163
- // Extract account ID from the scope
2164
- const accountId = Stack.of(this).account;
2165
- // Resolve repoRestriction from props or environment variables
2166
- let repoRestriction = propsRepoRestriction;
2167
- if (!repoRestriction) {
2168
- const envRepo = process.env.CDK_ENV_REPO || process.env.PROJECT_REPO;
2169
- if (!envRepo) {
2170
- throw new ConfigurationError("No repoRestriction provided. Set repoRestriction prop, CDK_ENV_REPO, or PROJECT_REPO environment variable");
2171
- }
2172
- // Extract organization from owner/repo format and create org-wide restriction
2173
- const organization = envRepo.split("/")[0];
2174
- repoRestriction = `repo:${organization}/*:*`;
2175
- }
2176
- // Create the IAM role
2177
- this._role = new Role(this, "GitHubActionsRole", {
2178
- assumedBy: new FederatedPrincipal(oidcProviderArn, {
2179
- StringLike: {
2180
- "token.actions.githubusercontent.com:sub": repoRestriction,
2181
- },
2182
- }, "sts:AssumeRoleWithWebIdentity"),
2183
- maxSessionDuration: Duration.hours(1),
2184
- path: "/",
2185
- });
2186
- Tags.of(this._role).add(CDK$2.TAG.ROLE, CDK$2.ROLE.DEPLOY);
2187
- // Allow the role to access the GitHub OIDC provider
2188
- this._role.addToPolicy(new PolicyStatement({
2189
- actions: ["sts:AssumeRoleWithWebIdentity"],
2190
- resources: [`arn:aws:iam::${accountId}:oidc-provider/*`],
2191
- }));
2192
- // Allow the role to deploy CDK apps
2193
- this._role.addToPolicy(new PolicyStatement({
2194
- actions: [
2195
- "cloudformation:CreateStack",
2196
- "cloudformation:DeleteStack",
2197
- "cloudformation:DescribeStackEvents",
2198
- "cloudformation:DescribeStackResource",
2199
- "cloudformation:DescribeStackResources",
2200
- "cloudformation:DescribeStacks",
2201
- "cloudformation:GetTemplate",
2202
- "cloudformation:SetStackPolicy",
2203
- "cloudformation:UpdateStack",
2204
- "cloudformation:ValidateTemplate",
2205
- "iam:PassRole",
2206
- "route53:ListHostedZones*",
2207
- "s3:GetObject",
2208
- "s3:ListBucket",
2209
- ],
2210
- effect: Effect.ALLOW,
2211
- resources: ["*"],
2212
- }));
2213
- this._role.addToPolicy(new PolicyStatement({
2214
- actions: ["iam:PassRole", "sts:AssumeRole"],
2215
- effect: Effect.ALLOW,
2216
- resources: [
2217
- "arn:aws:iam::*:role/cdk-hnb659fds-deploy-role-*",
2218
- "arn:aws:iam::*:role/cdk-hnb659fds-file-publishing-*",
2219
- "arn:aws:iam::*:role/cdk-readOnlyRole",
2220
- ],
2221
- }));
2222
- // Export the ARN of the role
2223
- if (output !== false) {
2224
- const outputId = typeof output === "string" ? output : "GitHubActionsRoleArn";
2225
- new CfnOutput(this, outputId, {
2226
- value: this._role.roleArn,
2227
- });
2228
- }
2229
- }
2230
- get role() {
2231
- return this._role;
2232
- }
2233
- get roleArn() {
2234
- return this._role.roleArn;
2235
- }
2236
- get roleName() {
2237
- return this._role.roleName;
2238
- }
2239
- }
2240
-
2241
- class JaypieExpressLambda extends JaypieLambda {
2242
- constructor(scope, id, props) {
2243
- super(scope, id, {
2244
- timeout: Duration.seconds(CDK$2.DURATION.EXPRESS_API),
2245
- roleTag: CDK$2.ROLE.API,
2246
- ...props,
2247
- });
2248
- }
2249
- }
2250
-
2251
- const SERVICE = {
2252
- ROUTE53: "route53.amazonaws.com",
2253
- };
2254
- /**
2255
- * Check if a string is a valid hostname
2256
- */
2257
- function isValidHostname(str) {
2258
- // Check if it contains a dot and matches hostname pattern
2259
- if (!str.includes("."))
2260
- return false;
2261
- // Basic hostname validation: alphanumeric, hyphens, dots
2262
- // Each label must start and end with alphanumeric
2263
- const hostnameRegex = /^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/i;
2264
- return hostnameRegex.test(str);
2265
- }
2266
- class JaypieHostedZone extends Construct {
2267
- /**
2268
- * Create a new hosted zone with query logging and optional DNS records
2269
- */
2270
- constructor(scope, idOrProps, propsOrRecords) {
2271
- // Handle overloaded constructor signatures
2272
- let props;
2273
- let id;
2274
- if (typeof idOrProps === "string") {
2275
- // If it's a valid hostname, treat it as zoneName
2276
- if (isValidHostname(idOrProps)) {
2277
- // Third param can be props object or records array
2278
- if (Array.isArray(propsOrRecords)) {
2279
- props = { zoneName: idOrProps, records: propsOrRecords };
2280
- }
2281
- else {
2282
- props = propsOrRecords || { zoneName: idOrProps };
2283
- // Set zoneName if not already set
2284
- if (!props.zoneName) {
2285
- props = { ...props, zoneName: idOrProps };
2286
- }
2287
- }
2288
- // Use id from props if provided, otherwise derive from zoneName
2289
- id = props.id || `${idOrProps}-HostedZone`;
2290
- }
2291
- else {
2292
- // Otherwise treat it as an explicit id
2293
- props = propsOrRecords;
2294
- id = idOrProps;
2295
- }
2296
- }
2297
- else {
2298
- // idOrProps is props
2299
- props = idOrProps;
2300
- id = props.id || `${props.zoneName}-HostedZone`;
2301
- }
2302
- super(scope, id);
2303
- const { zoneName, project } = props;
2304
- const destination = props.destination ?? true;
2305
- const service = props.service || CDK$2.SERVICE.INFRASTRUCTURE;
2306
- // Create the log group
2307
- this.logGroup = new LogGroup(this, "LogGroup", {
2308
- logGroupName: process.env.PROJECT_NONCE
2309
- ? `/aws/route53/${zoneName}-${process.env.PROJECT_NONCE}`
2310
- : `/aws/route53/${zoneName}`,
2311
- retention: RetentionDays.ONE_WEEK,
2312
- });
2313
- // Add tags
2314
- cdk.Tags.of(this.logGroup).add(CDK$2.TAG.SERVICE, service);
2315
- cdk.Tags.of(this.logGroup).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
2316
- if (project) {
2317
- cdk.Tags.of(this.logGroup).add(CDK$2.TAG.PROJECT, project);
2318
- }
2319
- // Grant Route 53 permissions to write to the log group
2320
- this.logGroup.grantWrite(new ServicePrincipal(SERVICE.ROUTE53));
2321
- // Add destination based on configuration
2322
- if (destination !== false) {
2323
- const lambdaDestination = destination === true
2324
- ? resolveDatadogLoggingDestination(scope)
2325
- : destination;
2326
- this.logGroup.addSubscriptionFilter("DatadogLambdaDestination", {
2327
- destination: lambdaDestination,
2328
- filterPattern: FilterPattern.allEvents(),
2329
- });
2330
- }
2331
- // Create the hosted zone
2332
- this.hostedZone = new HostedZone(this, "HostedZone", {
2333
- queryLogsLogGroupArn: this.logGroup.logGroupArn,
2334
- zoneName,
2335
- });
2336
- // Add tags
2337
- cdk.Tags.of(this.hostedZone).add(CDK$2.TAG.SERVICE, service);
2338
- cdk.Tags.of(this.hostedZone).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
2339
- if (project) {
2340
- cdk.Tags.of(this.hostedZone).add(CDK$2.TAG.PROJECT, project);
2341
- }
2342
- // Create DNS records if provided
2343
- this.dnsRecords = [];
2344
- if (props.records) {
2345
- props.records.forEach((recordConfig, index) => {
2346
- const { id, ...recordProps } = recordConfig;
2347
- // Generate a default ID if not provided
2348
- const recordId = id ||
2349
- `${recordProps.type}${recordProps.recordName ? `-${recordProps.recordName}` : ""}-${index}`;
2350
- const dnsRecord = new JaypieDnsRecord(this, recordId, {
2351
- ...recordProps,
2352
- zone: this.hostedZone,
2353
- });
2354
- this.dnsRecords.push(dnsRecord);
2355
- });
2356
- }
2357
- }
2358
- }
2359
-
2360
- const CDK = {
2361
- TAG: {
2362
- STACK_SHA: "stackSha",
2363
- },
2364
- };
2365
- class JaypieInfrastructureStack extends JaypieStack {
2366
- constructor(scope, id, props = {}) {
2367
- const { key = "infra", ...stackProps } = props;
2368
- // Handle stackName
2369
- if (!stackProps.stackName) {
2370
- stackProps.stackName = constructStackName(key);
2371
- }
2372
- super(scope, id, { key, ...stackProps });
2373
- // Add infrastructure-specific tag
2374
- if (process.env.CDK_ENV_INFRASTRUCTURE_STACK_SHA) {
2375
- Tags.of(this).add(CDK.TAG.STACK_SHA, process.env.CDK_ENV_INFRASTRUCTURE_STACK_SHA);
2376
- }
2377
- }
2378
- }
2379
-
2380
- class JaypieMongoDbSecret extends JaypieEnvSecret {
2381
- constructor(scope, id = "MongoConnectionString", props) {
2382
- const defaultProps = {
2383
- envKey: "MONGODB_URI",
2384
- roleTag: CDK$2.ROLE.STORAGE,
2385
- vendorTag: CDK$2.VENDOR.MONGODB,
2386
- ...props,
2387
- };
2388
- super(scope, id, defaultProps);
2389
- }
2390
- }
2391
-
2392
- class JaypieNextJs extends Construct {
2393
- constructor(scope, id, props) {
2394
- super(scope, id);
2395
- const domainName = props?.domainName || envHostname();
2396
- this.domainName = domainName;
2397
- const domainNameSanitized = domainName
2398
- .replace(/\./g, "-")
2399
- .replace(/[^a-zA-Z0-9]/g, "_");
2400
- const envSecrets = props?.envSecrets || {};
2401
- const nextjsPath = props?.nextjsPath?.startsWith("..")
2402
- ? path.join(process.cwd(), props.nextjsPath)
2403
- : props?.nextjsPath || path.join(process.cwd(), "..", "nextjs");
2404
- const paramsAndSecrets = resolveParamsAndSecrets();
2405
- const secrets = props?.secrets || [];
2406
- // Process secrets environment variables
2407
- const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
2408
- ...acc,
2409
- [`SECRET_${key}`]: secret.secretName,
2410
- }), {});
2411
- // Process JaypieEnvSecret array
2412
- const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
2413
- if (secret.envKey) {
2414
- return {
2415
- ...acc,
2416
- [`SECRET_${secret.envKey}`]: secret.secretName,
2417
- };
2418
- }
2419
- return acc;
2420
- }, {});
2421
- // Process NEXT_PUBLIC_ environment variables
2422
- const nextPublicEnv = Object.entries(process.env).reduce((acc, [key, value]) => {
2423
- if (key.startsWith("NEXT_PUBLIC_") && value) {
2424
- return {
2425
- ...acc,
2426
- [key]: value,
2427
- };
2428
- }
2429
- return acc;
2430
- }, {});
2431
- const nextjs = new Nextjs(this, "NextJsApp", {
2432
- nextjsPath,
2433
- domainProps: {
2434
- domainName,
2435
- hostedZone: resolveHostedZone(this, {
2436
- zone: props?.hostedZone,
2437
- }),
2438
- },
2439
- environment: {
2440
- ...jaypieLambdaEnv(),
2441
- ...secretsEnvironment,
2442
- ...jaypieSecretsEnvironment,
2443
- ...nextPublicEnv,
2444
- NEXT_PUBLIC_SITE_URL: `https://${domainName}`,
2445
- },
2446
- overrides: {
2447
- nextjsDistribution: {
2448
- imageCachePolicyProps: {
2449
- cachePolicyName: `NextJsImageCachePolicy-${domainNameSanitized}`,
2450
- },
2451
- serverCachePolicyProps: {
2452
- cachePolicyName: `NextJsServerCachePolicy-${domainNameSanitized}`,
2453
- },
2454
- },
2455
- nextjsImage: {
2456
- functionProps: {
2457
- paramsAndSecrets,
2458
- },
2459
- },
2460
- nextjsServer: {
2461
- functionProps: {
2462
- paramsAndSecrets,
2463
- },
2464
- },
2465
- },
2466
- });
2467
- addDatadogLayers(nextjs.imageOptimizationFunction);
2468
- addDatadogLayers(nextjs.serverFunction.lambdaFunction);
2469
- // Grant secret read permissions
2470
- Object.values(envSecrets).forEach((secret) => {
2471
- secret.grantRead(nextjs.serverFunction.lambdaFunction);
2472
- });
2473
- // Grant read permissions for JaypieEnvSecrets
2474
- secrets.forEach((secret) => {
2475
- secret.grantRead(nextjs.serverFunction.lambdaFunction);
2476
- });
2477
- }
2478
- }
2479
-
2480
- class JaypieOpenAiSecret extends JaypieEnvSecret {
2481
- constructor(scope, id = "OpenAiApiKey", props) {
2482
- const defaultProps = {
2483
- envKey: "OPENAI_API_KEY",
2484
- roleTag: CDK$2.ROLE.PROCESSING,
2485
- vendorTag: CDK$2.VENDOR.OPENAI,
2486
- ...props,
2487
- };
2488
- super(scope, id, defaultProps);
2489
- }
2490
- }
2491
-
2492
- class JaypieOrganizationTrail extends Construct {
2493
- /**
2494
- * Create a new organization CloudTrail with S3 bucket and lifecycle policies
2495
- */
2496
- constructor(scope, idOrProps, propsOrUndefined) {
2497
- // Handle overloaded constructor signatures
2498
- let props;
2499
- let id;
2500
- if (typeof idOrProps === "string") {
2501
- // First param is ID, second is props
2502
- props = propsOrUndefined || {};
2503
- id = idOrProps;
2504
- }
2505
- else {
2506
- // First param is props
2507
- props = idOrProps || {};
2508
- const defaultName = process.env.PROJECT_NONCE
2509
- ? `organization-cloudtrail-${process.env.PROJECT_NONCE}`
2510
- : "organization-cloudtrail";
2511
- id = props.id || `${props.trailName || defaultName}-Trail`;
2512
- }
2513
- super(scope, id);
2514
- // Resolve options with defaults
2515
- const { bucketName = process.env.PROJECT_NONCE
2516
- ? `organization-cloudtrail-${process.env.PROJECT_NONCE}`
2517
- : "organization-cloudtrail", enableDatadogNotifications = true, enableFileValidation = false, expirationDays = 365, glacierTransitionDays = 180, infrequentAccessTransitionDays = 30, project, service = CDK$2.SERVICE.INFRASTRUCTURE, trailName = process.env.PROJECT_NONCE
2518
- ? `organization-cloudtrail-${process.env.PROJECT_NONCE}`
2519
- : "organization-cloudtrail", } = props;
2520
- // Create the S3 bucket for CloudTrail logs
2521
- this.bucket = new Bucket(this, "Bucket", {
2522
- accessControl: BucketAccessControl.LOG_DELIVERY_WRITE,
2523
- bucketName,
2524
- lifecycleRules: [
2525
- {
2526
- expiration: cdk.Duration.days(expirationDays),
2527
- transitions: [
2528
- {
2529
- storageClass: StorageClass.INFREQUENT_ACCESS,
2530
- transitionAfter: cdk.Duration.days(infrequentAccessTransitionDays),
2531
- },
2532
- {
2533
- storageClass: StorageClass.GLACIER,
2534
- transitionAfter: cdk.Duration.days(glacierTransitionDays),
2535
- },
2536
- ],
2537
- },
2538
- ],
2539
- });
2540
- // Add CloudTrail bucket policies
2541
- this.bucket.addToResourcePolicy(new PolicyStatement({
2542
- actions: ["s3:GetBucketAcl"],
2543
- effect: Effect.ALLOW,
2544
- principals: [new ServicePrincipal("cloudtrail.amazonaws.com")],
2545
- resources: [this.bucket.bucketArn],
2546
- }));
2547
- this.bucket.addToResourcePolicy(new PolicyStatement({
2548
- actions: ["s3:PutObject"],
2549
- conditions: {
2550
- StringEquals: {
2551
- "s3:x-amz-acl": "bucket-owner-full-control",
2552
- },
2553
- },
2554
- effect: Effect.ALLOW,
2555
- principals: [new ServicePrincipal("cloudtrail.amazonaws.com")],
2556
- resources: [`${this.bucket.bucketArn}/*`],
2557
- }));
2558
- // Add tags to bucket
2559
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.SERVICE, service);
2560
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
2561
- if (project) {
2562
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.PROJECT, project);
2563
- }
2564
- // Add Datadog notifications if enabled
2565
- if (enableDatadogNotifications) {
2566
- const datadogForwarderFunction = resolveDatadogForwarderFunction(scope);
2567
- this.bucket.addEventNotification(EventType.OBJECT_CREATED, new LambdaDestination(datadogForwarderFunction));
2568
- }
2569
- // Create the organization trail
2570
- this.trail = new Trail(this, "Trail", {
2571
- bucket: this.bucket,
2572
- enableFileValidation,
2573
- isOrganizationTrail: true,
2574
- managementEvents: ReadWriteType.ALL,
2575
- trailName,
2576
- });
2577
- // Add tags to trail
2578
- cdk.Tags.of(this.trail).add(CDK$2.TAG.SERVICE, service);
2579
- cdk.Tags.of(this.trail).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
2580
- if (project) {
2581
- cdk.Tags.of(this.trail).add(CDK$2.TAG.PROJECT, project);
2582
- }
2583
- }
2584
- }
2585
-
2586
- /**
2587
- * JaypieSsoPermissions Construct
2588
- *
2589
- * Creates and manages AWS IAM Identity Center (SSO) permission sets and assignments
2590
- *
2591
- * @example
2592
- * const permissionSets = new JaypieSsoPermissions(this, "PermissionSets", {
2593
- * iamIdentityCenterArn: "arn:aws:sso:::instance/...",
2594
- * administratorGroupId: "b4c8b438-4031-7000-782d-5046945fb956",
2595
- * analystGroupId: "2488f4e8-d061-708e-abe1-c315f0e30005",
2596
- * developerGroupId: "b438a4f8-e0e1-707c-c6e8-21841daf9ad1",
2597
- * administratorAccountAssignments: {
2598
- * "211125635435": ["Administrator", "Analyst", "Developer"],
2599
- * "381492033431": ["Administrator", "Analyst"],
2600
- * },
2601
- * analystAccountAssignments: {
2602
- * "211125635435": ["Analyst", "Developer"],
2603
- * "381492033431": [],
2604
- * },
2605
- * developerAccountAssignments: {
2606
- * "211125635435": ["Analyst", "Developer"],
2607
- * "381492033431": [],
2608
- * },
2609
- * });
2610
- */
2611
- class JaypieSsoPermissions extends Construct {
2612
- constructor(scope, id, props) {
2613
- super(scope, id);
2614
- const { iamIdentityCenterArn: iamIdentityCenterArnProp, administratorGroupId, analystGroupId, developerGroupId, administratorAccountAssignments, analystAccountAssignments, developerAccountAssignments, } = props;
2615
- const iamIdentityCenterArn = iamIdentityCenterArnProp || process.env.CDK_ENV_IAM_IDENTITY_CENTER_ARN;
2616
- if (!iamIdentityCenterArn) {
2617
- // If no IAM Identity Center ARN provided, skip SSO setup
2618
- return;
2619
- }
2620
- //
2621
- // Permission Sets
2622
- //
2623
- this.administratorPermissionSet = new CfnPermissionSet(this, "AdministratorPermissionSet", {
2624
- // Required
2625
- instanceArn: iamIdentityCenterArn,
2626
- name: "Administrator",
2627
- // Optional
2628
- description: "Unrestricted access",
2629
- inlinePolicy: {
2630
- Version: "2012-10-17",
2631
- Statement: [
2632
- {
2633
- Effect: "Allow",
2634
- Action: [
2635
- "aws-portal:ViewUsage",
2636
- "aws-portal:ViewBilling",
2637
- "budgets:*",
2638
- "cur:DescribeReportDefinitions",
2639
- "cur:PutReportDefinition",
2640
- "cur:DeleteReportDefinition",
2641
- "cur:ModifyReportDefinition",
2642
- ],
2643
- Resource: "*",
2644
- },
2645
- ],
2646
- },
2647
- managedPolicies: [
2648
- ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")
2649
- .managedPolicyArn,
2650
- ManagedPolicy.fromAwsManagedPolicyName("AWSManagementConsoleBasicUserAccess").managedPolicyArn,
2651
- ],
2652
- sessionDuration: Duration.hours(1).toIsoString(),
2653
- tags: [
2654
- {
2655
- key: CDK$2.TAG.SERVICE,
2656
- value: CDK$2.SERVICE.SSO,
2657
- },
2658
- {
2659
- key: CDK$2.TAG.ROLE,
2660
- value: CDK$2.ROLE.SECURITY,
2661
- },
2662
- ],
2663
- });
2664
- this.analystPermissionSet = new CfnPermissionSet(this, "AnalystPermissionSet", {
2665
- // Required
2666
- instanceArn: iamIdentityCenterArn,
2667
- name: "Analyst",
2668
- // Optional
2669
- description: "Read-only access; may expand to limited write access",
2670
- inlinePolicy: {
2671
- Version: "2012-10-17",
2672
- Statement: [
2673
- {
2674
- Effect: "Allow",
2675
- Action: [
2676
- "aws-portal:ViewUsage",
2677
- "aws-portal:ViewBilling",
2678
- "budgets:Describe*",
2679
- "budgets:View*",
2680
- "ce:Get*",
2681
- "ce:List*",
2682
- "cloudformation:Describe*",
2683
- "cloudformation:Get*",
2684
- "cloudformation:List*",
2685
- "cloudwatch:BatchGet*",
2686
- "cloudwatch:Get*",
2687
- "cloudwatch:List*",
2688
- "cost-optimization-hub:Get*",
2689
- "cost-optimization-hub:List*",
2690
- "ec2:Describe*",
2691
- "ec2:Get*",
2692
- "ec2:List*",
2693
- "ec2:Search*",
2694
- "iam:Get*",
2695
- "iam:List*",
2696
- "iam:PassRole",
2697
- "lambda:Get*",
2698
- "lambda:List*",
2699
- "logs:Describe*",
2700
- "logs:Get*",
2701
- "logs:List*",
2702
- "pipes:Describe*",
2703
- "pipes:List*",
2704
- "s3:Get*",
2705
- "s3:List*",
2706
- "secretsmanager:GetRandomPassword",
2707
- "secretsmanager:GetResourcePolicy",
2708
- "secretsmanager:List*",
2709
- "securityhub:Describe*",
2710
- "securityhub:Get*",
2711
- "securityhub:List*",
2712
- "servicecatalog:Describe*",
2713
- "sns:Get*",
2714
- "sns:List*",
2715
- "sqs:Get*",
2716
- "sqs:List*",
2717
- "states:Describe*",
2718
- "states:Get*",
2719
- "states:List*",
2720
- "tag:*",
2721
- "uxc:*",
2722
- "xray:*",
2723
- ],
2724
- Resource: "*",
2725
- },
2726
- ],
2727
- },
2728
- managedPolicies: [
2729
- ManagedPolicy.fromAwsManagedPolicyName("AmazonQDeveloperAccess")
2730
- .managedPolicyArn,
2731
- ManagedPolicy.fromAwsManagedPolicyName("AWSManagementConsoleBasicUserAccess").managedPolicyArn,
2732
- ManagedPolicy.fromAwsManagedPolicyName("ReadOnlyAccess")
2733
- .managedPolicyArn,
2734
- ],
2735
- sessionDuration: Duration.hours(12).toIsoString(),
2736
- tags: [
2737
- {
2738
- key: CDK$2.TAG.SERVICE,
2739
- value: CDK$2.SERVICE.SSO,
2740
- },
2741
- {
2742
- key: CDK$2.TAG.ROLE,
2743
- value: CDK$2.ROLE.SECURITY,
2744
- },
2745
- ],
2746
- });
2747
- this.developerPermissionSet = new CfnPermissionSet(this, "DeveloperPermissionSet", {
2748
- // Required
2749
- instanceArn: iamIdentityCenterArn,
2750
- name: "Developer",
2751
- // Optional
2752
- description: "Administrative access with limited restrictions",
2753
- inlinePolicy: {
2754
- Version: "2012-10-17",
2755
- Statement: [
2756
- {
2757
- Effect: "Allow",
2758
- Action: [
2759
- "budgets:*",
2760
- "ce:*",
2761
- "cloudformation:*",
2762
- "cloudwatch:*",
2763
- "cost-optimization-hub:*",
2764
- "ec2:*",
2765
- "iam:Get*",
2766
- "iam:List*",
2767
- "iam:PassRole",
2768
- "lambda:*",
2769
- "logs:*",
2770
- "pipes:*",
2771
- "s3:*",
2772
- "secretsmanager:*",
2773
- "securityhub:*",
2774
- "servicecatalog:*",
2775
- "sns:*",
2776
- "sqs:*",
2777
- "states:*",
2778
- "tag:*",
2779
- "uxc:*",
2780
- "xray:*",
2781
- ],
2782
- Resource: "*",
2783
- },
2784
- ],
2785
- },
2786
- managedPolicies: [
2787
- ManagedPolicy.fromAwsManagedPolicyName("AmazonQDeveloperAccess")
2788
- .managedPolicyArn,
2789
- ManagedPolicy.fromAwsManagedPolicyName("AWSManagementConsoleBasicUserAccess").managedPolicyArn,
2790
- ManagedPolicy.fromAwsManagedPolicyName("ReadOnlyAccess")
2791
- .managedPolicyArn,
2792
- ManagedPolicy.fromAwsManagedPolicyName("job-function/SystemAdministrator").managedPolicyArn,
2793
- ],
2794
- sessionDuration: Duration.hours(4).toIsoString(),
2795
- tags: [
2796
- {
2797
- key: CDK$2.TAG.SERVICE,
2798
- value: CDK$2.SERVICE.SSO,
2799
- },
2800
- {
2801
- key: CDK$2.TAG.ROLE,
2802
- value: CDK$2.ROLE.SECURITY,
2803
- },
2804
- ],
2805
- });
2806
- // Map permission set names to their ARNs and labels
2807
- const permissionSetMap = {
2808
- Administrator: {
2809
- arn: this.administratorPermissionSet.attrPermissionSetArn,
2810
- label: "Administrator",
2811
- },
2812
- Analyst: {
2813
- arn: this.analystPermissionSet.attrPermissionSetArn,
2814
- label: "Analyst",
2815
- },
2816
- Developer: {
2817
- arn: this.developerPermissionSet.attrPermissionSetArn,
2818
- label: "Developer",
2819
- },
2820
- };
2821
- //
2822
- // Assignments
2823
- //
2824
- // Helper function to create assignments for a group
2825
- const createAssignments = (groupId, accountAssignments) => {
2826
- if (!groupId || !accountAssignments) {
2827
- return; // Skip if group ID or assignments not provided
2828
- }
2829
- Object.keys(accountAssignments).forEach((accountId) => {
2830
- const permissionSetNames = accountAssignments[accountId];
2831
- permissionSetNames.forEach((permissionSetName) => {
2832
- const permissionSet = permissionSetMap[permissionSetName];
2833
- if (!permissionSet) {
2834
- throw new ConfigurationError(`Unknown permission set: ${permissionSetName}. Valid options: ${Object.keys(permissionSetMap).join(", ")}`);
2835
- }
2836
- const accountAssignment = new CfnAssignment(this, `AccountAssignment-${accountId}-${permissionSet.label}Role-${groupId}Group`, {
2837
- // Required
2838
- instanceArn: iamIdentityCenterArn,
2839
- permissionSetArn: permissionSet.arn,
2840
- principalId: groupId,
2841
- principalType: CDK$2.PRINCIPAL_TYPE.GROUP,
2842
- targetId: accountId,
2843
- targetType: CDK$2.TARGET_TYPE.AWS_ACCOUNT,
2844
- });
2845
- Tags.of(accountAssignment).add(CDK$2.TAG.SERVICE, CDK$2.SERVICE.SSO);
2846
- Tags.of(accountAssignment).add(CDK$2.TAG.ROLE, CDK$2.ROLE.SECURITY);
2847
- });
2848
- });
2849
- };
2850
- // Create assignments for each group
2851
- createAssignments(administratorGroupId, administratorAccountAssignments);
2852
- createAssignments(analystGroupId, analystAccountAssignments);
2853
- createAssignments(developerGroupId, developerAccountAssignments);
2854
- }
2855
- }
2856
-
2857
- //
2858
- //
2859
- // Constants
2860
- //
2861
- const DEFAULT_APPLICATION_ID = "arn:aws:serverlessrepo:us-east-2:004480582608:applications/SSOSync";
2862
- const DEFAULT_APPLICATION_VERSION = "2.3.3";
2863
- const DEFAULT_GOOGLE_GROUP_MATCH = "name:AWS*";
2864
- //
2865
- //
2866
- // Class
2867
- //
2868
- class JaypieSsoSyncApplication extends Construct {
2869
- constructor(scope, id = "SsoSyncApplication", props = {}) {
2870
- super(scope, id);
2871
- const { googleAdminEmail, googleAdminEmailEnvKey = "CDK_ENV_SSOSYNC_GOOGLE_ADMIN_EMAIL", googleCredentials, googleCredentialsEnvKey = "CDK_ENV_SSOSYNC_GOOGLE_CREDENTIALS", googleGroupMatch, googleGroupMatchEnvKey = "CDK_ENV_SSOSYNC_GOOGLE_GROUP_MATCH", identityStoreId, identityStoreIdEnvKey = "CDK_ENV_SSOSYNC_IDENTITY_STORE_ID", scimEndpointAccessToken, scimEndpointAccessTokenEnvKey = "CDK_ENV_SCIM_ENDPOINT_ACCESS_TOKEN", scimEndpointUrl, scimEndpointUrlEnvKey = "CDK_ENV_SSOSYNC_SCIM_ENDPOINT_URL", semanticVersion, semanticVersionEnvKey = "CDK_ENV_SSOSYNC_SEMANTIC_VERSION", ssoSyncApplicationId = DEFAULT_APPLICATION_ID, tags, } = props;
2872
- // Resolve all values from props or environment variables
2873
- const resolvedGoogleAdminEmail = googleAdminEmail || process.env[googleAdminEmailEnvKey];
2874
- const resolvedGoogleCredentials = googleCredentials || process.env[googleCredentialsEnvKey];
2875
- const resolvedGoogleGroupMatch = googleGroupMatch ||
2876
- process.env[googleGroupMatchEnvKey] ||
2877
- DEFAULT_GOOGLE_GROUP_MATCH;
2878
- const resolvedIdentityStoreId = identityStoreId || process.env[identityStoreIdEnvKey];
2879
- const resolvedScimEndpointAccessToken = scimEndpointAccessToken || process.env[scimEndpointAccessTokenEnvKey];
2880
- const resolvedScimEndpointUrl = scimEndpointUrl || process.env[scimEndpointUrlEnvKey];
2881
- const resolvedSemanticVersion = semanticVersion ||
2882
- process.env[semanticVersionEnvKey] ||
2883
- DEFAULT_APPLICATION_VERSION;
2884
- // Validate required parameters
2885
- const missingParams = [];
2886
- if (!resolvedGoogleAdminEmail) {
2887
- missingParams.push(`googleAdminEmail or ${googleAdminEmailEnvKey} environment variable`);
2888
- }
2889
- if (!resolvedGoogleCredentials) {
2890
- missingParams.push(`googleCredentials or ${googleCredentialsEnvKey} environment variable`);
2891
- }
2892
- if (!resolvedIdentityStoreId) {
2893
- missingParams.push(`identityStoreId or ${identityStoreIdEnvKey} environment variable`);
2894
- }
2895
- if (!resolvedScimEndpointAccessToken) {
2896
- missingParams.push(`scimEndpointAccessToken or ${scimEndpointAccessTokenEnvKey} environment variable`);
2897
- }
2898
- if (!resolvedScimEndpointUrl) {
2899
- missingParams.push(`scimEndpointUrl or ${scimEndpointUrlEnvKey} environment variable`);
2900
- }
2901
- if (missingParams.length > 0) {
2902
- throw new ConfigurationError(`JaypieSsoSyncApplication missing required configuration: ${missingParams.join(", ")}`);
2903
- }
2904
- // Create the SSO Sync Application
2905
- // Type assertion is safe because we validated all required values above
2906
- this._application = new CfnApplication(this, "Application", {
2907
- location: {
2908
- applicationId: ssoSyncApplicationId,
2909
- semanticVersion: resolvedSemanticVersion,
2910
- },
2911
- parameters: {
2912
- GoogleAdminEmail: resolvedGoogleAdminEmail,
2913
- GoogleCredentials: resolvedGoogleCredentials,
2914
- GoogleGroupMatch: resolvedGoogleGroupMatch,
2915
- IdentityStoreID: resolvedIdentityStoreId,
2916
- Region: Stack.of(this).region,
2917
- SCIMEndpointAccessToken: resolvedScimEndpointAccessToken,
2918
- SCIMEndpointUrl: resolvedScimEndpointUrl,
2919
- },
2920
- });
2921
- // Add tags
2922
- const defaultTags = {
2923
- [CDK$2.TAG.ROLE]: CDK$2.ROLE.SECURITY,
2924
- };
2925
- const allTags = { ...defaultTags, ...tags };
2926
- Object.entries(allTags).forEach(([key, value]) => {
2927
- Tags.of(this._application).add(key, value);
2928
- });
2929
- }
2930
- get application() {
2931
- return this._application;
2932
- }
2933
- }
2934
-
2935
- class JaypieWebDeploymentBucket extends Construct {
2936
- constructor(scope, id, props = {}) {
2937
- super(scope, id);
2938
- const roleTag = props.roleTag || CDK$2.ROLE.HOSTING;
2939
- // Environment variable validation
2940
- if (process.env.CDK_ENV_WEB_SUBDOMAIN &&
2941
- !isValidSubdomain(process.env.CDK_ENV_WEB_SUBDOMAIN)) {
2942
- throw new ConfigurationError("CDK_ENV_WEB_SUBDOMAIN is not a valid subdomain");
2943
- }
2944
- if (process.env.CDK_ENV_WEB_HOSTED_ZONE &&
2945
- !isValidHostname$1(process.env.CDK_ENV_WEB_HOSTED_ZONE)) {
2946
- throw new ConfigurationError("CDK_ENV_WEB_HOSTED_ZONE is not a valid hostname");
2947
- }
2948
- if (process.env.CDK_ENV_HOSTED_ZONE &&
2949
- !isValidHostname$1(process.env.CDK_ENV_HOSTED_ZONE)) {
2950
- throw new ConfigurationError("CDK_ENV_HOSTED_ZONE is not a valid hostname");
2951
- }
2952
- // Determine host from props or environment
2953
- let host = props.host;
2954
- if (!host) {
2955
- try {
2956
- host =
2957
- process.env.CDK_ENV_WEB_HOST ||
2958
- mergeDomain(process.env.CDK_ENV_WEB_SUBDOMAIN || "", process.env.CDK_ENV_WEB_HOSTED_ZONE ||
2959
- process.env.CDK_ENV_HOSTED_ZONE ||
2960
- "");
2961
- }
2962
- catch {
2963
- host = undefined;
2964
- }
2965
- }
2966
- if (host && !isValidHostname$1(host)) {
2967
- throw new ConfigurationError("Host is not a valid hostname");
2968
- }
2969
- // Determine zone from props or environment
2970
- const zone = props.zone ||
2971
- process.env.CDK_ENV_WEB_HOSTED_ZONE ||
2972
- process.env.CDK_ENV_HOSTED_ZONE;
2973
- // Create the S3 bucket
2974
- this.bucket = new s3.Bucket(this, "DestinationBucket", {
2975
- accessControl: s3.BucketAccessControl.BUCKET_OWNER_FULL_CONTROL,
2976
- autoDeleteObjects: true,
2977
- blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS_ONLY,
2978
- bucketName: props.name || constructEnvName("web"),
2979
- publicReadAccess: true,
2980
- removalPolicy: RemovalPolicy.DESTROY,
2981
- versioned: false,
2982
- websiteErrorDocument: "index.html",
2983
- websiteIndexDocument: "index.html",
2984
- ...props,
2985
- });
2986
- // Delegate IBucket properties to the bucket
2987
- this.bucketArn = this.bucket.bucketArn;
2988
- this.bucketDomainName = this.bucket.bucketDomainName;
2989
- this.bucketDualStackDomainName = this.bucket.bucketDualStackDomainName;
2990
- this.bucketName = this.bucket.bucketName;
2991
- this.bucketRegionalDomainName = this.bucket.bucketRegionalDomainName;
2992
- this.bucketWebsiteDomainName = this.bucket.bucketWebsiteDomainName;
2993
- this.bucketWebsiteUrl = this.bucket.bucketWebsiteUrl;
2994
- this.encryptionKey = this.bucket.encryptionKey;
2995
- this.isWebsite = this.bucket.isWebsite;
2996
- this.notificationsHandlerRole = undefined;
2997
- this.policy = this.bucket.policy;
2998
- Tags.of(this.bucket).add(CDK$2.TAG.ROLE, roleTag);
2999
- // Create deployment role if repository is configured
3000
- let repo;
3001
- if (process.env.CDK_ENV_REPO) {
3002
- repo = `repo:${process.env.CDK_ENV_REPO}:*`;
3003
- }
3004
- if (repo) {
3005
- const bucketDeployRole = new Role(this, "DestinationBucketDeployRole", {
3006
- assumedBy: new FederatedPrincipal(Fn.importValue(CDK$2.IMPORT.OIDC_PROVIDER), {
3007
- StringLike: {
3008
- "token.actions.githubusercontent.com:sub": repo,
3009
- },
3010
- }, "sts:AssumeRoleWithWebIdentity"),
3011
- maxSessionDuration: Duration.hours(1),
3012
- });
3013
- Tags.of(bucketDeployRole).add(CDK$2.TAG.ROLE, CDK$2.ROLE.DEPLOY);
3014
- // Allow the role to write to the bucket
3015
- bucketDeployRole.addToPolicy(new PolicyStatement({
3016
- effect: Effect.ALLOW,
3017
- actions: [
3018
- "s3:DeleteObject",
3019
- "s3:GetObject",
3020
- "s3:ListObjectsV2",
3021
- "s3:PutObject",
3022
- ],
3023
- resources: [`${this.bucket.bucketArn}/*`],
3024
- }));
3025
- bucketDeployRole.addToPolicy(new PolicyStatement({
3026
- effect: Effect.ALLOW,
3027
- actions: ["s3:ListBucket"],
3028
- resources: [this.bucket.bucketArn],
3029
- }));
3030
- // Allow the role to describe the current stack
3031
- const stack = Stack.of(this);
3032
- bucketDeployRole.addToPolicy(new PolicyStatement({
3033
- actions: ["cloudformation:DescribeStacks"],
3034
- effect: Effect.ALLOW,
3035
- resources: [
3036
- `arn:aws:cloudformation:${stack.region}:${stack.account}:stack/${stack.stackName}/*`,
3037
- ],
3038
- }));
3039
- this.deployRoleArn = bucketDeployRole.roleArn;
3040
- // Output the deploy role ARN
3041
- new CfnOutput(this, "DestinationBucketDeployRoleArn", {
3042
- value: bucketDeployRole.roleArn,
3043
- });
3044
- }
3045
- // Create CloudFront distribution and certificate if host and zone are provided
3046
- if (host && zone) {
3047
- let hostedZone;
3048
- if (typeof zone === "string") {
3049
- hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
3050
- domainName: zone,
3051
- });
3052
- }
3053
- else if (zone instanceof JaypieHostedZone) {
3054
- hostedZone = zone.hostedZone;
3055
- }
3056
- else {
3057
- hostedZone = zone;
3058
- }
3059
- // Create certificate if not provided
3060
- if (props.certificate !== false) {
3061
- this.certificate =
3062
- typeof props.certificate === "object"
3063
- ? props.certificate
3064
- : new acm.Certificate(this, "Certificate", {
3065
- domainName: host,
3066
- validation: acm.CertificateValidation.fromDns(hostedZone),
3067
- });
3068
- new CfnOutput(this, "CertificateArn", {
3069
- value: this.certificate.certificateArn,
3070
- });
3071
- Tags.of(this.certificate).add(CDK$2.TAG.ROLE, roleTag);
3072
- }
3073
- // Create CloudFront distribution
3074
- this.distribution = new cloudfront.Distribution(this, "Distribution", {
3075
- defaultBehavior: {
3076
- cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
3077
- origin: new origins.S3StaticWebsiteOrigin(this.bucket),
3078
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
3079
- },
3080
- certificate: this.certificate,
3081
- domainNames: [host],
3082
- });
3083
- Tags.of(this.distribution).add(CDK$2.TAG.ROLE, roleTag);
3084
- // If this is production, enable caching on everything but index.html
3085
- if (isProductionEnv()) {
3086
- this.distribution.addBehavior("/*", new origins.S3StaticWebsiteOrigin(this.bucket), {
3087
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
3088
- cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
3089
- });
3090
- }
3091
- // Create DNS record
3092
- const record = new route53.ARecord(this, "AliasRecord", {
3093
- recordName: host,
3094
- target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
3095
- zone: hostedZone,
3096
- });
3097
- Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
3098
- this.distributionDomainName = this.distribution.distributionDomainName;
3099
- }
3100
- }
3101
- // Implement remaining IBucket methods by delegating to the bucket
3102
- addEventNotification(event, dest, ...filters) {
3103
- this.bucket.addEventNotification(event, dest, ...filters);
3104
- }
3105
- addObjectCreatedNotification(dest, ...filters) {
3106
- this.bucket.addObjectCreatedNotification(dest, ...filters);
3107
- }
3108
- addObjectRemovedNotification(dest, ...filters) {
3109
- this.bucket.addObjectRemovedNotification(dest, ...filters);
3110
- }
3111
- addToResourcePolicy(permission) {
3112
- return this.bucket.addToResourcePolicy(permission);
3113
- }
3114
- arnForObjects(keyPattern) {
3115
- return this.bucket.arnForObjects(keyPattern);
3116
- }
3117
- grantDelete(identity, objectsKeyPattern) {
3118
- return this.bucket.grantDelete(identity, objectsKeyPattern);
3119
- }
3120
- grantPublicAccess(allowedActions, keyPrefix) {
3121
- return keyPrefix
3122
- ? this.bucket.grantPublicAccess(allowedActions, keyPrefix)
3123
- : this.bucket.grantPublicAccess(allowedActions);
3124
- }
3125
- grantPut(identity, objectsKeyPattern) {
3126
- return this.bucket.grantPut(identity, objectsKeyPattern);
3127
- }
3128
- grantPutAcl(identity, objectsKeyPattern) {
3129
- return this.bucket.grantPutAcl(identity, objectsKeyPattern);
3130
- }
3131
- grantRead(identity, objectsKeyPattern) {
3132
- return this.bucket.grantRead(identity, objectsKeyPattern);
3133
- }
3134
- grantReadWrite(identity, objectsKeyPattern) {
3135
- return this.bucket.grantReadWrite(identity, objectsKeyPattern);
3136
- }
3137
- grantWrite(identity, objectsKeyPattern) {
3138
- return this.bucket.grantWrite(identity, objectsKeyPattern);
3139
- }
3140
- grantReplicationPermission(identity, props) {
3141
- return this.bucket.grantReplicationPermission(identity, props);
3142
- }
3143
- s3UrlForObject(key) {
3144
- return this.bucket.s3UrlForObject(key);
3145
- }
3146
- urlForObject(key) {
3147
- return this.bucket.urlForObject(key);
3148
- }
3149
- virtualHostedUrlForObject(key, options) {
3150
- return this.bucket.virtualHostedUrlForObject(key, options);
3151
- }
3152
- transferAccelerationUrlForObject(key) {
3153
- return this.bucket.transferAccelerationUrlForObject(key);
3154
- }
3155
- onCloudTrailEvent(id, options) {
3156
- return this.bucket.onCloudTrailEvent(id, options);
3157
- }
3158
- onCloudTrailPutObject(id, options) {
3159
- return this.bucket.onCloudTrailPutObject(id, options);
3160
- }
3161
- onCloudTrailWriteObject(id, options) {
3162
- return this.bucket.onCloudTrailWriteObject(id, options);
3163
- }
3164
- addCorsRule(rule) {
3165
- this.bucket.addCorsRule(rule);
3166
- }
3167
- addInventory(inventory) {
3168
- this.bucket.addInventory(inventory);
3169
- }
3170
- addLifecycleRule(rule) {
3171
- this.bucket.addLifecycleRule(rule);
3172
- }
3173
- addMetric(metric) {
3174
- this.bucket.addMetric(metric);
3175
- }
3176
- enableEventBridgeNotification() {
3177
- this.bucket.enableEventBridgeNotification();
3178
- }
3179
- addReplicationPolicy(policy) {
3180
- this.bucket.addReplicationPolicy(policy);
3181
- }
3182
- get stack() {
3183
- return this.bucket.stack;
3184
- }
3185
- get env() {
3186
- return this.bucket.env;
3187
- }
3188
- applyRemovalPolicy(policy) {
3189
- this.bucket.applyRemovalPolicy(policy);
3190
- }
3191
- get bucketRef() {
3192
- return {
3193
- bucketArn: this.bucket.bucketArn,
3194
- bucketName: this.bucket.bucketName,
3195
- };
3196
- }
3197
- }
3198
-
3199
- class JaypieStaticWebBucket extends JaypieWebDeploymentBucket {
3200
- constructor(scope, id, props = {}) {
3201
- // Handle overloaded signatures: (scope), (scope, props), (scope, id, props)
3202
- let resolvedId;
3203
- let resolvedProps;
3204
- if (typeof id === "string") {
3205
- resolvedId = id;
3206
- resolvedProps = props;
3207
- }
3208
- else if (typeof id === "object") {
3209
- resolvedId = "JaypieStaticWebBucket";
3210
- resolvedProps = id;
3211
- }
3212
- else {
3213
- resolvedId = "JaypieStaticWebBucket";
3214
- resolvedProps = props;
3215
- }
3216
- const host = resolvedProps.host ?? envHostname({ subdomain: "static" });
3217
- const name = resolvedProps.name ?? constructEnvName("static");
3218
- const roleTag = resolvedProps.roleTag ?? CDK$2.ROLE.HOSTING;
3219
- // Only use default zone if zone is not explicitly provided (including undefined)
3220
- const zone = "zone" in resolvedProps
3221
- ? resolvedProps.zone
3222
- : process.env.CDK_ENV_DOMAIN || process.env.CDK_ENV_HOSTED_ZONE;
3223
- super(scope, resolvedId, {
3224
- ...resolvedProps,
3225
- host,
3226
- name,
3227
- roleTag,
3228
- zone,
3229
- });
3230
- }
3231
- }
3232
-
3233
- class JaypieTraceSigningKeySecret extends JaypieEnvSecret {
3234
- constructor(scope, id = "TraceSigningKey", props) {
3235
- const defaultProps = {
3236
- envKey: "TRACE_SIGNING_KEY",
3237
- roleTag: CDK$2.ROLE.API,
3238
- vendorTag: CDK$2.VENDOR.KNOWTRACE,
3239
- ...props,
3240
- };
3241
- super(scope, id, defaultProps);
3242
- }
3243
- }
3244
-
3245
- export { CDK$2 as CDK, JaypieAccountLoggingBucket, JaypieApiGateway, JaypieAppStack, JaypieBucketQueuedLambda, JaypieDatadogBucket, JaypieDatadogForwarder, JaypieDatadogSecret, JaypieDistribution, JaypieDnsRecord, JaypieEnvSecret, JaypieEventsRule, JaypieExpressLambda, JaypieGitHubDeployRole, JaypieHostedZone, JaypieInfrastructureStack, JaypieLambda, JaypieMongoDbSecret, JaypieNextJs, JaypieOpenAiSecret, JaypieOrganizationTrail, JaypieQueuedLambda, JaypieSsoPermissions, JaypieSsoSyncApplication, JaypieStack, JaypieStaticWebBucket, JaypieTraceSigningKeySecret, JaypieWebDeploymentBucket, addDatadogLayers, constructEnvName, constructStackName, constructTagger, envHostname, extendDatadogRole, isEnv, isProductionEnv, isSandboxEnv, isValidHostname$1 as isValidHostname, isValidSubdomain, jaypieLambdaEnv, mergeDomain, resolveDatadogForwarderFunction, resolveDatadogLayers, resolveDatadogLoggingDestination, resolveHostedZone, resolveParamsAndSecrets };
3246
- //# sourceMappingURL=index.js.map