@jaypie/constructs 1.1.64 → 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 +2 -2
  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 -41
  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 -77
  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 -3335
  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 -41
  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 -77
  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 -3259
  131. package/dist/esm/index.js.map +0 -1
package/dist/esm/index.js DELETED
@@ -1,3259 +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 = new lambda.Runtime("nodejs24.x", lambda.RuntimeFamily.NODEJS, {
874
- supportsInlineCode: true,
875
- }), runtimeManagementMode, secrets = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, vpc, vpcSubnets, } = props;
876
- // Get base environment with defaults
877
- const environment = jaypieLambdaEnv({ initialEnvironment });
878
- const codeAsset = typeof code === "string" ? lambda.Code.fromAsset(code) : code;
879
- // Create a working copy of layers
880
- const resolvedLayers = [...layers];
881
- // Process secrets environment variables
882
- const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
883
- ...acc,
884
- [`SECRET_${key}`]: secret.secretName,
885
- }), {});
886
- // Process JaypieEnvSecret array
887
- const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
888
- if (secret.envKey) {
889
- return {
890
- ...acc,
891
- [`SECRET_${secret.envKey}`]: secret.secretName,
892
- };
893
- }
894
- return acc;
895
- }, {});
896
- // Add ParamsAndSecrets layer if configured
897
- const resolvedParamsAndSecrets = resolveParamsAndSecrets({
898
- paramsAndSecrets,
899
- options: paramsAndSecretsOptions,
900
- });
901
- // Create LogGroup if not provided
902
- const resolvedLogGroup = logGroup ??
903
- new logs.LogGroup(this, "LogGroup", {
904
- retention: logRetention,
905
- removalPolicy: RemovalPolicy.DESTROY,
906
- });
907
- // Create Lambda Function
908
- this._lambda = new lambda.Function(this, "Function", {
909
- allowAllOutbound,
910
- allowPublicSubnet,
911
- architecture,
912
- code: codeAsset,
913
- deadLetterQueue,
914
- deadLetterQueueEnabled,
915
- deadLetterTopic,
916
- description,
917
- environment: {
918
- ...environment,
919
- ...secretsEnvironment,
920
- ...jaypieSecretsEnvironment,
921
- },
922
- ephemeralStorageSize,
923
- filesystem,
924
- handler,
925
- initialPolicy,
926
- layers: resolvedLayers,
927
- logGroup: resolvedLogGroup,
928
- maxEventAge,
929
- memorySize,
930
- paramsAndSecrets: resolvedParamsAndSecrets,
931
- profiling,
932
- profilingGroup,
933
- reservedConcurrentExecutions,
934
- retryAttempts,
935
- runtime,
936
- runtimeManagementMode,
937
- securityGroups,
938
- timeout: typeof timeout === "number" ? Duration.seconds(timeout) : timeout,
939
- tracing,
940
- vpc,
941
- vpcSubnets,
942
- // Enable auto-publishing of versions when using provisioned concurrency
943
- currentVersionOptions: provisionedConcurrentExecutions !== undefined
944
- ? {
945
- removalPolicy: RemovalPolicy.RETAIN,
946
- description: "Auto-published version for provisioned concurrency",
947
- // Don't set provisioned concurrency here - it will be set on the alias
948
- }
949
- : undefined,
950
- });
951
- addDatadogLayers(this._lambda, { datadogApiKeyArn });
952
- // Grant secret read permissions
953
- Object.values(envSecrets).forEach((secret) => {
954
- secret.grantRead(this._lambda);
955
- });
956
- // Grant read permissions for JaypieEnvSecrets
957
- secrets.forEach((secret) => {
958
- secret.grantRead(this._lambda);
959
- });
960
- // Configure provisioned concurrency if specified
961
- if (provisionedConcurrentExecutions !== undefined) {
962
- // Use currentVersion which is auto-published with proper configuration
963
- const version = this._lambda.currentVersion;
964
- // Create alias for provisioned concurrency
965
- this._provisioned = new lambda.Alias(this, "ProvisionedAlias", {
966
- aliasName: "provisioned",
967
- version,
968
- provisionedConcurrentExecutions,
969
- });
970
- // Add explicit dependencies to ensure proper creation order
971
- this._provisioned.node.addDependency(version);
972
- }
973
- if (roleTag) {
974
- Tags.of(this._lambda).add(CDK$2.TAG.ROLE, roleTag);
975
- }
976
- if (vendorTag) {
977
- Tags.of(this._lambda).add(CDK$2.TAG.VENDOR, vendorTag);
978
- }
979
- // Assign _reference based on provisioned state
980
- this._reference =
981
- this._provisioned !== undefined ? this._provisioned : this._lambda;
982
- }
983
- // Public accessors
984
- get lambda() {
985
- return this._lambda;
986
- }
987
- get provisioned() {
988
- return this._provisioned;
989
- }
990
- get reference() {
991
- return this._reference;
992
- }
993
- // IFunction implementation
994
- get functionArn() {
995
- return this._reference.functionArn;
996
- }
997
- get functionName() {
998
- return this._reference.functionName;
999
- }
1000
- get grantPrincipal() {
1001
- return this._reference.grantPrincipal;
1002
- }
1003
- get role() {
1004
- return this._reference.role;
1005
- }
1006
- get architecture() {
1007
- return this._reference.architecture;
1008
- }
1009
- get connections() {
1010
- return this._reference.connections;
1011
- }
1012
- get isBoundToVpc() {
1013
- return this._reference.isBoundToVpc;
1014
- }
1015
- get latestVersion() {
1016
- return this._reference.latestVersion;
1017
- }
1018
- get permissionsNode() {
1019
- return this._reference.permissionsNode;
1020
- }
1021
- get resourceArnsForGrantInvoke() {
1022
- return this._reference.resourceArnsForGrantInvoke;
1023
- }
1024
- get functionRef() {
1025
- return {
1026
- functionArn: this._reference.functionArn,
1027
- functionName: this._reference.functionName,
1028
- };
1029
- }
1030
- addEventSource(source) {
1031
- this._reference.addEventSource(source);
1032
- }
1033
- addEventSourceMapping(id, options) {
1034
- return this._reference.addEventSourceMapping(id, options);
1035
- }
1036
- addFunctionUrl(options) {
1037
- return this._reference.addFunctionUrl(options);
1038
- }
1039
- addPermission(id, permission) {
1040
- this._reference.addPermission(id, permission);
1041
- }
1042
- addToRolePolicy(statement) {
1043
- this._reference.addToRolePolicy(statement);
1044
- }
1045
- configureAsyncInvoke(options) {
1046
- this._reference.configureAsyncInvoke(options);
1047
- }
1048
- grantInvoke(grantee) {
1049
- return this._reference.grantInvoke(grantee);
1050
- }
1051
- grantInvokeCompositePrincipal(compositePrincipal) {
1052
- return this._reference.grantInvokeCompositePrincipal(compositePrincipal);
1053
- }
1054
- grantInvokeUrl(grantee) {
1055
- return this._reference.grantInvokeUrl(grantee);
1056
- }
1057
- grantInvokeLatestVersion(grantee) {
1058
- return this._reference.grantInvokeLatestVersion(grantee);
1059
- }
1060
- grantInvokeVersion(grantee, version) {
1061
- return this._reference.grantInvokeVersion(grantee, version);
1062
- }
1063
- metric(metricName, props) {
1064
- return this._reference.metric(metricName, props);
1065
- }
1066
- metricDuration(props) {
1067
- return this._reference.metricDuration(props);
1068
- }
1069
- metricErrors(props) {
1070
- return this._reference.metricErrors(props);
1071
- }
1072
- metricInvocations(props) {
1073
- return this._reference.metricInvocations(props);
1074
- }
1075
- metricThrottles(props) {
1076
- return this._reference.metricThrottles(props);
1077
- }
1078
- get env() {
1079
- return {
1080
- account: Stack.of(this).account,
1081
- region: Stack.of(this).region,
1082
- };
1083
- }
1084
- get stack() {
1085
- return this._reference.stack;
1086
- }
1087
- applyRemovalPolicy(policy) {
1088
- this._reference.applyRemovalPolicy(policy);
1089
- }
1090
- addEnvironment(key, value) {
1091
- this._lambda.addEnvironment(key, value);
1092
- }
1093
- }
1094
-
1095
- class JaypieQueuedLambda extends Construct {
1096
- constructor(scope, id, props) {
1097
- super(scope, id);
1098
- 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 = new lambda.Runtime("nodejs24.x", lambda.RuntimeFamily.NODEJS, {
1099
- supportsInlineCode: true,
1100
- }), runtimeManagementMode, secrets = [], securityGroups, timeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), tracing, vendorTag, visibilityTimeout = Duration.seconds(CDK$2.DURATION.LAMBDA_WORKER), vpc, vpcSubnets, } = props;
1101
- // Create SQS Queue
1102
- this._queue = new sqs.Queue(this, "Queue", {
1103
- fifo,
1104
- visibilityTimeout: typeof visibilityTimeout === "number"
1105
- ? Duration.seconds(visibilityTimeout)
1106
- : visibilityTimeout,
1107
- });
1108
- if (roleTag) {
1109
- Tags.of(this._queue).add(CDK$2.TAG.ROLE, roleTag);
1110
- }
1111
- if (vendorTag) {
1112
- Tags.of(this._queue).add(CDK$2.TAG.VENDOR, vendorTag);
1113
- }
1114
- // Create Lambda with JaypieLambda
1115
- this._lambdaConstruct = new JaypieLambda(this, "Function", {
1116
- allowAllOutbound,
1117
- allowPublicSubnet,
1118
- architecture,
1119
- code,
1120
- datadogApiKeyArn,
1121
- deadLetterQueue,
1122
- deadLetterQueueEnabled,
1123
- deadLetterTopic,
1124
- description,
1125
- environment: {
1126
- ...environment,
1127
- CDK_ENV_QUEUE_URL: this._queue.queueUrl,
1128
- },
1129
- envSecrets,
1130
- ephemeralStorageSize,
1131
- filesystem,
1132
- handler,
1133
- initialPolicy,
1134
- layers,
1135
- logGroup,
1136
- logRetention,
1137
- maxEventAge,
1138
- memorySize,
1139
- paramsAndSecrets,
1140
- paramsAndSecretsOptions,
1141
- profiling,
1142
- profilingGroup,
1143
- provisionedConcurrentExecutions,
1144
- reservedConcurrentExecutions,
1145
- retryAttempts,
1146
- roleTag,
1147
- runtime,
1148
- runtimeManagementMode,
1149
- secrets,
1150
- securityGroups,
1151
- timeout,
1152
- tracing,
1153
- vendorTag,
1154
- vpc,
1155
- vpcSubnets,
1156
- });
1157
- // Set up queue and lambda integration
1158
- this._queue.grantConsumeMessages(this._lambdaConstruct);
1159
- this._queue.grantSendMessages(this._lambdaConstruct);
1160
- this._lambdaConstruct.addEventSource(new lambdaEventSources.SqsEventSource(this._queue, {
1161
- batchSize,
1162
- }));
1163
- }
1164
- // Public accessors
1165
- get queue() {
1166
- return this._queue;
1167
- }
1168
- get lambda() {
1169
- return this._lambdaConstruct.lambda;
1170
- }
1171
- // IFunction implementation
1172
- get functionArn() {
1173
- return this._lambdaConstruct.functionArn;
1174
- }
1175
- get functionName() {
1176
- return this._lambdaConstruct.functionName;
1177
- }
1178
- get grantPrincipal() {
1179
- return this._lambdaConstruct.grantPrincipal;
1180
- }
1181
- get role() {
1182
- return this._lambdaConstruct.role;
1183
- }
1184
- get architecture() {
1185
- return this._lambdaConstruct.architecture;
1186
- }
1187
- get connections() {
1188
- return this._lambdaConstruct.connections;
1189
- }
1190
- get isBoundToVpc() {
1191
- return this._lambdaConstruct.isBoundToVpc;
1192
- }
1193
- get latestVersion() {
1194
- return this._lambdaConstruct.latestVersion;
1195
- }
1196
- get permissionsNode() {
1197
- return this._lambdaConstruct.permissionsNode;
1198
- }
1199
- get resourceArnsForGrantInvoke() {
1200
- return this._lambdaConstruct.resourceArnsForGrantInvoke;
1201
- }
1202
- get functionRef() {
1203
- return this._lambdaConstruct.functionRef;
1204
- }
1205
- addEventSource(source) {
1206
- this._lambdaConstruct.addEventSource(source);
1207
- }
1208
- addEventSourceMapping(id, options) {
1209
- return this._lambdaConstruct.addEventSourceMapping(id, options);
1210
- }
1211
- addFunctionUrl(options) {
1212
- return this._lambdaConstruct.addFunctionUrl(options);
1213
- }
1214
- addPermission(id, permission) {
1215
- this._lambdaConstruct.addPermission(id, permission);
1216
- }
1217
- addToRolePolicy(statement) {
1218
- this._lambdaConstruct.addToRolePolicy(statement);
1219
- }
1220
- configureAsyncInvoke(options) {
1221
- this._lambdaConstruct.configureAsyncInvoke(options);
1222
- }
1223
- grantInvoke(grantee) {
1224
- return this._lambdaConstruct.grantInvoke(grantee);
1225
- }
1226
- grantInvokeCompositePrincipal(compositePrincipal) {
1227
- return this._lambdaConstruct.grantInvokeCompositePrincipal(compositePrincipal);
1228
- }
1229
- grantInvokeUrl(grantee) {
1230
- return this._lambdaConstruct.grantInvokeUrl(grantee);
1231
- }
1232
- metric(metricName, props) {
1233
- return this._lambdaConstruct.metric(metricName, props);
1234
- }
1235
- metricDuration(props) {
1236
- return this._lambdaConstruct.metricDuration(props);
1237
- }
1238
- metricErrors(props) {
1239
- return this._lambdaConstruct.metricErrors(props);
1240
- }
1241
- metricInvocations(props) {
1242
- return this._lambdaConstruct.metricInvocations(props);
1243
- }
1244
- metricThrottles(props) {
1245
- return this._lambdaConstruct.metricThrottles(props);
1246
- }
1247
- // Additional IFunction implementation
1248
- grantInvokeLatestVersion(grantee) {
1249
- return this._lambdaConstruct.grantInvokeLatestVersion(grantee);
1250
- }
1251
- grantInvokeVersion(grantee, version) {
1252
- return this._lambdaConstruct.grantInvokeVersion(grantee, version);
1253
- }
1254
- get env() {
1255
- return {
1256
- account: Stack.of(this).account,
1257
- region: Stack.of(this).region,
1258
- };
1259
- }
1260
- get stack() {
1261
- return Stack.of(this);
1262
- }
1263
- applyRemovalPolicy(policy) {
1264
- this._lambdaConstruct.applyRemovalPolicy(policy);
1265
- this._queue.applyRemovalPolicy(policy);
1266
- }
1267
- // IQueue implementation
1268
- get queueRef() {
1269
- return {
1270
- queueUrl: this._queue.queueUrl,
1271
- queueArn: this._queue.queueArn,
1272
- };
1273
- }
1274
- get fifo() {
1275
- return this._queue.fifo;
1276
- }
1277
- get queueArn() {
1278
- return this._queue.queueArn;
1279
- }
1280
- get queueName() {
1281
- return this._queue.queueName;
1282
- }
1283
- get queueUrl() {
1284
- return this._queue.queueUrl;
1285
- }
1286
- get encryptionMasterKey() {
1287
- return this._queue.encryptionMasterKey;
1288
- }
1289
- addToResourcePolicy(statement) {
1290
- return this._queue.addToResourcePolicy(statement);
1291
- }
1292
- grant(grantee, ...actions) {
1293
- return this._queue.grant(grantee, ...actions);
1294
- }
1295
- grantConsumeMessages(grantee) {
1296
- return this._queue.grantConsumeMessages(grantee);
1297
- }
1298
- grantPurge(grantee) {
1299
- return this._queue.grantPurge(grantee);
1300
- }
1301
- grantSendMessages(grantee) {
1302
- return this._queue.grantSendMessages(grantee);
1303
- }
1304
- // Queue metrics
1305
- metricApproximateAgeOfOldestMessage(props) {
1306
- return this._queue.metricApproximateAgeOfOldestMessage(props);
1307
- }
1308
- metricApproximateNumberOfMessagesDelayed(props) {
1309
- return this._queue.metricApproximateNumberOfMessagesDelayed(props);
1310
- }
1311
- metricApproximateNumberOfMessagesNotVisible(props) {
1312
- return this._queue.metricApproximateNumberOfMessagesNotVisible(props);
1313
- }
1314
- metricApproximateNumberOfMessagesVisible(props) {
1315
- return this._queue.metricApproximateNumberOfMessagesVisible(props);
1316
- }
1317
- metricNumberOfEmptyReceives(props) {
1318
- return this._queue.metricNumberOfEmptyReceives(props);
1319
- }
1320
- metricNumberOfMessagesDeleted(props) {
1321
- return this._queue.metricNumberOfMessagesDeleted(props);
1322
- }
1323
- metricNumberOfMessagesReceived(props) {
1324
- return this._queue.metricNumberOfMessagesReceived(props);
1325
- }
1326
- metricNumberOfMessagesSent(props) {
1327
- return this._queue.metricNumberOfMessagesSent(props);
1328
- }
1329
- metricSentMessageSize(props) {
1330
- return this._queue.metricSentMessageSize(props);
1331
- }
1332
- addEnvironment(key, value) {
1333
- this._lambdaConstruct.addEnvironment(key, value);
1334
- }
1335
- }
1336
-
1337
- class JaypieBucketQueuedLambda extends JaypieQueuedLambda {
1338
- constructor(scope, id, props) {
1339
- props.fifo = false; // S3 event notifications are not supported for FIFO queues
1340
- super(scope, id, props);
1341
- const { bucketName, roleTag, vendorTag, bucketOptions = {} } = props;
1342
- // Create S3 Bucket
1343
- this._bucket = new s3.Bucket(this, "Bucket", {
1344
- bucketName: bucketOptions.bucketName || bucketName,
1345
- removalPolicy: bucketOptions.removalPolicy || RemovalPolicy.RETAIN,
1346
- ...bucketOptions,
1347
- });
1348
- // Add tags to bucket
1349
- if (roleTag) {
1350
- Tags.of(this._bucket).add(CDK$2.TAG.ROLE, roleTag);
1351
- }
1352
- if (vendorTag) {
1353
- Tags.of(this._bucket).add(CDK$2.TAG.VENDOR, vendorTag);
1354
- }
1355
- // Add an event notification from the bucket to the queue
1356
- this._bucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3n.SqsDestination(this.queue));
1357
- // Grant the lambda access to the bucket
1358
- this._bucket.grantReadWrite(this);
1359
- // Add environment variable for bucket name
1360
- this.lambda.addEnvironment("CDK_ENV_BUCKET_NAME", this._bucket.bucketName);
1361
- }
1362
- // Public accessors
1363
- get bucket() {
1364
- return this._bucket;
1365
- }
1366
- // IBucket implementation
1367
- get bucketArn() {
1368
- return this._bucket.bucketArn;
1369
- }
1370
- get bucketDomainName() {
1371
- return this._bucket.bucketDomainName;
1372
- }
1373
- get bucketDualStackDomainName() {
1374
- return this._bucket.bucketDualStackDomainName;
1375
- }
1376
- get bucketName() {
1377
- return this._bucket.bucketName;
1378
- }
1379
- get bucketRegionalDomainName() {
1380
- return this._bucket.bucketRegionalDomainName;
1381
- }
1382
- get bucketWebsiteDomainName() {
1383
- return this._bucket.bucketWebsiteDomainName;
1384
- }
1385
- get bucketWebsiteUrl() {
1386
- return this._bucket.bucketWebsiteUrl;
1387
- }
1388
- get encryptionKey() {
1389
- return this._bucket.encryptionKey;
1390
- }
1391
- get isWebsite() {
1392
- return this._bucket.isWebsite || false;
1393
- }
1394
- get policy() {
1395
- return this._bucket.policy;
1396
- }
1397
- addEventNotification(event, dest, ...filters) {
1398
- this._bucket.addEventNotification(event, dest, ...filters);
1399
- }
1400
- addObjectCreatedNotification(dest, ...filters) {
1401
- this._bucket.addObjectCreatedNotification(dest, ...filters);
1402
- }
1403
- addObjectRemovedNotification(dest, ...filters) {
1404
- this._bucket.addObjectRemovedNotification(dest, ...filters);
1405
- }
1406
- addToResourcePolicy(permission) {
1407
- return this._bucket.addToResourcePolicy(permission);
1408
- }
1409
- arnForObjects(objectKeyPattern) {
1410
- return this._bucket.arnForObjects(objectKeyPattern);
1411
- }
1412
- enableEventBridgeNotification() {
1413
- this._bucket.enableEventBridgeNotification();
1414
- }
1415
- grantDelete(grantee, objectsKeyPattern) {
1416
- return this._bucket.grantDelete(grantee, objectsKeyPattern);
1417
- }
1418
- grantPublicAccess(keyPrefix, ...allowedActions) {
1419
- return this._bucket.grantPublicAccess(keyPrefix, ...allowedActions);
1420
- }
1421
- grantPut(grantee, objectsKeyPattern) {
1422
- return this._bucket.grantPut(grantee, objectsKeyPattern);
1423
- }
1424
- grantPutAcl(grantee, objectsKeyPattern) {
1425
- return this._bucket.grantPutAcl(grantee, objectsKeyPattern);
1426
- }
1427
- grantRead(grantee, objectsKeyPattern) {
1428
- return this._bucket.grantRead(grantee, objectsKeyPattern);
1429
- }
1430
- grantReadWrite(grantee, objectsKeyPattern) {
1431
- return this._bucket.grantReadWrite(grantee, objectsKeyPattern);
1432
- }
1433
- grantWrite(grantee, objectsKeyPattern) {
1434
- return this._bucket.grantWrite(grantee, objectsKeyPattern);
1435
- }
1436
- onCloudTrailEvent(id, options) {
1437
- return this._bucket.onCloudTrailEvent(id, options);
1438
- }
1439
- onCloudTrailPutObject(id, options) {
1440
- return this._bucket.onCloudTrailPutObject(id, options);
1441
- }
1442
- onCloudTrailWriteObject(id, options) {
1443
- return this._bucket.onCloudTrailWriteObject(id, options);
1444
- }
1445
- s3UrlForObject(key) {
1446
- return this._bucket.s3UrlForObject(key);
1447
- }
1448
- transferAccelerationUrlForObject(key, options) {
1449
- return this._bucket.transferAccelerationUrlForObject(key, options);
1450
- }
1451
- urlForObject(key) {
1452
- return this._bucket.urlForObject(key);
1453
- }
1454
- virtualHostedUrlForObject(key, options) {
1455
- return this._bucket.virtualHostedUrlForObject(key, options);
1456
- }
1457
- grantReplicationPermission(identity, props) {
1458
- return this._bucket.grantReplicationPermission(identity, props);
1459
- }
1460
- addReplicationPolicy(policy) {
1461
- this._bucket.addReplicationPolicy(policy);
1462
- }
1463
- get bucketRef() {
1464
- return {
1465
- bucketArn: this._bucket.bucketArn,
1466
- bucketName: this._bucket.bucketName,
1467
- };
1468
- }
1469
- // Override applyRemovalPolicy to apply to all resources
1470
- applyRemovalPolicy(policy) {
1471
- super.applyRemovalPolicy(policy);
1472
- this._bucket.applyRemovalPolicy(policy);
1473
- }
1474
- }
1475
-
1476
- class JaypieDatadogBucket extends Construct {
1477
- /**
1478
- * Create a new S3 bucket for Datadog log archiving with automatic IAM permissions
1479
- */
1480
- constructor(scope, idOrProps, propsOrUndefined) {
1481
- // Handle overloaded constructor signatures
1482
- let props;
1483
- let id;
1484
- if (typeof idOrProps === "string") {
1485
- // First param is ID, second is props
1486
- props = propsOrUndefined || {};
1487
- id = idOrProps;
1488
- }
1489
- else {
1490
- // First param is props
1491
- props = idOrProps || {};
1492
- id = props.id || "JaypieDatadogBucket";
1493
- }
1494
- super(scope, id);
1495
- // Extract Jaypie-specific options
1496
- const { bucketId = "DatadogArchiveBucket", bucketScope, grantDatadogAccess = true, project, service = CDK$2.SERVICE.DATADOG, ...bucketProps } = props;
1497
- // Create the bucket using bucketScope (defaults to this) and bucketId
1498
- const effectiveBucketScope = bucketScope || this;
1499
- this.bucket = new Bucket(effectiveBucketScope, bucketId, bucketProps);
1500
- // Add tags to bucket
1501
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.SERVICE, service);
1502
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1503
- if (project) {
1504
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.PROJECT, project);
1505
- }
1506
- // Grant Datadog role access to bucket if enabled
1507
- if (grantDatadogAccess) {
1508
- this.policy = this.grantDatadogRoleBucketAccess({ project, service });
1509
- }
1510
- }
1511
- /**
1512
- * Grants the Datadog IAM role access to this bucket
1513
- *
1514
- * Checks for CDK_ENV_DATADOG_ROLE_ARN environment variable.
1515
- * If found, creates a custom policy with:
1516
- * - s3:ListBucket on bucket
1517
- * - s3:GetObject and s3:PutObject on bucket/*
1518
- *
1519
- * @param options - Configuration options
1520
- * @returns The created Policy, or undefined if CDK_ENV_DATADOG_ROLE_ARN is not set
1521
- */
1522
- grantDatadogRoleBucketAccess(options) {
1523
- const datadogRoleArn = process.env.CDK_ENV_DATADOG_ROLE_ARN;
1524
- // Early return if no Datadog role ARN is configured
1525
- if (!datadogRoleArn) {
1526
- return undefined;
1527
- }
1528
- const { project, service = CDK$2.SERVICE.DATADOG } = options || {};
1529
- // Lookup the Datadog role
1530
- const datadogRole = Role.fromRoleArn(this, "DatadogRole", datadogRoleArn);
1531
- // Build policy statements for bucket access
1532
- const statements = [
1533
- // Allow list bucket
1534
- new PolicyStatement({
1535
- actions: ["s3:ListBucket"],
1536
- resources: [this.bucket.bucketArn],
1537
- }),
1538
- // Allow read and write to the bucket
1539
- new PolicyStatement({
1540
- actions: ["s3:GetObject", "s3:PutObject"],
1541
- resources: [`${this.bucket.bucketArn}/*`],
1542
- }),
1543
- ];
1544
- // Create the custom policy
1545
- const datadogBucketPolicy = new Policy(this, "DatadogBucketPolicy", {
1546
- roles: [datadogRole],
1547
- statements,
1548
- });
1549
- // Add tags
1550
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.SERVICE, service);
1551
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1552
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.VENDOR, CDK$2.VENDOR.DATADOG);
1553
- if (project) {
1554
- cdk.Tags.of(datadogBucketPolicy).add(CDK$2.TAG.PROJECT, project);
1555
- }
1556
- return datadogBucketPolicy;
1557
- }
1558
- }
1559
-
1560
- const DATADOG_FORWARDER_TEMPLATE_URL = "https://datadog-cloudformation-template.s3.amazonaws.com/aws/forwarder/latest.yaml";
1561
- const DEFAULT_RESERVED_CONCURRENCY = "10";
1562
- class JaypieDatadogForwarder extends Construct {
1563
- /**
1564
- * Create a new Datadog forwarder with CloudFormation nested stack
1565
- */
1566
- constructor(scope, idOrProps, propsOrUndefined) {
1567
- // Handle overloaded constructor signatures
1568
- let props;
1569
- let id;
1570
- if (typeof idOrProps === "string") {
1571
- // First param is ID, second is props
1572
- props = propsOrUndefined || {};
1573
- id = idOrProps;
1574
- }
1575
- else {
1576
- // First param is props
1577
- props = idOrProps || {};
1578
- id = props.id || "DatadogForwarder";
1579
- }
1580
- super(scope, id);
1581
- // Resolve options with defaults
1582
- 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;
1583
- // Validate required parameters
1584
- if (!datadogApiKey) {
1585
- throw new Error("Datadog API key is required. Provide via datadogApiKey prop or CDK_ENV_DATADOG_API_KEY environment variable.");
1586
- }
1587
- // Build Datadog tags
1588
- let ddTags = account ? `account:${account}` : "";
1589
- if (additionalTags) {
1590
- ddTags = ddTags ? `${ddTags},${additionalTags}` : additionalTags;
1591
- }
1592
- // Deploy Datadog CloudFormation stack
1593
- this.cfnStack = new CfnStack(this, "Stack", {
1594
- parameters: {
1595
- DdApiKey: datadogApiKey,
1596
- DdTags: ddTags,
1597
- ReservedConcurrency: reservedConcurrency,
1598
- },
1599
- templateUrl,
1600
- });
1601
- // Add tags to stack
1602
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1603
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.SERVICE, service);
1604
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.VENDOR, CDK$2.VENDOR.DATADOG);
1605
- if (project) {
1606
- cdk.Tags.of(this.cfnStack).add(CDK$2.TAG.PROJECT, project);
1607
- }
1608
- // Extract forwarder function from stack outputs
1609
- this.forwarderFunction = lambda.Function.fromFunctionArn(this, "Function", this.cfnStack.getAtt("Outputs.DatadogForwarderArn").toString());
1610
- // Extend Datadog role with custom permissions if enabled
1611
- if (enableRoleExtension) {
1612
- extendDatadogRole(this, { project, service });
1613
- }
1614
- // Create CloudFormation events rule if enabled
1615
- if (enableCloudFormationEvents) {
1616
- this.eventsRule = new Rule(this, "CloudFormationEventsRule", {
1617
- eventPattern: {
1618
- source: ["aws.cloudformation"],
1619
- },
1620
- targets: [
1621
- new LambdaFunction(this.forwarderFunction, {
1622
- event: RuleTargetInput.fromEventPath("$"),
1623
- }),
1624
- ],
1625
- });
1626
- // Add tags to events rule
1627
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
1628
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.SERVICE, service);
1629
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.VENDOR, CDK$2.VENDOR.DATADOG);
1630
- if (project) {
1631
- cdk.Tags.of(this.eventsRule).add(CDK$2.TAG.PROJECT, project);
1632
- }
1633
- }
1634
- // Create CloudFormation output if enabled
1635
- if (createOutput) {
1636
- new cdk.CfnOutput(this, "ForwarderArnOutput", {
1637
- description: "Datadog Log Forwarder Lambda ARN",
1638
- exportName,
1639
- value: this.cfnStack.getAtt("Outputs.DatadogForwarderArn").toString(),
1640
- });
1641
- }
1642
- }
1643
- }
1644
-
1645
- class JaypieDistribution extends Construct {
1646
- constructor(scope, id, props) {
1647
- super(scope, id);
1648
- 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;
1649
- // Validate environment variables
1650
- if (process.env.CDK_ENV_API_SUBDOMAIN &&
1651
- !isValidSubdomain(process.env.CDK_ENV_API_SUBDOMAIN)) {
1652
- throw new Error("CDK_ENV_API_SUBDOMAIN is not a valid subdomain");
1653
- }
1654
- if (process.env.CDK_ENV_API_HOSTED_ZONE &&
1655
- !isValidHostname$1(process.env.CDK_ENV_API_HOSTED_ZONE)) {
1656
- throw new Error("CDK_ENV_API_HOSTED_ZONE is not a valid hostname");
1657
- }
1658
- if (process.env.CDK_ENV_HOSTED_ZONE &&
1659
- !isValidHostname$1(process.env.CDK_ENV_HOSTED_ZONE)) {
1660
- throw new Error("CDK_ENV_HOSTED_ZONE is not a valid hostname");
1661
- }
1662
- // Determine host from props or environment
1663
- let host = propsHost;
1664
- if (!host) {
1665
- try {
1666
- if (process.env.CDK_ENV_API_HOST_NAME) {
1667
- host = process.env.CDK_ENV_API_HOST_NAME;
1668
- }
1669
- else if (process.env.CDK_ENV_API_SUBDOMAIN) {
1670
- host = mergeDomain(process.env.CDK_ENV_API_SUBDOMAIN, process.env.CDK_ENV_API_HOSTED_ZONE ||
1671
- process.env.CDK_ENV_HOSTED_ZONE ||
1672
- "");
1673
- }
1674
- }
1675
- catch {
1676
- host = undefined;
1677
- }
1678
- }
1679
- if (host && !isValidHostname$1(host)) {
1680
- throw new Error("Host is not a valid hostname");
1681
- }
1682
- this.host = host;
1683
- // Determine zone from props or environment
1684
- const zone = propsZone || process.env.CDK_ENV_HOSTED_ZONE;
1685
- // Resolve the origin from handler
1686
- // Check order matters: IFunctionUrl before IOrigin (FunctionUrl also has bind method)
1687
- // IFunction before IFunctionUrl (IFunction doesn't have functionUrlId)
1688
- let origin;
1689
- if (handler) {
1690
- if (this.isIFunction(handler)) {
1691
- // Create FunctionUrl for the Lambda function
1692
- const functionUrl = new lambda.FunctionUrl(this, "FunctionUrl", {
1693
- function: handler,
1694
- authType: lambda.FunctionUrlAuthType.NONE,
1695
- invokeMode,
1696
- });
1697
- this.functionUrl = functionUrl;
1698
- origin = new origins.FunctionUrlOrigin(functionUrl);
1699
- }
1700
- else if (this.isIFunctionUrl(handler)) {
1701
- origin = new origins.FunctionUrlOrigin(handler);
1702
- }
1703
- else if (this.isIOrigin(handler)) {
1704
- origin = handler;
1705
- }
1706
- }
1707
- // Build default behavior
1708
- let defaultBehavior;
1709
- if (propsDefaultBehavior) {
1710
- defaultBehavior = propsDefaultBehavior;
1711
- }
1712
- else if (origin) {
1713
- defaultBehavior = {
1714
- allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
1715
- cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
1716
- origin,
1717
- originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
1718
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
1719
- };
1720
- }
1721
- else {
1722
- throw new Error("Either handler or defaultBehavior must be provided to JaypieDistribution");
1723
- }
1724
- // Resolve hosted zone and certificate
1725
- // Only resolve zone when we need it (for certificate or DNS)
1726
- let hostedZone;
1727
- let certificateToUse;
1728
- if (host && zone && certificateProp !== false) {
1729
- hostedZone = resolveHostedZone(this, { zone });
1730
- if (certificateProp === true) {
1731
- certificateToUse = new acm.Certificate(this, constructEnvName("Certificate"), {
1732
- domainName: host,
1733
- validation: acm.CertificateValidation.fromDns(hostedZone),
1734
- });
1735
- Tags.of(certificateToUse).add(CDK$2.TAG.ROLE, roleTag);
1736
- }
1737
- else if (typeof certificateProp === "object") {
1738
- certificateToUse = certificateProp;
1739
- }
1740
- this.certificate = certificateToUse;
1741
- }
1742
- // Create log bucket if logging is enabled
1743
- let logBucket;
1744
- if (destinationProp !== false) {
1745
- logBucket = new s3.Bucket(this, constructEnvName("LogBucket"), {
1746
- objectOwnership: s3.ObjectOwnership.OBJECT_WRITER,
1747
- removalPolicy: RemovalPolicy.DESTROY,
1748
- autoDeleteObjects: true,
1749
- lifecycleRules: [
1750
- {
1751
- expiration: Duration.days(90),
1752
- transitions: [
1753
- {
1754
- storageClass: s3.StorageClass.INFREQUENT_ACCESS,
1755
- transitionAfter: Duration.days(30),
1756
- },
1757
- ],
1758
- },
1759
- ],
1760
- });
1761
- Tags.of(logBucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.STORAGE);
1762
- // Add S3 notification to Datadog forwarder
1763
- const lambdaDestination = destinationProp === true
1764
- ? new LambdaDestination(resolveDatadogForwarderFunction(this))
1765
- : destinationProp;
1766
- logBucket.addEventNotification(s3.EventType.OBJECT_CREATED, lambdaDestination);
1767
- this.logBucket = logBucket;
1768
- }
1769
- // Create the CloudFront distribution
1770
- this.distribution = new cloudfront.Distribution(this, constructEnvName("Distribution"), {
1771
- defaultBehavior,
1772
- ...(host && certificateToUse
1773
- ? {
1774
- certificate: certificateToUse,
1775
- domainNames: [host],
1776
- }
1777
- : {}),
1778
- ...(logBucket
1779
- ? {
1780
- enableLogging: true,
1781
- logBucket,
1782
- logFilePrefix: "cloudfront-logs/",
1783
- }
1784
- : {}),
1785
- ...distributionProps,
1786
- });
1787
- Tags.of(this.distribution).add(CDK$2.TAG.ROLE, roleTag);
1788
- this.distributionArn = `arn:aws:cloudfront::${Stack.of(this).account}:distribution/${this.distribution.distributionId}`;
1789
- this.distributionDomainName = this.distribution.distributionDomainName;
1790
- this.distributionId = this.distribution.distributionId;
1791
- this.domainName = this.distribution.domainName;
1792
- // Create DNS records if we have host and zone
1793
- if (host && hostedZone) {
1794
- const aRecord = new route53.ARecord(this, "AliasRecord", {
1795
- recordName: host,
1796
- target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
1797
- zone: hostedZone,
1798
- });
1799
- Tags.of(aRecord).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
1800
- const aaaaRecord = new route53.AaaaRecord(this, "AaaaAliasRecord", {
1801
- recordName: host,
1802
- target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
1803
- zone: hostedZone,
1804
- });
1805
- Tags.of(aaaaRecord).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
1806
- }
1807
- }
1808
- // Type guards for handler types
1809
- isIOrigin(handler) {
1810
- return (typeof handler === "object" &&
1811
- handler !== null &&
1812
- "bind" in handler &&
1813
- typeof handler.bind === "function");
1814
- }
1815
- isIFunctionUrl(handler) {
1816
- // FunctionUrl has 'url' property which is the function URL string
1817
- // IFunction does not have 'url' property
1818
- return (typeof handler === "object" &&
1819
- handler !== null &&
1820
- "url" in handler &&
1821
- "functionArn" in handler);
1822
- }
1823
- isIFunction(handler) {
1824
- // IFunction has functionArn and functionName but NOT 'url'
1825
- // (FunctionUrl also has functionArn but also has 'url')
1826
- return (typeof handler === "object" &&
1827
- handler !== null &&
1828
- "functionArn" in handler &&
1829
- "functionName" in handler &&
1830
- !("url" in handler));
1831
- }
1832
- // Implement IDistribution interface
1833
- get env() {
1834
- return {
1835
- account: Stack.of(this).account,
1836
- region: Stack.of(this).region,
1837
- };
1838
- }
1839
- get stack() {
1840
- return this.distribution.stack;
1841
- }
1842
- applyRemovalPolicy(policy) {
1843
- this.distribution.applyRemovalPolicy(policy);
1844
- }
1845
- grant(identity, ...actions) {
1846
- return this.distribution.grant(identity, ...actions);
1847
- }
1848
- grantCreateInvalidation(identity) {
1849
- return this.distribution.grantCreateInvalidation(identity);
1850
- }
1851
- get distributionRef() {
1852
- return {
1853
- distributionId: this.distribution.distributionId,
1854
- };
1855
- }
1856
- }
1857
-
1858
- // It is a consumer if the environment is ephemeral
1859
- function checkEnvIsConsumer(env = process.env) {
1860
- return (env.PROJECT_ENV === CDK$2.ENV.PERSONAL ||
1861
- !!env.CDK_ENV_PERSONAL ||
1862
- /** @deprecated */ env.PROJECT_ENV === "ephemeral" ||
1863
- /** @deprecated */ !!env.CDK_ENV_EPHEMERAL);
1864
- }
1865
- function checkEnvIsProvider(env = process.env) {
1866
- return env.PROJECT_ENV === CDK$2.ENV.SANDBOX;
1867
- }
1868
- function cleanName(name) {
1869
- return name.replace(/[^a-zA-Z0-9:-]/g, "");
1870
- }
1871
- function exportEnvName(name, env = process.env) {
1872
- let rawName;
1873
- if (checkEnvIsProvider(env)) {
1874
- rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
1875
- // Clean the entire name to only allow alphanumeric, colons, and hyphens
1876
- return cleanName(rawName);
1877
- }
1878
- else {
1879
- if (checkEnvIsConsumer(env)) {
1880
- rawName = `env-${CDK$2.ENV.SANDBOX}-${env.PROJECT_KEY}-${name}`;
1881
- }
1882
- else {
1883
- rawName = `env-${env.PROJECT_ENV}-${env.PROJECT_KEY}-${name}`;
1884
- }
1885
- }
1886
- return cleanName(rawName);
1887
- }
1888
- class JaypieEnvSecret extends Construct {
1889
- constructor(scope, idOrEnvKey, props) {
1890
- // Check if idOrEnvKey should be treated as envKey:
1891
- // - No props provided OR props.envKey is not set
1892
- // - AND idOrEnvKey exists as a non-empty string in process.env
1893
- const treatAsEnvKey = (!props || props.envKey === undefined) &&
1894
- typeof process.env[idOrEnvKey] === "string" &&
1895
- process.env[idOrEnvKey] !== "";
1896
- const id = treatAsEnvKey ? `EnvSecret_${idOrEnvKey}` : idOrEnvKey;
1897
- super(scope, id);
1898
- const { consumer = checkEnvIsConsumer(), envKey: envKeyProp, export: exportParam, generateSecretString, provider = checkEnvIsProvider(), roleTag, vendorTag, value, } = props || {};
1899
- const envKey = treatAsEnvKey ? idOrEnvKey : envKeyProp;
1900
- this._envKey = envKey;
1901
- let exportName;
1902
- if (!exportParam) {
1903
- exportName = exportEnvName(id);
1904
- }
1905
- else {
1906
- exportName = cleanName(exportParam);
1907
- }
1908
- if (consumer) {
1909
- const secretName = Fn.importValue(exportName);
1910
- this._secret = secretsmanager.Secret.fromSecretNameV2(this, id, secretName);
1911
- // Add CfnOutput for consumer secrets
1912
- new CfnOutput(this, `ConsumedName`, {
1913
- value: this._secret.secretName,
1914
- });
1915
- }
1916
- else {
1917
- const secretValue = envKey && process.env[envKey] ? process.env[envKey] : value;
1918
- const secretProps = {
1919
- generateSecretString,
1920
- secretStringValue: !generateSecretString && secretValue
1921
- ? SecretValue.unsafePlainText(secretValue)
1922
- : undefined,
1923
- };
1924
- this._secret = new secretsmanager.Secret(this, id, secretProps);
1925
- if (roleTag) {
1926
- Tags.of(this._secret).add(CDK$2.TAG.ROLE, roleTag);
1927
- }
1928
- if (vendorTag) {
1929
- Tags.of(this._secret).add(CDK$2.TAG.VENDOR, vendorTag);
1930
- }
1931
- if (provider) {
1932
- new CfnOutput(this, `ProvidedName`, {
1933
- value: this._secret.secretName,
1934
- exportName,
1935
- });
1936
- }
1937
- else {
1938
- new CfnOutput(this, `CreatedName`, {
1939
- value: this._secret.secretName,
1940
- });
1941
- }
1942
- }
1943
- }
1944
- // IResource implementation
1945
- get stack() {
1946
- return Stack.of(this);
1947
- }
1948
- get env() {
1949
- return {
1950
- account: Stack.of(this).account,
1951
- region: Stack.of(this).region,
1952
- };
1953
- }
1954
- applyRemovalPolicy(policy) {
1955
- this._secret.applyRemovalPolicy(policy);
1956
- }
1957
- // ISecret implementation
1958
- get secretArn() {
1959
- return this._secret.secretArn;
1960
- }
1961
- get secretName() {
1962
- return this._secret.secretName;
1963
- }
1964
- get secretFullArn() {
1965
- return this._secret.secretFullArn;
1966
- }
1967
- get encryptionKey() {
1968
- return this._secret.encryptionKey;
1969
- }
1970
- get secretValue() {
1971
- return this._secret.secretValue;
1972
- }
1973
- secretValueFromJson(key) {
1974
- return this._secret.secretValueFromJson(key);
1975
- }
1976
- grantRead(grantee, versionStages) {
1977
- return this._secret.grantRead(grantee, versionStages);
1978
- }
1979
- grantWrite(grantee) {
1980
- return this._secret.grantWrite(grantee);
1981
- }
1982
- addRotationSchedule(id, options) {
1983
- return this._secret.addRotationSchedule(id, options);
1984
- }
1985
- addToResourcePolicy(statement) {
1986
- return this._secret.addToResourcePolicy(statement);
1987
- }
1988
- denyAccountRootDelete() {
1989
- this._secret.denyAccountRootDelete();
1990
- }
1991
- attach(target) {
1992
- return this._secret.attach(target);
1993
- }
1994
- cfnDynamicReferenceKey(options) {
1995
- return this._secret.cfnDynamicReferenceKey(options);
1996
- }
1997
- get envKey() {
1998
- return this._envKey;
1999
- }
2000
- }
2001
-
2002
- class JaypieDatadogSecret extends JaypieEnvSecret {
2003
- constructor(scope, id = "MongoConnectionString", props) {
2004
- const defaultProps = {
2005
- envKey: "DATADOG_API_KEY",
2006
- roleTag: CDK$2.ROLE.MONITORING,
2007
- vendorTag: CDK$2.VENDOR.DATADOG,
2008
- ...props,
2009
- };
2010
- super(scope, id, defaultProps);
2011
- }
2012
- }
2013
-
2014
- class JaypieDnsRecord extends Construct {
2015
- constructor(scope, id, props) {
2016
- super(scope, id);
2017
- const { comment, recordName, type, values } = props;
2018
- const ttl = props.ttl || cdk.Duration.seconds(CDK$2.DNS.CONFIG.TTL);
2019
- // Resolve the hosted zone (supports both string and IHostedZone)
2020
- const zone = resolveHostedZone(scope, {
2021
- name: `${id}HostedZone`,
2022
- zone: props.zone,
2023
- });
2024
- // Common properties for all record types
2025
- const baseProps = {
2026
- comment,
2027
- recordName,
2028
- ttl,
2029
- zone,
2030
- };
2031
- // Create the appropriate record based on type
2032
- switch (type) {
2033
- case CDK$2.DNS.RECORD.A: {
2034
- if (!Array.isArray(values) || values.length === 0) {
2035
- throw new ConfigurationError("A record requires at least one IP address");
2036
- }
2037
- this.record = new ARecord(this, "Record", {
2038
- ...baseProps,
2039
- target: RecordTarget.fromIpAddresses(...values),
2040
- });
2041
- break;
2042
- }
2043
- case CDK$2.DNS.RECORD.CNAME: {
2044
- if (!Array.isArray(values) || values.length === 0) {
2045
- throw new ConfigurationError("CNAME record requires a domain name");
2046
- }
2047
- this.record = new CnameRecord(this, "Record", {
2048
- ...baseProps,
2049
- domainName: values[0],
2050
- });
2051
- break;
2052
- }
2053
- case CDK$2.DNS.RECORD.MX: {
2054
- if (!Array.isArray(values) || values.length === 0) {
2055
- throw new ConfigurationError("MX record requires at least one mail server");
2056
- }
2057
- this.record = new MxRecord(this, "Record", {
2058
- ...baseProps,
2059
- values: values,
2060
- });
2061
- break;
2062
- }
2063
- case CDK$2.DNS.RECORD.NS: {
2064
- if (!Array.isArray(values) || values.length === 0) {
2065
- throw new ConfigurationError("NS record requires at least one name server");
2066
- }
2067
- this.record = new NsRecord(this, "Record", {
2068
- ...baseProps,
2069
- values: values,
2070
- });
2071
- break;
2072
- }
2073
- case CDK$2.DNS.RECORD.TXT: {
2074
- if (!Array.isArray(values) || values.length === 0) {
2075
- throw new ConfigurationError("TXT record requires at least one value");
2076
- }
2077
- this.record = new TxtRecord(this, "Record", {
2078
- ...baseProps,
2079
- values: values,
2080
- });
2081
- break;
2082
- }
2083
- default:
2084
- throw new ConfigurationError(`Unsupported DNS record type: ${type}. Supported types: A, CNAME, MX, NS, TXT`);
2085
- }
2086
- // Add standard tags to the DNS record
2087
- cdk.Tags.of(this.record).add(CDK$2.TAG.SERVICE, CDK$2.SERVICE.INFRASTRUCTURE);
2088
- cdk.Tags.of(this.record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
2089
- }
2090
- }
2091
-
2092
- class JaypieEventsRule extends Construct {
2093
- /**
2094
- * Create a new EventBridge rule that targets a Lambda function
2095
- */
2096
- constructor(scope, idOrSourceOrProps, propsOrUndefined) {
2097
- // Handle overloaded constructor signatures
2098
- let props;
2099
- let id;
2100
- if (typeof idOrSourceOrProps === "string") {
2101
- // Check if it looks like an AWS source (starts with "aws.")
2102
- if (idOrSourceOrProps.startsWith("aws.")) {
2103
- // First param is source, second is props
2104
- props = propsOrUndefined || {};
2105
- props.source = idOrSourceOrProps;
2106
- // Generate ID from source
2107
- const sourceName = idOrSourceOrProps
2108
- .replace("aws.", "")
2109
- .split(".")
2110
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
2111
- .join("");
2112
- id = props.id || `${sourceName}EventsRule`;
2113
- }
2114
- else {
2115
- // First param is ID, second is props
2116
- props = propsOrUndefined || {};
2117
- id = idOrSourceOrProps;
2118
- }
2119
- }
2120
- else {
2121
- // First param is props
2122
- props = idOrSourceOrProps || {};
2123
- if (props.source) {
2124
- const sourceName = typeof props.source === "string"
2125
- ? props.source
2126
- .replace("aws.", "")
2127
- .split(".")
2128
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
2129
- .join("")
2130
- : "Events";
2131
- id = props.id || `${sourceName}EventsRule`;
2132
- }
2133
- else {
2134
- id = props.id || "EventsRule";
2135
- }
2136
- }
2137
- super(scope, id);
2138
- // Extract Jaypie-specific options
2139
- const { id: _id, project, service = CDK$2.SERVICE.DATADOG, source, targetFunction, vendor = CDK$2.VENDOR.DATADOG, ...ruleProps } = props;
2140
- // Resolve target function
2141
- this.targetFunction =
2142
- targetFunction || resolveDatadogForwarderFunction(scope);
2143
- // Build event pattern if source is specified
2144
- const eventPattern = source
2145
- ? {
2146
- ...ruleProps.eventPattern,
2147
- source: Array.isArray(source) ? source : [source],
2148
- }
2149
- : ruleProps.eventPattern;
2150
- // Build rule props
2151
- const finalRuleProps = {
2152
- ...ruleProps,
2153
- eventPattern,
2154
- targets: [
2155
- new LambdaFunction(this.targetFunction, {
2156
- event: RuleTargetInput.fromEventPath("$"),
2157
- }),
2158
- ],
2159
- };
2160
- // Create the rule
2161
- this.rule = new Rule(this, "Rule", finalRuleProps);
2162
- // Add tags
2163
- cdk.Tags.of(this.rule).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
2164
- cdk.Tags.of(this.rule).add(CDK$2.TAG.SERVICE, service);
2165
- cdk.Tags.of(this.rule).add(CDK$2.TAG.VENDOR, vendor);
2166
- if (project) {
2167
- cdk.Tags.of(this.rule).add(CDK$2.TAG.PROJECT, project);
2168
- }
2169
- }
2170
- }
2171
-
2172
- class JaypieGitHubDeployRole extends Construct {
2173
- constructor(scope, id = "GitHubDeployRole", props = {}) {
2174
- super(scope, id);
2175
- const { oidcProviderArn = Fn.importValue(CDK$2.IMPORT.OIDC_PROVIDER), output = true, repoRestriction: propsRepoRestriction, } = props;
2176
- // Extract account ID from the scope
2177
- const accountId = Stack.of(this).account;
2178
- // Resolve repoRestriction from props or environment variables
2179
- let repoRestriction = propsRepoRestriction;
2180
- if (!repoRestriction) {
2181
- const envRepo = process.env.CDK_ENV_REPO || process.env.PROJECT_REPO;
2182
- if (!envRepo) {
2183
- throw new ConfigurationError("No repoRestriction provided. Set repoRestriction prop, CDK_ENV_REPO, or PROJECT_REPO environment variable");
2184
- }
2185
- // Extract organization from owner/repo format and create org-wide restriction
2186
- const organization = envRepo.split("/")[0];
2187
- repoRestriction = `repo:${organization}/*:*`;
2188
- }
2189
- // Create the IAM role
2190
- this._role = new Role(this, "GitHubActionsRole", {
2191
- assumedBy: new FederatedPrincipal(oidcProviderArn, {
2192
- StringLike: {
2193
- "token.actions.githubusercontent.com:sub": repoRestriction,
2194
- },
2195
- }, "sts:AssumeRoleWithWebIdentity"),
2196
- maxSessionDuration: Duration.hours(1),
2197
- path: "/",
2198
- });
2199
- Tags.of(this._role).add(CDK$2.TAG.ROLE, CDK$2.ROLE.DEPLOY);
2200
- // Allow the role to access the GitHub OIDC provider
2201
- this._role.addToPolicy(new PolicyStatement({
2202
- actions: ["sts:AssumeRoleWithWebIdentity"],
2203
- resources: [`arn:aws:iam::${accountId}:oidc-provider/*`],
2204
- }));
2205
- // Allow the role to deploy CDK apps
2206
- this._role.addToPolicy(new PolicyStatement({
2207
- actions: [
2208
- "cloudformation:CreateStack",
2209
- "cloudformation:DeleteStack",
2210
- "cloudformation:DescribeStackEvents",
2211
- "cloudformation:DescribeStackResource",
2212
- "cloudformation:DescribeStackResources",
2213
- "cloudformation:DescribeStacks",
2214
- "cloudformation:GetTemplate",
2215
- "cloudformation:SetStackPolicy",
2216
- "cloudformation:UpdateStack",
2217
- "cloudformation:ValidateTemplate",
2218
- "iam:PassRole",
2219
- "route53:ListHostedZones*",
2220
- "s3:GetObject",
2221
- "s3:ListBucket",
2222
- ],
2223
- effect: Effect.ALLOW,
2224
- resources: ["*"],
2225
- }));
2226
- this._role.addToPolicy(new PolicyStatement({
2227
- actions: ["iam:PassRole", "sts:AssumeRole"],
2228
- effect: Effect.ALLOW,
2229
- resources: [
2230
- "arn:aws:iam::*:role/cdk-hnb659fds-deploy-role-*",
2231
- "arn:aws:iam::*:role/cdk-hnb659fds-file-publishing-*",
2232
- "arn:aws:iam::*:role/cdk-readOnlyRole",
2233
- ],
2234
- }));
2235
- // Export the ARN of the role
2236
- if (output !== false) {
2237
- const outputId = typeof output === "string" ? output : "GitHubActionsRoleArn";
2238
- new CfnOutput(this, outputId, {
2239
- value: this._role.roleArn,
2240
- });
2241
- }
2242
- }
2243
- get role() {
2244
- return this._role;
2245
- }
2246
- get roleArn() {
2247
- return this._role.roleArn;
2248
- }
2249
- get roleName() {
2250
- return this._role.roleName;
2251
- }
2252
- }
2253
-
2254
- class JaypieExpressLambda extends JaypieLambda {
2255
- constructor(scope, id, props) {
2256
- super(scope, id, {
2257
- timeout: Duration.seconds(CDK$2.DURATION.EXPRESS_API),
2258
- roleTag: CDK$2.ROLE.API,
2259
- ...props,
2260
- });
2261
- }
2262
- }
2263
-
2264
- const SERVICE = {
2265
- ROUTE53: "route53.amazonaws.com",
2266
- };
2267
- /**
2268
- * Check if a string is a valid hostname
2269
- */
2270
- function isValidHostname(str) {
2271
- // Check if it contains a dot and matches hostname pattern
2272
- if (!str.includes("."))
2273
- return false;
2274
- // Basic hostname validation: alphanumeric, hyphens, dots
2275
- // Each label must start and end with alphanumeric
2276
- const hostnameRegex = /^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$/i;
2277
- return hostnameRegex.test(str);
2278
- }
2279
- class JaypieHostedZone extends Construct {
2280
- /**
2281
- * Create a new hosted zone with query logging and optional DNS records
2282
- */
2283
- constructor(scope, idOrProps, propsOrRecords) {
2284
- // Handle overloaded constructor signatures
2285
- let props;
2286
- let id;
2287
- if (typeof idOrProps === "string") {
2288
- // If it's a valid hostname, treat it as zoneName
2289
- if (isValidHostname(idOrProps)) {
2290
- // Third param can be props object or records array
2291
- if (Array.isArray(propsOrRecords)) {
2292
- props = { zoneName: idOrProps, records: propsOrRecords };
2293
- }
2294
- else {
2295
- props = propsOrRecords || { zoneName: idOrProps };
2296
- // Set zoneName if not already set
2297
- if (!props.zoneName) {
2298
- props = { ...props, zoneName: idOrProps };
2299
- }
2300
- }
2301
- // Use id from props if provided, otherwise derive from zoneName
2302
- id = props.id || `${idOrProps}-HostedZone`;
2303
- }
2304
- else {
2305
- // Otherwise treat it as an explicit id
2306
- props = propsOrRecords;
2307
- id = idOrProps;
2308
- }
2309
- }
2310
- else {
2311
- // idOrProps is props
2312
- props = idOrProps;
2313
- id = props.id || `${props.zoneName}-HostedZone`;
2314
- }
2315
- super(scope, id);
2316
- const { zoneName, project } = props;
2317
- const destination = props.destination ?? true;
2318
- const service = props.service || CDK$2.SERVICE.INFRASTRUCTURE;
2319
- // Create the log group
2320
- this.logGroup = new LogGroup(this, "LogGroup", {
2321
- logGroupName: process.env.PROJECT_NONCE
2322
- ? `/aws/route53/${zoneName}-${process.env.PROJECT_NONCE}`
2323
- : `/aws/route53/${zoneName}`,
2324
- retention: RetentionDays.ONE_WEEK,
2325
- });
2326
- // Add tags
2327
- cdk.Tags.of(this.logGroup).add(CDK$2.TAG.SERVICE, service);
2328
- cdk.Tags.of(this.logGroup).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
2329
- if (project) {
2330
- cdk.Tags.of(this.logGroup).add(CDK$2.TAG.PROJECT, project);
2331
- }
2332
- // Grant Route 53 permissions to write to the log group
2333
- this.logGroup.grantWrite(new ServicePrincipal(SERVICE.ROUTE53));
2334
- // Add destination based on configuration
2335
- if (destination !== false) {
2336
- const lambdaDestination = destination === true
2337
- ? resolveDatadogLoggingDestination(scope)
2338
- : destination;
2339
- this.logGroup.addSubscriptionFilter("DatadogLambdaDestination", {
2340
- destination: lambdaDestination,
2341
- filterPattern: FilterPattern.allEvents(),
2342
- });
2343
- }
2344
- // Create the hosted zone
2345
- this.hostedZone = new HostedZone(this, "HostedZone", {
2346
- queryLogsLogGroupArn: this.logGroup.logGroupArn,
2347
- zoneName,
2348
- });
2349
- // Add tags
2350
- cdk.Tags.of(this.hostedZone).add(CDK$2.TAG.SERVICE, service);
2351
- cdk.Tags.of(this.hostedZone).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
2352
- if (project) {
2353
- cdk.Tags.of(this.hostedZone).add(CDK$2.TAG.PROJECT, project);
2354
- }
2355
- // Create DNS records if provided
2356
- this.dnsRecords = [];
2357
- if (props.records) {
2358
- props.records.forEach((recordConfig, index) => {
2359
- const { id, ...recordProps } = recordConfig;
2360
- // Generate a default ID if not provided
2361
- const recordId = id ||
2362
- `${recordProps.type}${recordProps.recordName ? `-${recordProps.recordName}` : ""}-${index}`;
2363
- const dnsRecord = new JaypieDnsRecord(this, recordId, {
2364
- ...recordProps,
2365
- zone: this.hostedZone,
2366
- });
2367
- this.dnsRecords.push(dnsRecord);
2368
- });
2369
- }
2370
- }
2371
- }
2372
-
2373
- const CDK = {
2374
- TAG: {
2375
- STACK_SHA: "stackSha",
2376
- },
2377
- };
2378
- class JaypieInfrastructureStack extends JaypieStack {
2379
- constructor(scope, id, props = {}) {
2380
- const { key = "infra", ...stackProps } = props;
2381
- // Handle stackName
2382
- if (!stackProps.stackName) {
2383
- stackProps.stackName = constructStackName(key);
2384
- }
2385
- super(scope, id, { key, ...stackProps });
2386
- // Add infrastructure-specific tag
2387
- if (process.env.CDK_ENV_INFRASTRUCTURE_STACK_SHA) {
2388
- Tags.of(this).add(CDK.TAG.STACK_SHA, process.env.CDK_ENV_INFRASTRUCTURE_STACK_SHA);
2389
- }
2390
- }
2391
- }
2392
-
2393
- class JaypieMongoDbSecret extends JaypieEnvSecret {
2394
- constructor(scope, id = "MongoConnectionString", props) {
2395
- const defaultProps = {
2396
- envKey: "MONGODB_URI",
2397
- roleTag: CDK$2.ROLE.STORAGE,
2398
- vendorTag: CDK$2.VENDOR.MONGODB,
2399
- ...props,
2400
- };
2401
- super(scope, id, defaultProps);
2402
- }
2403
- }
2404
-
2405
- class JaypieNextJs extends Construct {
2406
- constructor(scope, id, props) {
2407
- super(scope, id);
2408
- const domainName = props?.domainName || envHostname();
2409
- this.domainName = domainName;
2410
- const domainNameSanitized = domainName
2411
- .replace(/\./g, "-")
2412
- .replace(/[^a-zA-Z0-9]/g, "_");
2413
- const envSecrets = props?.envSecrets || {};
2414
- const nextjsPath = props?.nextjsPath?.startsWith("..")
2415
- ? path.join(process.cwd(), props.nextjsPath)
2416
- : props?.nextjsPath || path.join(process.cwd(), "..", "nextjs");
2417
- const paramsAndSecrets = resolveParamsAndSecrets();
2418
- const secrets = props?.secrets || [];
2419
- // Process secrets environment variables
2420
- const secretsEnvironment = Object.entries(envSecrets).reduce((acc, [key, secret]) => ({
2421
- ...acc,
2422
- [`SECRET_${key}`]: secret.secretName,
2423
- }), {});
2424
- // Process JaypieEnvSecret array
2425
- const jaypieSecretsEnvironment = secrets.reduce((acc, secret) => {
2426
- if (secret.envKey) {
2427
- return {
2428
- ...acc,
2429
- [`SECRET_${secret.envKey}`]: secret.secretName,
2430
- };
2431
- }
2432
- return acc;
2433
- }, {});
2434
- // Process NEXT_PUBLIC_ environment variables
2435
- const nextPublicEnv = Object.entries(process.env).reduce((acc, [key, value]) => {
2436
- if (key.startsWith("NEXT_PUBLIC_") && value) {
2437
- return {
2438
- ...acc,
2439
- [key]: value,
2440
- };
2441
- }
2442
- return acc;
2443
- }, {});
2444
- const nextjs = new Nextjs(this, "NextJsApp", {
2445
- nextjsPath,
2446
- domainProps: {
2447
- domainName,
2448
- hostedZone: resolveHostedZone(this, {
2449
- zone: props?.hostedZone,
2450
- }),
2451
- },
2452
- environment: {
2453
- ...jaypieLambdaEnv(),
2454
- ...secretsEnvironment,
2455
- ...jaypieSecretsEnvironment,
2456
- ...nextPublicEnv,
2457
- NEXT_PUBLIC_SITE_URL: `https://${domainName}`,
2458
- },
2459
- overrides: {
2460
- nextjsDistribution: {
2461
- imageCachePolicyProps: {
2462
- cachePolicyName: `NextJsImageCachePolicy-${domainNameSanitized}`,
2463
- },
2464
- serverCachePolicyProps: {
2465
- cachePolicyName: `NextJsServerCachePolicy-${domainNameSanitized}`,
2466
- },
2467
- },
2468
- nextjsImage: {
2469
- functionProps: {
2470
- paramsAndSecrets,
2471
- },
2472
- },
2473
- nextjsServer: {
2474
- functionProps: {
2475
- paramsAndSecrets,
2476
- },
2477
- },
2478
- },
2479
- });
2480
- addDatadogLayers(nextjs.imageOptimizationFunction);
2481
- addDatadogLayers(nextjs.serverFunction.lambdaFunction);
2482
- // Grant secret read permissions
2483
- Object.values(envSecrets).forEach((secret) => {
2484
- secret.grantRead(nextjs.serverFunction.lambdaFunction);
2485
- });
2486
- // Grant read permissions for JaypieEnvSecrets
2487
- secrets.forEach((secret) => {
2488
- secret.grantRead(nextjs.serverFunction.lambdaFunction);
2489
- });
2490
- }
2491
- }
2492
-
2493
- class JaypieOpenAiSecret extends JaypieEnvSecret {
2494
- constructor(scope, id = "OpenAiApiKey", props) {
2495
- const defaultProps = {
2496
- envKey: "OPENAI_API_KEY",
2497
- roleTag: CDK$2.ROLE.PROCESSING,
2498
- vendorTag: CDK$2.VENDOR.OPENAI,
2499
- ...props,
2500
- };
2501
- super(scope, id, defaultProps);
2502
- }
2503
- }
2504
-
2505
- class JaypieOrganizationTrail extends Construct {
2506
- /**
2507
- * Create a new organization CloudTrail with S3 bucket and lifecycle policies
2508
- */
2509
- constructor(scope, idOrProps, propsOrUndefined) {
2510
- // Handle overloaded constructor signatures
2511
- let props;
2512
- let id;
2513
- if (typeof idOrProps === "string") {
2514
- // First param is ID, second is props
2515
- props = propsOrUndefined || {};
2516
- id = idOrProps;
2517
- }
2518
- else {
2519
- // First param is props
2520
- props = idOrProps || {};
2521
- const defaultName = process.env.PROJECT_NONCE
2522
- ? `organization-cloudtrail-${process.env.PROJECT_NONCE}`
2523
- : "organization-cloudtrail";
2524
- id = props.id || `${props.trailName || defaultName}-Trail`;
2525
- }
2526
- super(scope, id);
2527
- // Resolve options with defaults
2528
- const { bucketName = process.env.PROJECT_NONCE
2529
- ? `organization-cloudtrail-${process.env.PROJECT_NONCE}`
2530
- : "organization-cloudtrail", enableDatadogNotifications = true, enableFileValidation = false, expirationDays = 365, glacierTransitionDays = 180, infrequentAccessTransitionDays = 30, project, service = CDK$2.SERVICE.INFRASTRUCTURE, trailName = process.env.PROJECT_NONCE
2531
- ? `organization-cloudtrail-${process.env.PROJECT_NONCE}`
2532
- : "organization-cloudtrail", } = props;
2533
- // Create the S3 bucket for CloudTrail logs
2534
- this.bucket = new Bucket(this, "Bucket", {
2535
- accessControl: BucketAccessControl.LOG_DELIVERY_WRITE,
2536
- bucketName,
2537
- lifecycleRules: [
2538
- {
2539
- expiration: cdk.Duration.days(expirationDays),
2540
- transitions: [
2541
- {
2542
- storageClass: StorageClass.INFREQUENT_ACCESS,
2543
- transitionAfter: cdk.Duration.days(infrequentAccessTransitionDays),
2544
- },
2545
- {
2546
- storageClass: StorageClass.GLACIER,
2547
- transitionAfter: cdk.Duration.days(glacierTransitionDays),
2548
- },
2549
- ],
2550
- },
2551
- ],
2552
- });
2553
- // Add CloudTrail bucket policies
2554
- this.bucket.addToResourcePolicy(new PolicyStatement({
2555
- actions: ["s3:GetBucketAcl"],
2556
- effect: Effect.ALLOW,
2557
- principals: [new ServicePrincipal("cloudtrail.amazonaws.com")],
2558
- resources: [this.bucket.bucketArn],
2559
- }));
2560
- this.bucket.addToResourcePolicy(new PolicyStatement({
2561
- actions: ["s3:PutObject"],
2562
- conditions: {
2563
- StringEquals: {
2564
- "s3:x-amz-acl": "bucket-owner-full-control",
2565
- },
2566
- },
2567
- effect: Effect.ALLOW,
2568
- principals: [new ServicePrincipal("cloudtrail.amazonaws.com")],
2569
- resources: [`${this.bucket.bucketArn}/*`],
2570
- }));
2571
- // Add tags to bucket
2572
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.SERVICE, service);
2573
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
2574
- if (project) {
2575
- cdk.Tags.of(this.bucket).add(CDK$2.TAG.PROJECT, project);
2576
- }
2577
- // Add Datadog notifications if enabled
2578
- if (enableDatadogNotifications) {
2579
- const datadogForwarderFunction = resolveDatadogForwarderFunction(scope);
2580
- this.bucket.addEventNotification(EventType.OBJECT_CREATED, new LambdaDestination(datadogForwarderFunction));
2581
- }
2582
- // Create the organization trail
2583
- this.trail = new Trail(this, "Trail", {
2584
- bucket: this.bucket,
2585
- enableFileValidation,
2586
- isOrganizationTrail: true,
2587
- managementEvents: ReadWriteType.ALL,
2588
- trailName,
2589
- });
2590
- // Add tags to trail
2591
- cdk.Tags.of(this.trail).add(CDK$2.TAG.SERVICE, service);
2592
- cdk.Tags.of(this.trail).add(CDK$2.TAG.ROLE, CDK$2.ROLE.MONITORING);
2593
- if (project) {
2594
- cdk.Tags.of(this.trail).add(CDK$2.TAG.PROJECT, project);
2595
- }
2596
- }
2597
- }
2598
-
2599
- /**
2600
- * JaypieSsoPermissions Construct
2601
- *
2602
- * Creates and manages AWS IAM Identity Center (SSO) permission sets and assignments
2603
- *
2604
- * @example
2605
- * const permissionSets = new JaypieSsoPermissions(this, "PermissionSets", {
2606
- * iamIdentityCenterArn: "arn:aws:sso:::instance/...",
2607
- * administratorGroupId: "b4c8b438-4031-7000-782d-5046945fb956",
2608
- * analystGroupId: "2488f4e8-d061-708e-abe1-c315f0e30005",
2609
- * developerGroupId: "b438a4f8-e0e1-707c-c6e8-21841daf9ad1",
2610
- * administratorAccountAssignments: {
2611
- * "211125635435": ["Administrator", "Analyst", "Developer"],
2612
- * "381492033431": ["Administrator", "Analyst"],
2613
- * },
2614
- * analystAccountAssignments: {
2615
- * "211125635435": ["Analyst", "Developer"],
2616
- * "381492033431": [],
2617
- * },
2618
- * developerAccountAssignments: {
2619
- * "211125635435": ["Analyst", "Developer"],
2620
- * "381492033431": [],
2621
- * },
2622
- * });
2623
- */
2624
- class JaypieSsoPermissions extends Construct {
2625
- constructor(scope, id, props) {
2626
- super(scope, id);
2627
- const { iamIdentityCenterArn: iamIdentityCenterArnProp, administratorGroupId, analystGroupId, developerGroupId, administratorAccountAssignments, analystAccountAssignments, developerAccountAssignments, } = props;
2628
- const iamIdentityCenterArn = iamIdentityCenterArnProp || process.env.CDK_ENV_IAM_IDENTITY_CENTER_ARN;
2629
- if (!iamIdentityCenterArn) {
2630
- // If no IAM Identity Center ARN provided, skip SSO setup
2631
- return;
2632
- }
2633
- //
2634
- // Permission Sets
2635
- //
2636
- this.administratorPermissionSet = new CfnPermissionSet(this, "AdministratorPermissionSet", {
2637
- // Required
2638
- instanceArn: iamIdentityCenterArn,
2639
- name: "Administrator",
2640
- // Optional
2641
- description: "Unrestricted access",
2642
- inlinePolicy: {
2643
- Version: "2012-10-17",
2644
- Statement: [
2645
- {
2646
- Effect: "Allow",
2647
- Action: [
2648
- "aws-portal:ViewUsage",
2649
- "aws-portal:ViewBilling",
2650
- "budgets:*",
2651
- "cur:DescribeReportDefinitions",
2652
- "cur:PutReportDefinition",
2653
- "cur:DeleteReportDefinition",
2654
- "cur:ModifyReportDefinition",
2655
- ],
2656
- Resource: "*",
2657
- },
2658
- ],
2659
- },
2660
- managedPolicies: [
2661
- ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")
2662
- .managedPolicyArn,
2663
- ManagedPolicy.fromAwsManagedPolicyName("AWSManagementConsoleBasicUserAccess").managedPolicyArn,
2664
- ],
2665
- sessionDuration: Duration.hours(1).toIsoString(),
2666
- tags: [
2667
- {
2668
- key: CDK$2.TAG.SERVICE,
2669
- value: CDK$2.SERVICE.SSO,
2670
- },
2671
- {
2672
- key: CDK$2.TAG.ROLE,
2673
- value: CDK$2.ROLE.SECURITY,
2674
- },
2675
- ],
2676
- });
2677
- this.analystPermissionSet = new CfnPermissionSet(this, "AnalystPermissionSet", {
2678
- // Required
2679
- instanceArn: iamIdentityCenterArn,
2680
- name: "Analyst",
2681
- // Optional
2682
- description: "Read-only access; may expand to limited write access",
2683
- inlinePolicy: {
2684
- Version: "2012-10-17",
2685
- Statement: [
2686
- {
2687
- Effect: "Allow",
2688
- Action: [
2689
- "aws-portal:ViewUsage",
2690
- "aws-portal:ViewBilling",
2691
- "budgets:Describe*",
2692
- "budgets:View*",
2693
- "ce:Get*",
2694
- "ce:List*",
2695
- "cloudformation:Describe*",
2696
- "cloudformation:Get*",
2697
- "cloudformation:List*",
2698
- "cloudwatch:BatchGet*",
2699
- "cloudwatch:Get*",
2700
- "cloudwatch:List*",
2701
- "cost-optimization-hub:Get*",
2702
- "cost-optimization-hub:List*",
2703
- "ec2:Describe*",
2704
- "ec2:Get*",
2705
- "ec2:List*",
2706
- "ec2:Search*",
2707
- "iam:Get*",
2708
- "iam:List*",
2709
- "iam:PassRole",
2710
- "lambda:Get*",
2711
- "lambda:List*",
2712
- "logs:Describe*",
2713
- "logs:Get*",
2714
- "logs:List*",
2715
- "pipes:Describe*",
2716
- "pipes:List*",
2717
- "s3:Get*",
2718
- "s3:List*",
2719
- "secretsmanager:GetRandomPassword",
2720
- "secretsmanager:GetResourcePolicy",
2721
- "secretsmanager:List*",
2722
- "securityhub:Describe*",
2723
- "securityhub:Get*",
2724
- "securityhub:List*",
2725
- "servicecatalog:Describe*",
2726
- "sns:Get*",
2727
- "sns:List*",
2728
- "sqs:Get*",
2729
- "sqs:List*",
2730
- "states:Describe*",
2731
- "states:Get*",
2732
- "states:List*",
2733
- "tag:*",
2734
- "uxc:*",
2735
- "xray:*",
2736
- ],
2737
- Resource: "*",
2738
- },
2739
- ],
2740
- },
2741
- managedPolicies: [
2742
- ManagedPolicy.fromAwsManagedPolicyName("AmazonQDeveloperAccess")
2743
- .managedPolicyArn,
2744
- ManagedPolicy.fromAwsManagedPolicyName("AWSManagementConsoleBasicUserAccess").managedPolicyArn,
2745
- ManagedPolicy.fromAwsManagedPolicyName("ReadOnlyAccess")
2746
- .managedPolicyArn,
2747
- ],
2748
- sessionDuration: Duration.hours(12).toIsoString(),
2749
- tags: [
2750
- {
2751
- key: CDK$2.TAG.SERVICE,
2752
- value: CDK$2.SERVICE.SSO,
2753
- },
2754
- {
2755
- key: CDK$2.TAG.ROLE,
2756
- value: CDK$2.ROLE.SECURITY,
2757
- },
2758
- ],
2759
- });
2760
- this.developerPermissionSet = new CfnPermissionSet(this, "DeveloperPermissionSet", {
2761
- // Required
2762
- instanceArn: iamIdentityCenterArn,
2763
- name: "Developer",
2764
- // Optional
2765
- description: "Administrative access with limited restrictions",
2766
- inlinePolicy: {
2767
- Version: "2012-10-17",
2768
- Statement: [
2769
- {
2770
- Effect: "Allow",
2771
- Action: [
2772
- "budgets:*",
2773
- "ce:*",
2774
- "cloudformation:*",
2775
- "cloudwatch:*",
2776
- "cost-optimization-hub:*",
2777
- "ec2:*",
2778
- "iam:Get*",
2779
- "iam:List*",
2780
- "iam:PassRole",
2781
- "lambda:*",
2782
- "logs:*",
2783
- "pipes:*",
2784
- "s3:*",
2785
- "secretsmanager:*",
2786
- "securityhub:*",
2787
- "servicecatalog:*",
2788
- "sns:*",
2789
- "sqs:*",
2790
- "states:*",
2791
- "tag:*",
2792
- "uxc:*",
2793
- "xray:*",
2794
- ],
2795
- Resource: "*",
2796
- },
2797
- ],
2798
- },
2799
- managedPolicies: [
2800
- ManagedPolicy.fromAwsManagedPolicyName("AmazonQDeveloperAccess")
2801
- .managedPolicyArn,
2802
- ManagedPolicy.fromAwsManagedPolicyName("AWSManagementConsoleBasicUserAccess").managedPolicyArn,
2803
- ManagedPolicy.fromAwsManagedPolicyName("ReadOnlyAccess")
2804
- .managedPolicyArn,
2805
- ManagedPolicy.fromAwsManagedPolicyName("job-function/SystemAdministrator").managedPolicyArn,
2806
- ],
2807
- sessionDuration: Duration.hours(4).toIsoString(),
2808
- tags: [
2809
- {
2810
- key: CDK$2.TAG.SERVICE,
2811
- value: CDK$2.SERVICE.SSO,
2812
- },
2813
- {
2814
- key: CDK$2.TAG.ROLE,
2815
- value: CDK$2.ROLE.SECURITY,
2816
- },
2817
- ],
2818
- });
2819
- // Map permission set names to their ARNs and labels
2820
- const permissionSetMap = {
2821
- Administrator: {
2822
- arn: this.administratorPermissionSet.attrPermissionSetArn,
2823
- label: "Administrator",
2824
- },
2825
- Analyst: {
2826
- arn: this.analystPermissionSet.attrPermissionSetArn,
2827
- label: "Analyst",
2828
- },
2829
- Developer: {
2830
- arn: this.developerPermissionSet.attrPermissionSetArn,
2831
- label: "Developer",
2832
- },
2833
- };
2834
- //
2835
- // Assignments
2836
- //
2837
- // Helper function to create assignments for a group
2838
- const createAssignments = (groupId, accountAssignments) => {
2839
- if (!groupId || !accountAssignments) {
2840
- return; // Skip if group ID or assignments not provided
2841
- }
2842
- Object.keys(accountAssignments).forEach((accountId) => {
2843
- const permissionSetNames = accountAssignments[accountId];
2844
- permissionSetNames.forEach((permissionSetName) => {
2845
- const permissionSet = permissionSetMap[permissionSetName];
2846
- if (!permissionSet) {
2847
- throw new ConfigurationError(`Unknown permission set: ${permissionSetName}. Valid options: ${Object.keys(permissionSetMap).join(", ")}`);
2848
- }
2849
- const accountAssignment = new CfnAssignment(this, `AccountAssignment-${accountId}-${permissionSet.label}Role-${groupId}Group`, {
2850
- // Required
2851
- instanceArn: iamIdentityCenterArn,
2852
- permissionSetArn: permissionSet.arn,
2853
- principalId: groupId,
2854
- principalType: CDK$2.PRINCIPAL_TYPE.GROUP,
2855
- targetId: accountId,
2856
- targetType: CDK$2.TARGET_TYPE.AWS_ACCOUNT,
2857
- });
2858
- Tags.of(accountAssignment).add(CDK$2.TAG.SERVICE, CDK$2.SERVICE.SSO);
2859
- Tags.of(accountAssignment).add(CDK$2.TAG.ROLE, CDK$2.ROLE.SECURITY);
2860
- });
2861
- });
2862
- };
2863
- // Create assignments for each group
2864
- createAssignments(administratorGroupId, administratorAccountAssignments);
2865
- createAssignments(analystGroupId, analystAccountAssignments);
2866
- createAssignments(developerGroupId, developerAccountAssignments);
2867
- }
2868
- }
2869
-
2870
- //
2871
- //
2872
- // Constants
2873
- //
2874
- const DEFAULT_APPLICATION_ID = "arn:aws:serverlessrepo:us-east-2:004480582608:applications/SSOSync";
2875
- const DEFAULT_APPLICATION_VERSION = "2.3.3";
2876
- const DEFAULT_GOOGLE_GROUP_MATCH = "name:AWS*";
2877
- //
2878
- //
2879
- // Class
2880
- //
2881
- class JaypieSsoSyncApplication extends Construct {
2882
- constructor(scope, id = "SsoSyncApplication", props = {}) {
2883
- super(scope, id);
2884
- 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;
2885
- // Resolve all values from props or environment variables
2886
- const resolvedGoogleAdminEmail = googleAdminEmail || process.env[googleAdminEmailEnvKey];
2887
- const resolvedGoogleCredentials = googleCredentials || process.env[googleCredentialsEnvKey];
2888
- const resolvedGoogleGroupMatch = googleGroupMatch ||
2889
- process.env[googleGroupMatchEnvKey] ||
2890
- DEFAULT_GOOGLE_GROUP_MATCH;
2891
- const resolvedIdentityStoreId = identityStoreId || process.env[identityStoreIdEnvKey];
2892
- const resolvedScimEndpointAccessToken = scimEndpointAccessToken || process.env[scimEndpointAccessTokenEnvKey];
2893
- const resolvedScimEndpointUrl = scimEndpointUrl || process.env[scimEndpointUrlEnvKey];
2894
- const resolvedSemanticVersion = semanticVersion ||
2895
- process.env[semanticVersionEnvKey] ||
2896
- DEFAULT_APPLICATION_VERSION;
2897
- // Validate required parameters
2898
- const missingParams = [];
2899
- if (!resolvedGoogleAdminEmail) {
2900
- missingParams.push(`googleAdminEmail or ${googleAdminEmailEnvKey} environment variable`);
2901
- }
2902
- if (!resolvedGoogleCredentials) {
2903
- missingParams.push(`googleCredentials or ${googleCredentialsEnvKey} environment variable`);
2904
- }
2905
- if (!resolvedIdentityStoreId) {
2906
- missingParams.push(`identityStoreId or ${identityStoreIdEnvKey} environment variable`);
2907
- }
2908
- if (!resolvedScimEndpointAccessToken) {
2909
- missingParams.push(`scimEndpointAccessToken or ${scimEndpointAccessTokenEnvKey} environment variable`);
2910
- }
2911
- if (!resolvedScimEndpointUrl) {
2912
- missingParams.push(`scimEndpointUrl or ${scimEndpointUrlEnvKey} environment variable`);
2913
- }
2914
- if (missingParams.length > 0) {
2915
- throw new ConfigurationError(`JaypieSsoSyncApplication missing required configuration: ${missingParams.join(", ")}`);
2916
- }
2917
- // Create the SSO Sync Application
2918
- // Type assertion is safe because we validated all required values above
2919
- this._application = new CfnApplication(this, "Application", {
2920
- location: {
2921
- applicationId: ssoSyncApplicationId,
2922
- semanticVersion: resolvedSemanticVersion,
2923
- },
2924
- parameters: {
2925
- GoogleAdminEmail: resolvedGoogleAdminEmail,
2926
- GoogleCredentials: resolvedGoogleCredentials,
2927
- GoogleGroupMatch: resolvedGoogleGroupMatch,
2928
- IdentityStoreID: resolvedIdentityStoreId,
2929
- Region: Stack.of(this).region,
2930
- SCIMEndpointAccessToken: resolvedScimEndpointAccessToken,
2931
- SCIMEndpointUrl: resolvedScimEndpointUrl,
2932
- },
2933
- });
2934
- // Add tags
2935
- const defaultTags = {
2936
- [CDK$2.TAG.ROLE]: CDK$2.ROLE.SECURITY,
2937
- };
2938
- const allTags = { ...defaultTags, ...tags };
2939
- Object.entries(allTags).forEach(([key, value]) => {
2940
- Tags.of(this._application).add(key, value);
2941
- });
2942
- }
2943
- get application() {
2944
- return this._application;
2945
- }
2946
- }
2947
-
2948
- class JaypieWebDeploymentBucket extends Construct {
2949
- constructor(scope, id, props = {}) {
2950
- super(scope, id);
2951
- const roleTag = props.roleTag || CDK$2.ROLE.HOSTING;
2952
- // Environment variable validation
2953
- if (process.env.CDK_ENV_WEB_SUBDOMAIN &&
2954
- !isValidSubdomain(process.env.CDK_ENV_WEB_SUBDOMAIN)) {
2955
- throw new ConfigurationError("CDK_ENV_WEB_SUBDOMAIN is not a valid subdomain");
2956
- }
2957
- if (process.env.CDK_ENV_WEB_HOSTED_ZONE &&
2958
- !isValidHostname$1(process.env.CDK_ENV_WEB_HOSTED_ZONE)) {
2959
- throw new ConfigurationError("CDK_ENV_WEB_HOSTED_ZONE is not a valid hostname");
2960
- }
2961
- if (process.env.CDK_ENV_HOSTED_ZONE &&
2962
- !isValidHostname$1(process.env.CDK_ENV_HOSTED_ZONE)) {
2963
- throw new ConfigurationError("CDK_ENV_HOSTED_ZONE is not a valid hostname");
2964
- }
2965
- // Determine host from props or environment
2966
- let host = props.host;
2967
- if (!host) {
2968
- try {
2969
- host =
2970
- process.env.CDK_ENV_WEB_HOST ||
2971
- mergeDomain(process.env.CDK_ENV_WEB_SUBDOMAIN || "", process.env.CDK_ENV_WEB_HOSTED_ZONE ||
2972
- process.env.CDK_ENV_HOSTED_ZONE ||
2973
- "");
2974
- }
2975
- catch {
2976
- host = undefined;
2977
- }
2978
- }
2979
- if (host && !isValidHostname$1(host)) {
2980
- throw new ConfigurationError("Host is not a valid hostname");
2981
- }
2982
- // Determine zone from props or environment
2983
- const zone = props.zone ||
2984
- process.env.CDK_ENV_WEB_HOSTED_ZONE ||
2985
- process.env.CDK_ENV_HOSTED_ZONE;
2986
- // Create the S3 bucket
2987
- this.bucket = new s3.Bucket(this, "DestinationBucket", {
2988
- accessControl: s3.BucketAccessControl.BUCKET_OWNER_FULL_CONTROL,
2989
- autoDeleteObjects: true,
2990
- blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS_ONLY,
2991
- bucketName: props.name || constructEnvName("web"),
2992
- publicReadAccess: true,
2993
- removalPolicy: RemovalPolicy.DESTROY,
2994
- versioned: false,
2995
- websiteErrorDocument: "index.html",
2996
- websiteIndexDocument: "index.html",
2997
- ...props,
2998
- });
2999
- // Delegate IBucket properties to the bucket
3000
- this.bucketArn = this.bucket.bucketArn;
3001
- this.bucketDomainName = this.bucket.bucketDomainName;
3002
- this.bucketDualStackDomainName = this.bucket.bucketDualStackDomainName;
3003
- this.bucketName = this.bucket.bucketName;
3004
- this.bucketRegionalDomainName = this.bucket.bucketRegionalDomainName;
3005
- this.bucketWebsiteDomainName = this.bucket.bucketWebsiteDomainName;
3006
- this.bucketWebsiteUrl = this.bucket.bucketWebsiteUrl;
3007
- this.encryptionKey = this.bucket.encryptionKey;
3008
- this.isWebsite = this.bucket.isWebsite;
3009
- this.notificationsHandlerRole = undefined;
3010
- this.policy = this.bucket.policy;
3011
- Tags.of(this.bucket).add(CDK$2.TAG.ROLE, roleTag);
3012
- // Create deployment role if repository is configured
3013
- let repo;
3014
- if (process.env.CDK_ENV_REPO) {
3015
- repo = `repo:${process.env.CDK_ENV_REPO}:*`;
3016
- }
3017
- if (repo) {
3018
- const bucketDeployRole = new Role(this, "DestinationBucketDeployRole", {
3019
- assumedBy: new FederatedPrincipal(Fn.importValue(CDK$2.IMPORT.OIDC_PROVIDER), {
3020
- StringLike: {
3021
- "token.actions.githubusercontent.com:sub": repo,
3022
- },
3023
- }, "sts:AssumeRoleWithWebIdentity"),
3024
- maxSessionDuration: Duration.hours(1),
3025
- });
3026
- Tags.of(bucketDeployRole).add(CDK$2.TAG.ROLE, CDK$2.ROLE.DEPLOY);
3027
- // Allow the role to write to the bucket
3028
- bucketDeployRole.addToPolicy(new PolicyStatement({
3029
- effect: Effect.ALLOW,
3030
- actions: [
3031
- "s3:DeleteObject",
3032
- "s3:GetObject",
3033
- "s3:ListObjectsV2",
3034
- "s3:PutObject",
3035
- ],
3036
- resources: [`${this.bucket.bucketArn}/*`],
3037
- }));
3038
- bucketDeployRole.addToPolicy(new PolicyStatement({
3039
- effect: Effect.ALLOW,
3040
- actions: ["s3:ListBucket"],
3041
- resources: [this.bucket.bucketArn],
3042
- }));
3043
- // Allow the role to describe the current stack
3044
- const stack = Stack.of(this);
3045
- bucketDeployRole.addToPolicy(new PolicyStatement({
3046
- actions: ["cloudformation:DescribeStacks"],
3047
- effect: Effect.ALLOW,
3048
- resources: [
3049
- `arn:aws:cloudformation:${stack.region}:${stack.account}:stack/${stack.stackName}/*`,
3050
- ],
3051
- }));
3052
- this.deployRoleArn = bucketDeployRole.roleArn;
3053
- // Output the deploy role ARN
3054
- new CfnOutput(this, "DestinationBucketDeployRoleArn", {
3055
- value: bucketDeployRole.roleArn,
3056
- });
3057
- }
3058
- // Create CloudFront distribution and certificate if host and zone are provided
3059
- if (host && zone) {
3060
- let hostedZone;
3061
- if (typeof zone === "string") {
3062
- hostedZone = route53.HostedZone.fromLookup(this, "HostedZone", {
3063
- domainName: zone,
3064
- });
3065
- }
3066
- else if (zone instanceof JaypieHostedZone) {
3067
- hostedZone = zone.hostedZone;
3068
- }
3069
- else {
3070
- hostedZone = zone;
3071
- }
3072
- // Create certificate if not provided
3073
- if (props.certificate !== false) {
3074
- this.certificate =
3075
- typeof props.certificate === "object"
3076
- ? props.certificate
3077
- : new acm.Certificate(this, "Certificate", {
3078
- domainName: host,
3079
- validation: acm.CertificateValidation.fromDns(hostedZone),
3080
- });
3081
- new CfnOutput(this, "CertificateArn", {
3082
- value: this.certificate.certificateArn,
3083
- });
3084
- Tags.of(this.certificate).add(CDK$2.TAG.ROLE, roleTag);
3085
- }
3086
- // Create CloudFront distribution
3087
- this.distribution = new cloudfront.Distribution(this, "Distribution", {
3088
- defaultBehavior: {
3089
- cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
3090
- origin: new origins.S3StaticWebsiteOrigin(this.bucket),
3091
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
3092
- },
3093
- certificate: this.certificate,
3094
- domainNames: [host],
3095
- });
3096
- Tags.of(this.distribution).add(CDK$2.TAG.ROLE, roleTag);
3097
- // If this is production, enable caching on everything but index.html
3098
- if (isProductionEnv()) {
3099
- this.distribution.addBehavior("/*", new origins.S3StaticWebsiteOrigin(this.bucket), {
3100
- viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
3101
- cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
3102
- });
3103
- }
3104
- // Create DNS record
3105
- const record = new route53.ARecord(this, "AliasRecord", {
3106
- recordName: host,
3107
- target: route53.RecordTarget.fromAlias(new route53Targets.CloudFrontTarget(this.distribution)),
3108
- zone: hostedZone,
3109
- });
3110
- Tags.of(record).add(CDK$2.TAG.ROLE, CDK$2.ROLE.NETWORKING);
3111
- this.distributionDomainName = this.distribution.distributionDomainName;
3112
- }
3113
- }
3114
- // Implement remaining IBucket methods by delegating to the bucket
3115
- addEventNotification(event, dest, ...filters) {
3116
- this.bucket.addEventNotification(event, dest, ...filters);
3117
- }
3118
- addObjectCreatedNotification(dest, ...filters) {
3119
- this.bucket.addObjectCreatedNotification(dest, ...filters);
3120
- }
3121
- addObjectRemovedNotification(dest, ...filters) {
3122
- this.bucket.addObjectRemovedNotification(dest, ...filters);
3123
- }
3124
- addToResourcePolicy(permission) {
3125
- return this.bucket.addToResourcePolicy(permission);
3126
- }
3127
- arnForObjects(keyPattern) {
3128
- return this.bucket.arnForObjects(keyPattern);
3129
- }
3130
- grantDelete(identity, objectsKeyPattern) {
3131
- return this.bucket.grantDelete(identity, objectsKeyPattern);
3132
- }
3133
- grantPublicAccess(allowedActions, keyPrefix) {
3134
- return keyPrefix
3135
- ? this.bucket.grantPublicAccess(allowedActions, keyPrefix)
3136
- : this.bucket.grantPublicAccess(allowedActions);
3137
- }
3138
- grantPut(identity, objectsKeyPattern) {
3139
- return this.bucket.grantPut(identity, objectsKeyPattern);
3140
- }
3141
- grantPutAcl(identity, objectsKeyPattern) {
3142
- return this.bucket.grantPutAcl(identity, objectsKeyPattern);
3143
- }
3144
- grantRead(identity, objectsKeyPattern) {
3145
- return this.bucket.grantRead(identity, objectsKeyPattern);
3146
- }
3147
- grantReadWrite(identity, objectsKeyPattern) {
3148
- return this.bucket.grantReadWrite(identity, objectsKeyPattern);
3149
- }
3150
- grantWrite(identity, objectsKeyPattern) {
3151
- return this.bucket.grantWrite(identity, objectsKeyPattern);
3152
- }
3153
- grantReplicationPermission(identity, props) {
3154
- return this.bucket.grantReplicationPermission(identity, props);
3155
- }
3156
- s3UrlForObject(key) {
3157
- return this.bucket.s3UrlForObject(key);
3158
- }
3159
- urlForObject(key) {
3160
- return this.bucket.urlForObject(key);
3161
- }
3162
- virtualHostedUrlForObject(key, options) {
3163
- return this.bucket.virtualHostedUrlForObject(key, options);
3164
- }
3165
- transferAccelerationUrlForObject(key) {
3166
- return this.bucket.transferAccelerationUrlForObject(key);
3167
- }
3168
- onCloudTrailEvent(id, options) {
3169
- return this.bucket.onCloudTrailEvent(id, options);
3170
- }
3171
- onCloudTrailPutObject(id, options) {
3172
- return this.bucket.onCloudTrailPutObject(id, options);
3173
- }
3174
- onCloudTrailWriteObject(id, options) {
3175
- return this.bucket.onCloudTrailWriteObject(id, options);
3176
- }
3177
- addCorsRule(rule) {
3178
- this.bucket.addCorsRule(rule);
3179
- }
3180
- addInventory(inventory) {
3181
- this.bucket.addInventory(inventory);
3182
- }
3183
- addLifecycleRule(rule) {
3184
- this.bucket.addLifecycleRule(rule);
3185
- }
3186
- addMetric(metric) {
3187
- this.bucket.addMetric(metric);
3188
- }
3189
- enableEventBridgeNotification() {
3190
- this.bucket.enableEventBridgeNotification();
3191
- }
3192
- addReplicationPolicy(policy) {
3193
- this.bucket.addReplicationPolicy(policy);
3194
- }
3195
- get stack() {
3196
- return this.bucket.stack;
3197
- }
3198
- get env() {
3199
- return this.bucket.env;
3200
- }
3201
- applyRemovalPolicy(policy) {
3202
- this.bucket.applyRemovalPolicy(policy);
3203
- }
3204
- get bucketRef() {
3205
- return {
3206
- bucketArn: this.bucket.bucketArn,
3207
- bucketName: this.bucket.bucketName,
3208
- };
3209
- }
3210
- }
3211
-
3212
- class JaypieStaticWebBucket extends JaypieWebDeploymentBucket {
3213
- constructor(scope, id, props = {}) {
3214
- // Handle overloaded signatures: (scope), (scope, props), (scope, id, props)
3215
- let resolvedId;
3216
- let resolvedProps;
3217
- if (typeof id === "string") {
3218
- resolvedId = id;
3219
- resolvedProps = props;
3220
- }
3221
- else if (typeof id === "object") {
3222
- resolvedId = "JaypieStaticWebBucket";
3223
- resolvedProps = id;
3224
- }
3225
- else {
3226
- resolvedId = "JaypieStaticWebBucket";
3227
- resolvedProps = props;
3228
- }
3229
- const host = resolvedProps.host ?? envHostname({ subdomain: "static" });
3230
- const name = resolvedProps.name ?? constructEnvName("static");
3231
- const roleTag = resolvedProps.roleTag ?? CDK$2.ROLE.HOSTING;
3232
- // Only use default zone if zone is not explicitly provided (including undefined)
3233
- const zone = "zone" in resolvedProps
3234
- ? resolvedProps.zone
3235
- : process.env.CDK_ENV_DOMAIN || process.env.CDK_ENV_HOSTED_ZONE;
3236
- super(scope, resolvedId, {
3237
- ...resolvedProps,
3238
- host,
3239
- name,
3240
- roleTag,
3241
- zone,
3242
- });
3243
- }
3244
- }
3245
-
3246
- class JaypieTraceSigningKeySecret extends JaypieEnvSecret {
3247
- constructor(scope, id = "TraceSigningKey", props) {
3248
- const defaultProps = {
3249
- envKey: "TRACE_SIGNING_KEY",
3250
- roleTag: CDK$2.ROLE.API,
3251
- vendorTag: CDK$2.VENDOR.KNOWTRACE,
3252
- ...props,
3253
- };
3254
- super(scope, id, defaultProps);
3255
- }
3256
- }
3257
-
3258
- 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 };
3259
- //# sourceMappingURL=index.js.map