@guardian/cdk 63.3.1 → 63.5.0

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.
@@ -0,0 +1,351 @@
1
+ import { Duration } from "aws-cdk-lib";
2
+ import type { BlockDevice, UpdatePolicy } from "aws-cdk-lib/aws-autoscaling";
3
+ import type { InstanceType, ISubnet, IVpc } from "aws-cdk-lib/aws-ec2";
4
+ import { UserData } from "aws-cdk-lib/aws-ec2";
5
+ import { FargateService } from "aws-cdk-lib/aws-ecs";
6
+ import type { HealthCheck as ALBHealthCheck } from "aws-cdk-lib/aws-elasticloadbalancingv2";
7
+ import { Construct } from "constructs";
8
+ import { GuCertificate } from "../../constructs/acm";
9
+ import type { GuUserDataProps } from "../../constructs/autoscaling";
10
+ import { GuAutoScalingGroup } from "../../constructs/autoscaling";
11
+ import type { NoMonitoring } from "../../constructs/cloudwatch";
12
+ import type { GuStack } from "../../constructs/core";
13
+ import { AppIdentity } from "../../constructs/core";
14
+ import type { GuInstanceRoleProps } from "../../constructs/iam";
15
+ import { GuApplicationLoadBalancer, GuApplicationTargetGroup, GuHttpsApplicationListener, type WafProps } from "../../constructs/loadbalancing";
16
+ import type { Alarms, ApplicationLoggingProps } from "../../patterns";
17
+ import { AppAccess } from "../../types";
18
+ import type { GuAsgCapacity, GuDomainName } from "../../types";
19
+ import type { AmigoProps } from "../../types/amigo";
20
+ export interface GuLoadBalancedAppExperimentalProps extends AppIdentity {
21
+ /**
22
+ * Network access restrictions for your load balancer.
23
+ *
24
+ * Note, this merely provides defence in depth; you should NOT rely on network access restrictions alone for
25
+ * restricting access. Use Google Auth for human access, or a suitable machine auth mechanism.
26
+ */
27
+ access: AppAccess;
28
+ /**
29
+ * The port your application runs on.
30
+ */
31
+ applicationPort: number;
32
+ /**
33
+ * Enable access logging for this load balancer.
34
+ * Access logs are written to an S3 bucket within your AWS account.
35
+ * The bucket is created by {@link https://github.com/guardian/aws-account-setup}.
36
+ * The logs are queryable via the `gucdk_access_logs` Athena database.
37
+ *
38
+ * @defaultValue true
39
+ */
40
+ withAccessLogging?: boolean;
41
+ /**
42
+ * Enable and configure alarms.
43
+ */
44
+ monitoringConfiguration: Alarms | NoMonitoring;
45
+ /**
46
+ * Specify certificate for the load balancer.
47
+ */
48
+ certificateProps?: GuDomainName;
49
+ /**
50
+ * Specify the VPC to use.
51
+ *
52
+ * @see https://github.com/guardian/aws-account-setup
53
+ */
54
+ vpc?: IVpc;
55
+ /**
56
+ * Specify private subnets if using a non-default VPC or (generally
57
+ * discouraged) to limit to a subset of the available subnets.
58
+ */
59
+ privateSubnets?: ISubnet[];
60
+ /**
61
+ * Specify public subnets if using a non-default VPC or (generally
62
+ * discouraged) to limit to a subset of the available subnets.
63
+ */
64
+ publicSubnets?: ISubnet[];
65
+ /**
66
+ * Configure Google Auth.
67
+ */
68
+ googleAuth?: {
69
+ /**
70
+ * Enables Google Auth (via Cognito). **Additional MANUAL steps required -
71
+ * see below.**
72
+ *
73
+ * Limits access to members of the allowed Google groups.
74
+ *
75
+ * Note, this does not currently support simultaneous machine access, so
76
+ * only set to true if you only require staff access to your service, or are
77
+ * supporting machine access in some other way.
78
+ *
79
+ * MANUAL STEPS: to get this to work, we need a Google Project and
80
+ * associated credentials. Full instructions can be found here:
81
+ *
82
+ * https://docs.google.com/document/d/1_k1FSE52AZHXufWLTiKTI3xy5cGpziyHazSHTKrYfco/edit?usp=sharing
83
+ *
84
+ * DevX hope to automate this process in the near future.
85
+ */
86
+ enabled: true;
87
+ /**
88
+ * The domain users will access your service.
89
+ *
90
+ * Set this to the same as for certificateProps.
91
+ */
92
+ domain: string;
93
+ /**
94
+ * Groups used for membership checks.
95
+ *
96
+ * If specified, cannot be empty. Users must be a member of at least one
97
+ * group to gain access.
98
+ *
99
+ * WARNING: groups must be specified with the `guardian.co.uk` domain, even
100
+ * if that is the non-idiomatic choice for daily use.
101
+ *
102
+ * @defaultValue [`engineering@guardian.co.uk`]
103
+ */
104
+ allowedGroups?: string[];
105
+ /**
106
+ * The number of minutes before the session expires.
107
+ *
108
+ * Set this value to a safe period of time that revoked users
109
+ * sessions will continue to function.
110
+ *
111
+ * NOTE: This value cannot be larger than 60 minutes.
112
+ *
113
+ * @defaultValue 15
114
+ */
115
+ sessionTimeoutInMinutes?: number;
116
+ /**
117
+ * Secrets Manager path containing Google OAuth2 Client credentials.
118
+ *
119
+ * NOTE: you do not need to set this value, but you DO need to generate and
120
+ * store the associated credentials in Secrets Manager.
121
+ *
122
+ * Credentials should be stored in Secrets Manager as JSON:
123
+ *
124
+ * ```json
125
+ * {
126
+ * "clientId": "my-client-id",
127
+ * "clientSecret": "my-client-secret"
128
+ * }
129
+ * ```
130
+ *
131
+ * @see `googleAuth.enabled` for how to generate.
132
+ *
133
+ * @defaultValue /:STAGE/:stack/:app/google-auth-credentials
134
+ */
135
+ credentialsSecretsManagerPath?: string;
136
+ /**
137
+ * When using Auth in the ALB, which stage of cognito-lambda to use.
138
+ *
139
+ * For most applications this should always be PROD, even in the CODE environments.
140
+ *
141
+ * @defaultValue PROD
142
+ */
143
+ cognitoAuthStage?: string;
144
+ };
145
+ /**
146
+ * Specify custom healthcheck
147
+ */
148
+ healthcheck?: ALBHealthCheck;
149
+ /**
150
+ * You can specify if the arn of this load balancer should be exposed for protection via WAF
151
+ *
152
+ * If this value changes, it is only picked up on WAF configuration redeploy.
153
+ *
154
+ * NB this parameter setting _alone_ is not sufficient to protect the application.
155
+ * You must also ensure that the application and stage combination is present in the WAF
156
+ * configuration.
157
+ *
158
+ * See https://github.com/guardian/waf/tree/main/lib
159
+ *
160
+ * There is a "gotcha" when migrating to this functionality. You may not change only the Logical
161
+ * ID of an SSM Parameter (see https://docs.aws.amazon.com/cdk/v2/guide/identifiers.html) and the
162
+ * parameter name must be of the required form, meaning you cannot have an alternate name.
163
+ *
164
+ * You can either:
165
+ *
166
+ * Remove the old param and immediately redeploy with the new param (this does not affect
167
+ * protection unless and until the WAF configuration is redeployed)
168
+ *
169
+ * OR
170
+ *
171
+ * Create an escape hatch by overriding the logical id (see "ssm param escape hatch" test for example)
172
+ **/
173
+ waf?: WafProps;
174
+ /**
175
+ * If you want to use an AutoScaling Group with EC2 instances to serve requests, then pass in relevant props here.
176
+ *
177
+ * If you are setting both `ec2Props` and `ecsProps` (i.e. if you are migrating from EC2 to ECS) then you must also
178
+ * specify weights for each compute type using `targetGroupWeights`.
179
+ */
180
+ ec2Props?: {
181
+ /**
182
+ * User data for the autoscaling group.
183
+ */
184
+ userData: GuUserDataProps | UserData;
185
+ /**
186
+ * EC2 instance type. Note, ensure your code is built for the same
187
+ * architecture family (arm64 - 'Graviton' instances - or x64).
188
+ */
189
+ instanceType: InstanceType;
190
+ /**
191
+ * Enable and configures application logs.
192
+ */
193
+ applicationLogging?: ApplicationLoggingProps;
194
+ /**
195
+ * Configure IAM roles for autoscaling group EC2 instances.
196
+ */
197
+ roleConfiguration?: GuInstanceRoleProps;
198
+ /**
199
+ * Add block devices (additional storage).
200
+ */
201
+ blockDevices?: BlockDevice[];
202
+ /**
203
+ * Autoscaling group min and max sizes.
204
+ */
205
+ scaling: GuAsgCapacity;
206
+ /**
207
+ * Configure AMIgo image recipe. This is only necessary if you are using GuCDK to generate your riff-raff.yaml file.
208
+ */
209
+ imageRecipe?: string | AmigoProps;
210
+ /**
211
+ * Set http put response hop limit for the launch template.
212
+ * It can be necessary to raise this value from the default of 1
213
+ * for example when sharing the instance profile with a docker container running on the instance.
214
+ */
215
+ instanceMetadataHopLimit?: number;
216
+ /**
217
+ * Specify an update policy for the ASG created by this pattern.
218
+ *
219
+ * @see https://docs.aws.amazon.com/cdk/api/latest/docs/aws-autoscaling-readme.html#update-policy
220
+ *
221
+ * @defaultValue UpdatePolicy.none() - Cloudformation does not attempt to rotate instances in the ASG
222
+ * and must rely on riffraff to do so.
223
+ */
224
+ updatePolicy?: UpdatePolicy;
225
+ /**
226
+ * Enable CloudFormation-only deployments for EC2.
227
+ *
228
+ * In order to use this feature you must include the build number in the name of the artifact that you upload to
229
+ * Riff-Raff. Your userData should also refer to this versioned artifact.
230
+ *
231
+ * Users migrating from the `GuEc2AppExperimental` pattern can keep existing deployment behaviour by configuring
232
+ * these props.
233
+ */
234
+ versionedDeployments?: {
235
+ enabled: boolean;
236
+ buildIdentifier: string;
237
+ slowStartDuration?: Duration;
238
+ };
239
+ /**
240
+ * You can specify how long after an instance reaches the InService state it waits before contributing
241
+ * usage data to the aggregated metrics. This specified time is called the default instance warmup.
242
+ * This keeps dynamic scaling from being affected by metrics for individual instances that aren't yet
243
+ * handling application traffic and that might be experiencing temporarily high usage of compute resources.
244
+ *
245
+ * @see https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-default-instance-warmup.html
246
+ */
247
+ defaultInstanceWarmup?: Duration;
248
+ /**
249
+ * How often to send EC2 metrics, such as CPU usage.
250
+ * By default, AWS will produce `5Minute` granular metrics.
251
+ *
252
+ * It is recommended to produce `1Minute` granular metrics in production,
253
+ * especially when using ASG metrics to trigger horizontal scaling as it allows for earlier scaling.
254
+ *
255
+ * @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html
256
+ */
257
+ instanceMetricGranularity: "1Minute" | "5Minute";
258
+ };
259
+ /**
260
+ * If you want to use an ECS service and ECS tasks to serve requests, then pass in relevant props here.
261
+ *
262
+ * If you are setting both `ecsProps` and `ec2Props` (i.e. if you are migrating from EC2 to ECS) then you must also
263
+ * specify weights for each compute type using `targetGroupWeights`.
264
+ */
265
+ ecsProps?: {
266
+ /**
267
+ * Which image to run.
268
+ * This should be the image digest (e.g. 'sha256:abc123') to ensure immutable deployments.
269
+ *
270
+ * @see https://docs.docker.com/dhi/core-concepts/digests
271
+ */
272
+ imageIdentifier: string;
273
+ cpu: number;
274
+ memoryLimitMiB: number;
275
+ /**
276
+ * ECR repository name which contains your images. This defaults to the name of your GitHub repository as we
277
+ * expect there to be a one-to-one mapping between GitHub repositories and ECR repositories.
278
+ */
279
+ repositoryName?: string;
280
+ /**
281
+ * The number of tasks that you want to run. We recommend running 3 tasks for production services which need a high
282
+ * level of availability so that all 3 Availability Zones are utilised.
283
+ */
284
+ scaling: {
285
+ /**
286
+ * Scaling actions will never scale down below this threshold. This also controls the number of tasks that
287
+ * your ECS service will launch when it is first created.
288
+ */
289
+ minimumTasks: number;
290
+ /**
291
+ * Scaling actions will never scale up above this threshold.
292
+ *
293
+ * Note that this max can be exceeded when a deployment runs (unlike the ASG max size). E.g. if maximumTasks is 6,
294
+ * the service is running 6 tasks and a deployment starts, the ECS service will briefly run with 12 tasks to get
295
+ * the deployment through.
296
+ */
297
+ maximumTasks: number;
298
+ };
299
+ };
300
+ /**
301
+ * If you are specifying `ec2Props` and `ecsProps` use these weights to distribute traffic across the different compute
302
+ * types. The weights must sum to 999.
303
+ */
304
+ targetGroupWeights?: {
305
+ ecs: number;
306
+ ec2: number;
307
+ };
308
+ }
309
+ interface TargetGroups {
310
+ ec2?: GuApplicationTargetGroup;
311
+ ecs?: GuApplicationTargetGroup;
312
+ }
313
+ export declare class GuLoadBalancedAppExperimental extends Construct {
314
+ /**
315
+ * The VPC that the pattern's load balancer, EC2 instances and/or ECS tasks are running in.
316
+ */
317
+ readonly vpc: IVpc;
318
+ /**
319
+ * The certificate associated with your load balancer. This will only be available if `certificateProps` were
320
+ * passed in.
321
+ */
322
+ readonly certificate?: GuCertificate;
323
+ /**
324
+ * The application load balancer that this pattern creates.
325
+ */
326
+ readonly loadBalancer: GuApplicationLoadBalancer;
327
+ /**
328
+ * The AutoScaling Group that this pattern creates. This will only be available if `ec2Props` are specified.
329
+ */
330
+ readonly autoScalingGroup?: GuAutoScalingGroup;
331
+ /**
332
+ * The ECS Service that this pattern creates. This will only be available if `ecsProps` are specified.
333
+ */
334
+ readonly ecsService?: FargateService;
335
+ /**
336
+ * The load balancer listener that this pattern creates.
337
+ */
338
+ readonly listener: GuHttpsApplicationListener;
339
+ /**
340
+ * The target groups capable of serving traffic routed to this pattern.
341
+ *
342
+ * If `ec2Props` were passed in but `ecsProps` were not, there will be a single EC2 target group.
343
+ * Similarly, if `ecsProps` were passed in but `ec2Props` were not, there will be a single ECS target group.
344
+ * If both `ec2Props` and `ecsProps` were passed in (e.g. during a migration) then both target groups will be
345
+ * available.
346
+ */
347
+ readonly targetGroups: TargetGroups;
348
+ constructor(scope: GuStack, props: GuLoadBalancedAppExperimentalProps);
349
+ }
350
+ export {};
351
+ //# sourceMappingURL=gu-load-balanced-app.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gu-load-balanced-app.d.ts","sourceRoot":"","sources":["../../../src/experimental/patterns/gu-load-balanced-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,QAAQ,EAAqB,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAuB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAQlG,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C,OAAO,EAGL,cAAc,EAMf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAQ5F,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAMhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAKh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