-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathservice.ts
1510 lines (1334 loc) · 42.9 KB
/
service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as ecr from 'aws-cdk-lib/aws-ecr';
import * as assets from 'aws-cdk-lib/aws-ecr-assets';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as kms from 'aws-cdk-lib/aws-kms';
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import * as cdk from 'aws-cdk-lib/core';
import { Lazy } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { CfnService } from 'aws-cdk-lib/aws-apprunner';
import { IVpcConnector } from './vpc-connector';
import { IAutoScalingConfiguration } from './auto-scaling-configuration';
import { IObservabilityConfiguration } from './observability-configuration';
/**
* The image repository types
*/
export enum ImageRepositoryType {
/**
* Amazon ECR Public
*/
ECR_PUBLIC = 'ECR_PUBLIC',
/**
* Amazon ECR
*/
ECR = 'ECR',
}
/**
* The number of CPU units reserved for each instance of your App Runner service.
*
*/
export class Cpu {
/**
* 0.25 vCPU
*/
public static readonly QUARTER_VCPU = Cpu.of('0.25 vCPU');
/**
* 0.5 vCPU
*/
public static readonly HALF_VCPU = Cpu.of('0.5 vCPU');
/**
* 1 vCPU
*/
public static readonly ONE_VCPU = Cpu.of('1 vCPU');
/**
* 2 vCPU
*/
public static readonly TWO_VCPU = Cpu.of('2 vCPU');
/**
* 4 vCPU
*/
public static readonly FOUR_VCPU = Cpu.of('4 vCPU');
/**
* Custom CPU unit
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-instanceconfiguration.html#cfn-apprunner-service-instanceconfiguration-cpu
*
* @param unit custom CPU unit
*/
public static of(unit: string): Cpu {
const numericPatterns = ['256', '512', '1024', '2048', '4096'];
const unitPatterns = ['0.25 vCPU', '0.5 vCPU', '1 vCPU', '2 vCPU', '4 vCPU'];
const allowedPatterns = numericPatterns.concat(unitPatterns);
const isValidValue = allowedPatterns.some(
(pattern) => pattern === unit,
);
if (!isValidValue) {
throw new Error('CPU value is invalid');
}
return new Cpu(unit);
}
/**
*
* @param unit The unit of CPU.
*/
private constructor(public readonly unit: string) { }
}
/**
* The amount of memory reserved for each instance of your App Runner service.
*/
export class Memory {
/**
* 0.5 GB(for 0.25 vCPU)
*/
public static readonly HALF_GB = Memory.of('0.5 GB');
/**
* 1 GB(for 0.25 or 0.5 vCPU)
*/
public static readonly ONE_GB = Memory.of('1 GB');
/**
* 2 GB(for 1 vCPU)
*/
public static readonly TWO_GB = Memory.of('2 GB');
/**
* 3 GB(for 1 vCPU)
*/
public static readonly THREE_GB = Memory.of('3 GB');
/**
* 4 GB(for 1 or 2 vCPU)
*/
public static readonly FOUR_GB = Memory.of('4 GB');
/**
* 6 GB(for 2 vCPU)
*/
public static readonly SIX_GB = Memory.of('6 GB');
/**
* 8 GB(for 4 vCPU)
*/
public static readonly EIGHT_GB = Memory.of('8 GB');
/**
* 10 GB(for 4 vCPU)
*/
public static readonly TEN_GB = Memory.of('10 GB');
/**
* 12 GB(for 4 vCPU)
*/
public static readonly TWELVE_GB = Memory.of('12 GB');
/**
* Custom Memory unit
*
* @param unit custom Memory unit
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-instanceconfiguration.html#cfn-apprunner-service-instanceconfiguration-memory
*/
public static of(unit: string): Memory {
const numericPatterns = ['512', '1024', '2048', '3072', '4096', '6144', '8192', '10240', '12288'];
const unitPatterns = ['0.5 GB', '1 GB', '2 GB', '3 GB', '4 GB', '6 GB', '8 GB', '10 GB', '12 GB'];
const allowedPatterns = numericPatterns.concat(unitPatterns);
const isValidValue = allowedPatterns.some(
(pattern) => pattern === unit,
);
if (!isValidValue) {
throw new Error('Memory value is invalid');
}
return new Memory(unit);
}
/**
*
* @param unit The unit of memory.
*/
private constructor(public readonly unit: string) { }
}
/**
* The code runtimes
*/
export class Runtime {
/**
* CORRETTO 8
*/
public static readonly CORRETTO_8 = Runtime.of('CORRETTO_8');
/**
* CORRETTO 11
*/
public static readonly CORRETTO_11 = Runtime.of('CORRETTO_11');
/**
* .NET 6
*/
public static readonly DOTNET_6 = Runtime.of('DOTNET_6');
/**
* Go 1.18
*/
public static readonly GO_1 = Runtime.of('GO_1');
/**
* NodeJS 12
*/
public static readonly NODEJS_12 = Runtime.of('NODEJS_12');
/**
* NodeJS 14
*/
public static readonly NODEJS_14 = Runtime.of('NODEJS_14');
/**
* NodeJS 16
*/
public static readonly NODEJS_16 = Runtime.of('NODEJS_16');
/**
* NodeJS 18
*/
public static readonly NODEJS_18 = Runtime.of('NODEJS_18');
/**
* PHP 8.1
*/
public static readonly PHP_81 = Runtime.of('PHP_81');
/**
* Python 3
*/
public static readonly PYTHON_3 = Runtime.of('PYTHON_3');
/**
* Python 3.11
*/
public static readonly PYTHON_311 = Runtime.of('PYTHON_311');
/**
* Ruby 3.1
*/
public static readonly RUBY_31 = Runtime.of('RUBY_31');
/**
* Other runtimes
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-codeconfigurationvalues.html#cfn-apprunner-service-codeconfigurationvalues-runtime for all available runtimes.
*
* @param name runtime name
*
*/
public static of(name: string) { return new Runtime(name); }
/**
*
* @param name The runtime name.
*/
private constructor(public readonly name: string) { }
}
/**
* The environment secret for the service.
*/
interface EnvironmentSecret {
readonly name: string;
readonly value: string;
}
/**
* The environment variable for the service.
*/
interface EnvironmentVariable {
readonly name: string;
readonly value: string;
}
/**
* Result of binding `Source` into a `Service`.
*/
export interface SourceConfig {
/**
* The image repository configuration (mutually exclusive with `codeRepository`).
*
* @default - no image repository.
*/
readonly imageRepository?: ImageRepository;
/**
* The ECR repository (required to grant the pull privileges for the iam role).
*
* @default - no ECR repository.
*/
readonly ecrRepository?: ecr.IRepository;
/**
* The code repository configuration (mutually exclusive with `imageRepository`).
*
* @default - no code repository.
*/
readonly codeRepository?: CodeRepositoryProps;
}
/**
* Properties of the Github repository for `Source.fromGitHub()`
*/
export interface GithubRepositoryProps {
/**
* The code configuration values. Will be ignored if configurationSource is `REPOSITORY`.
* @default - no values will be passed. The `apprunner.yaml` from the github reopsitory will be used instead.
*/
readonly codeConfigurationValues?: CodeConfigurationValues;
/**
* The source of the App Runner configuration.
*/
readonly configurationSource: ConfigurationSourceType;
/**
* The location of the repository that contains the source code.
*/
readonly repositoryUrl: string;
/**
* The branch name that represents a specific version for the repository.
*
* @default main
*/
readonly branch?: string;
/**
* ARN of the connection to Github. Only required for Github source.
*/
readonly connection: GitHubConnection;
}
/**
* Properties of the image repository for `Source.fromEcrPublic()`
*/
export interface EcrPublicProps {
/**
* The image configuration for the image from ECR Public.
* @default - no image configuration will be passed. The default `port` will be 8080.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-imageconfiguration.html#cfn-apprunner-service-imageconfiguration-port
*/
readonly imageConfiguration?: ImageConfiguration;
/**
* The ECR Public image URI.
*/
readonly imageIdentifier: string;
}
/**
* Properties of the image repository for `Source.fromEcr()`
*/
export interface EcrProps {
/**
* The image configuration for the image from ECR.
* @default - no image configuration will be passed. The default `port` will be 8080.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-imageconfiguration.html#cfn-apprunner-service-imageconfiguration-port
*/
readonly imageConfiguration?: ImageConfiguration;
/**
* Represents the ECR repository.
*/
readonly repository: ecr.IRepository;
/**
* Image tag.
* @default - 'latest'
* @deprecated use `tagOrDigest`
*/
readonly tag?: string;
/**
* Image tag or digest (digests must start with `sha256:`).
* @default - 'latest'
*/
readonly tagOrDigest?: string;
}
/**
* Properties of the image repository for `Source.fromAsset()`
*/
export interface AssetProps {
/**
* The image configuration for the image built from the asset.
* @default - no image configuration will be passed. The default `port` will be 8080.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-imageconfiguration.html#cfn-apprunner-service-imageconfiguration-port
*/
readonly imageConfiguration?: ImageConfiguration;
/**
* Represents the docker image asset.
*/
readonly asset: assets.DockerImageAsset;
}
/**
* Specify the secret's version id or version stage
*/
export interface SecretVersionInfo {
/**
* version id of the secret
*
* @default - use default version id
*/
readonly versionId?: string;
/**
* version stage of the secret
*
* @default - use default version stage
*/
readonly versionStage?: string;
}
/**
* Represents the App Runner service source.
*/
export abstract class Source {
/**
* Source from the GitHub repository.
*/
public static fromGitHub(props: GithubRepositoryProps): GithubSource {
return new GithubSource(props);
}
/**
* Source from the ECR repository.
*/
public static fromEcr(props: EcrProps): EcrSource {
return new EcrSource(props);
}
/**
* Source from the ECR Public repository.
*/
public static fromEcrPublic(props: EcrPublicProps): EcrPublicSource {
return new EcrPublicSource(props);
}
/**
* Source from local assets.
*/
public static fromAsset(props: AssetProps): AssetSource {
return new AssetSource(props);
}
/**
* Called when the Job is initialized to allow this object to bind.
*/
public abstract bind(scope: Construct): SourceConfig;
}
/**
* Represents the service source from a Github repository.
*/
export class GithubSource extends Source {
private readonly props: GithubRepositoryProps;
constructor(props: GithubRepositoryProps) {
super();
this.props = props;
}
public bind(_scope: Construct): SourceConfig {
return {
codeRepository: {
codeConfiguration: {
configurationSource: this.props.configurationSource,
configurationValues: this.props.codeConfigurationValues,
},
repositoryUrl: this.props.repositoryUrl,
sourceCodeVersion: {
type: 'BRANCH',
value: this.props.branch ?? 'main',
},
connection: this.props.connection,
},
};
}
}
/**
* Represents the service source from ECR.
*/
export class EcrSource extends Source {
private readonly props: EcrProps;
constructor(props: EcrProps) {
super();
this.props = props;
}
public bind(_scope: Construct): SourceConfig {
return {
imageRepository: {
imageConfiguration: this.props.imageConfiguration,
imageIdentifier: this.props.repository.repositoryUriForTagOrDigest(
this.props.tagOrDigest || this.props.tag || 'latest',
),
imageRepositoryType: ImageRepositoryType.ECR,
},
ecrRepository: this.props.repository,
};
}
}
/**
* Represents the service source from ECR Public.
*/
export class EcrPublicSource extends Source {
private readonly props: EcrPublicProps;
constructor(props: EcrPublicProps) {
super();
this.props = props;
}
public bind(_scope: Construct): SourceConfig {
return {
imageRepository: {
imageConfiguration: this.props.imageConfiguration,
imageIdentifier: this.props.imageIdentifier,
imageRepositoryType: ImageRepositoryType.ECR_PUBLIC,
},
};
}
}
/**
* Represents the source from local assets.
*/
export class AssetSource extends Source {
private readonly props: AssetProps;
constructor(props: AssetProps) {
super();
this.props = props;
}
public bind(_scope: Construct): SourceConfig {
return {
imageRepository: {
imageConfiguration: this.props.imageConfiguration,
imageIdentifier: this.props.asset.imageUri,
imageRepositoryType: ImageRepositoryType.ECR,
},
ecrRepository: this.props.asset.repository,
};
}
}
/**
* Describes the configuration that AWS App Runner uses to run an App Runner service
* using an image pulled from a source image repository.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-imageconfiguration.html
*/
export interface ImageConfiguration {
/**
* The port that your application listens to in the container.
*
* @default 8080
*/
readonly port?: number;
/**
* Environment variables that are available to your running App Runner service.
*
* @default - no environment variables
* @deprecated use environmentVariables.
*/
readonly environment?: { [key: string]: string };
/**
* Environment variables that are available to your running App Runner service.
*
* @default - no environment variables
*/
readonly environmentVariables?: { [key: string]: string };
/**
* Environment secrets that are available to your running App Runner service.
*
* @default - no environment secrets
*/
readonly environmentSecrets?: { [key: string]: Secret };
/**
* An optional command that App Runner runs to start the application in the source image.
* If specified, this command overrides the Docker image’s default start command.
*
* @default - no start command
*/
readonly startCommand?: string;
}
/**
* Describes a source image repository.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-imagerepository.html
*/
export interface ImageRepository {
/**
* The identifier of the image. For `ECR_PUBLIC` imageRepositoryType, the identifier domain should
* always be `public.ecr.aws`. For `ECR`, the pattern should be
* `([0-9]{12}.dkr.ecr.[a-z\-]+-[0-9]{1}.amazonaws.com\/.*)`.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-imagerepository.html
*/
readonly imageIdentifier: string;
/**
* The type of the image repository. This reflects the repository provider and whether
* the repository is private or public.
*/
readonly imageRepositoryType: ImageRepositoryType;
/**
* Configuration for running the identified image.
* @default - no image configuration will be passed. The default `port` will be 8080.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-imageconfiguration.html#cfn-apprunner-service-imageconfiguration-port
*/
readonly imageConfiguration?: ImageConfiguration;
}
/**
* Identifies a version of code that AWS App Runner refers to within a source code repository.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-sourcecodeversion.html
*/
export interface SourceCodeVersion {
/**
* The type of version identifier.
*/
readonly type: string;
/**
* A source code version.
*/
readonly value: string;
}
/**
* Properties of the CodeRepository.
*/
export interface CodeRepositoryProps {
/**
* Configuration for building and running the service from a source code repository.
*/
readonly codeConfiguration: CodeConfiguration;
/**
* The location of the repository that contains the source code.
*/
readonly repositoryUrl: string;
/**
* The version that should be used within the source code repository.
*/
readonly sourceCodeVersion: SourceCodeVersion;
/**
* The App Runner connection for GitHub.
*/
readonly connection: GitHubConnection;
}
/**
* Properties of the AppRunner Service
*/
export interface ServiceProps {
/**
* The source of the repository for the service.
*/
readonly source: Source;
/**
* Specifies whether to enable continuous integration from the source repository.
*
* If true, continuous integration from the source repository is enabled for the App Runner service.
* Each repository change (including any source code commit or new image version) starts a deployment.
* By default, App Runner sets to false for a source image that uses an ECR Public repository or an ECR repository that's in an AWS account other than the one that the service is in.
* App Runner sets to true in all other cases (which currently include a source code repository or a source image using a same-account ECR repository).
*
* @default - no value will be passed.
*/
readonly autoDeploymentsEnabled?: boolean;
/**
* Specifies an App Runner Auto Scaling Configuration.
*
* A default configuration is either the AWS recommended configuration,
* or the configuration you set as the default.
*
* @see https://docs.aws.amazon.com/apprunner/latest/dg/manage-autoscaling.html
*
* @default - the latest revision of a default auto scaling configuration is used.
*/
readonly autoScalingConfiguration?: IAutoScalingConfiguration;
/**
* The number of CPU units reserved for each instance of your App Runner service.
*
* @default Cpu.ONE_VCPU
*/
readonly cpu?: Cpu;
/**
* The amount of memory reserved for each instance of your App Runner service.
*
* @default Memory.TWO_GB
*/
readonly memory?: Memory;
/**
* The IAM role that grants the App Runner service access to a source repository.
* It's required for ECR image repositories (but not for ECR Public repositories).
*
* The role must be assumable by the 'build.apprunner.amazonaws.com' service principal.
*
* @see https://docs.aws.amazon.com/apprunner/latest/dg/security_iam_service-with-iam.html#security_iam_service-with-iam-roles-service.access
*
* @default - generate a new access role.
*/
readonly accessRole?: iam.IRole;
/**
* The IAM role that provides permissions to your App Runner service.
* These are permissions that your code needs when it calls any AWS APIs.
*
* The role must be assumable by the 'tasks.apprunner.amazonaws.com' service principal.
*
* @see https://docs.aws.amazon.com/apprunner/latest/dg/security_iam_service-with-iam.html#security_iam_service-with-iam-roles-service.instance
*
* @default - generate a new instance role.
*/
readonly instanceRole?: iam.IRole;
/**
* Name of the service.
*
* @default - auto-generated if undefined.
*/
readonly serviceName?: string;
/**
* Settings for an App Runner VPC connector to associate with the service.
*
* @default - no VPC connector, uses the DEFAULT egress type instead
*/
readonly vpcConnector?: IVpcConnector;
/**
* Specifies whether your App Runner service is publicly accessible.
*
* If you use `VpcIngressConnection`, you must set this property to `false`.
*
* @default true
*/
readonly isPubliclyAccessible?: boolean;
/**
* Settings for the health check that AWS App Runner performs to monitor the health of a service.
*
* You can specify it by static methods `HealthCheck.http` or `HealthCheck.tcp`.
*
* @default - no health check configuration
*/
readonly healthCheck?: HealthCheck;
/**
* The customer managed key that AWS App Runner uses to encrypt copies of the source repository and service logs.
*
* @default - Use an AWS managed key
*/
readonly kmsKey?: kms.IKey;
/**
* The IP address type for your incoming public network configuration.
*
* @default - IpAddressType.IPV4
*/
readonly ipAddressType?: IpAddressType;
/**
* Settings for an App Runner observability configuration.
*
* @default - no observability configuration resource is associated with the service.
*/
readonly observabilityConfiguration?: IObservabilityConfiguration;
}
/**
* The source of the App Runner configuration.
*/
export enum ConfigurationSourceType {
/**
* App Runner reads configuration values from `the apprunner.yaml` file in the source code repository
* and ignores `configurationValues`.
*/
REPOSITORY = 'REPOSITORY',
/**
* App Runner uses configuration values provided in `configurationValues` and ignores the `apprunner.yaml`
* file in the source code repository.
*/
API = 'API',
}
/**
* Describes the configuration that AWS App Runner uses to build and run an App Runner service
* from a source code repository.
*
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apprunner-service-codeconfiguration.html
*/
export interface CodeConfiguration {
/**
* The basic configuration for building and running the App Runner service.
* Use it to quickly launch an App Runner service without providing a apprunner.yaml file in the
* source code repository (or ignoring the file if it exists).
*
* @default - not specified. Use `apprunner.yaml` instead.
*/
readonly configurationValues?: CodeConfigurationValues;
/**
* The source of the App Runner configuration.
*/
readonly configurationSource: ConfigurationSourceType;
}
/**
* Describes resources needed to authenticate access to some source repositories.
* The specific resource depends on the repository provider.
*/
interface AuthenticationConfiguration {
/**
* The Amazon Resource Name (ARN) of the IAM role that grants the App Runner service access to a
* source repository. It's required for ECR image repositories (but not for ECR Public repositories).
*
* @default - no access role.
*/
readonly accessRoleArn?: string;
/**
* The Amazon Resource Name (ARN) of the App Runner connection that enables the App Runner service
* to connect to a source repository. It's required for GitHub code repositories.
*
* @default - no connection.
*/
readonly connectionArn?: string;
}
/**
* Describes the basic configuration needed for building and running an AWS App Runner service.
* This type doesn't support the full set of possible configuration options. Fur full configuration capabilities,
* use a `apprunner.yaml` file in the source code repository.
*/
export interface CodeConfigurationValues {
/**
* The command App Runner runs to build your application.
*
* @default - no build command.
*/
readonly buildCommand?: string;
/**
* The port that your application listens to in the container.
*
* @default 8080
*/
readonly port?: string;
/**
* A runtime environment type for building and running an App Runner service. It represents
* a programming language runtime.
*/
readonly runtime: Runtime;
/**
* The environment variables that are available to your running App Runner service.
*
* @default - no environment variables.
* @deprecated use environmentVariables.
*/
readonly environment?: { [key: string]: string };
/**
* The environment variables that are available to your running App Runner service.
*
* @default - no environment variables.
*/
readonly environmentVariables?: { [key: string]: string };
/**
* The environment secrets that are available to your running App Runner service.
*
* @default - no environment secrets.
*/
readonly environmentSecrets?: { [key: string]: Secret };
/**
* The command App Runner runs to start your application.
*
* @default - no start command.
*/
readonly startCommand?: string;
}
/**
* Represents the App Runner connection that enables the App Runner service to connect
* to a source repository. It's required for GitHub code repositories.
*/
export class GitHubConnection {
/**
* Using existing App Runner connection by specifying the connection ARN.
* @param arn connection ARN
* @returns Connection
*/
public static fromConnectionArn(arn: string): GitHubConnection {
return new GitHubConnection(arn);
}
/**
* The ARN of the Connection for App Runner service to connect to the repository.
*/
public readonly connectionArn: string;
constructor(arn: string) {
this.connectionArn = arn;
}
}
/**
* The health check protocol type
*/
export enum HealthCheckProtocolType {
/**
* HTTP protocol
*/
HTTP = 'HTTP',
/**
* TCP protocol
*/
TCP = 'TCP',
}
/**
* Describes the settings for the health check that AWS App Runner performs to monitor the health of a service.
*/
interface HealthCheckCommonOptions {
/**
* The number of consecutive checks that must succeed before App Runner decides that the service is healthy.
*
* @default 1
*/
readonly healthyThreshold?: number;
/**
* The time interval, in seconds, between health checks.
*
* @default Duration.seconds(5)
*/
readonly interval?: cdk.Duration;
/**
* The time, in seconds, to wait for a health check response before deciding it failed.
*
* @default Duration.seconds(2)
*/
readonly timeout?: cdk.Duration;
/**
* The number of consecutive checks that must fail before App Runner decides that the service is unhealthy.
*
* @default 5
*/
readonly unhealthyThreshold?: number;
}
/**
* Properties used to define HTTP Based healthchecks.
*/
export interface HttpHealthCheckOptions extends HealthCheckCommonOptions {
/**
* The URL that health check requests are sent to.
*
* @default /
*/
readonly path?: string;
}
/**
* Properties used to define TCP Based healthchecks.
*/
export interface TcpHealthCheckOptions extends HealthCheckCommonOptions { }
/**
* Contains static factory methods for creating health checks for different protocols
*/
export class HealthCheck {
/**
* Construct a HTTP health check
*/
public static http(options: HttpHealthCheckOptions = {}): HealthCheck {
return new HealthCheck(
HealthCheckProtocolType.HTTP,
options.healthyThreshold,
options.interval,
options.timeout,
options.unhealthyThreshold,
options.path,
);
}
/**
* Construct a TCP health check
*/