@gradientedge/cdk-utils-aws 1.0.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.
- package/LICENSE +21 -0
- package/dist/src/common/construct.d.ts +85 -0
- package/dist/src/common/construct.js +125 -0
- package/dist/src/common/index.d.ts +4 -0
- package/dist/src/common/index.js +4 -0
- package/dist/src/common/resource-name-formatter.d.ts +13 -0
- package/dist/src/common/resource-name-formatter.js +30 -0
- package/dist/src/common/stack.d.ts +62 -0
- package/dist/src/common/stack.js +139 -0
- package/dist/src/common/types.d.ts +30 -0
- package/dist/src/common/types.js +1 -0
- package/dist/src/construct/api-to-any-target/index.d.ts +3 -0
- package/dist/src/construct/api-to-any-target/index.js +3 -0
- package/dist/src/construct/api-to-any-target/main.d.ts +47 -0
- package/dist/src/construct/api-to-any-target/main.js +154 -0
- package/dist/src/construct/api-to-any-target/target.d.ts +23 -0
- package/dist/src/construct/api-to-any-target/target.js +14 -0
- package/dist/src/construct/api-to-any-target/types.d.ts +60 -0
- package/dist/src/construct/api-to-any-target/types.js +1 -0
- package/dist/src/construct/api-to-eventbridge-target/api.d.ts +34 -0
- package/dist/src/construct/api-to-eventbridge-target/api.js +23 -0
- package/dist/src/construct/api-to-eventbridge-target/event.d.ts +15 -0
- package/dist/src/construct/api-to-eventbridge-target/event.js +12 -0
- package/dist/src/construct/api-to-eventbridge-target/index.d.ts +4 -0
- package/dist/src/construct/api-to-eventbridge-target/index.js +4 -0
- package/dist/src/construct/api-to-eventbridge-target/main.d.ts +121 -0
- package/dist/src/construct/api-to-eventbridge-target/main.js +442 -0
- package/dist/src/construct/api-to-eventbridge-target/types.d.ts +100 -0
- package/dist/src/construct/api-to-eventbridge-target/types.js +1 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.d.ts +16 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.js +12 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/index.d.ts +3 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/index.js +3 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/main.d.ts +159 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/main.js +547 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/types.d.ts +22 -0
- package/dist/src/construct/api-to-eventbridge-target-with-sns/types.js +1 -0
- package/dist/src/construct/api-to-lambda-target/api.d.ts +35 -0
- package/dist/src/construct/api-to-lambda-target/api.js +24 -0
- package/dist/src/construct/api-to-lambda-target/index.d.ts +3 -0
- package/dist/src/construct/api-to-lambda-target/index.js +3 -0
- package/dist/src/construct/api-to-lambda-target/main.d.ts +70 -0
- package/dist/src/construct/api-to-lambda-target/main.js +218 -0
- package/dist/src/construct/api-to-lambda-target/types.d.ts +62 -0
- package/dist/src/construct/api-to-lambda-target/types.js +1 -0
- package/dist/src/construct/application-configuration/index.d.ts +2 -0
- package/dist/src/construct/application-configuration/index.js +2 -0
- package/dist/src/construct/application-configuration/main.d.ts +23 -0
- package/dist/src/construct/application-configuration/main.js +79 -0
- package/dist/src/construct/application-configuration/types.d.ts +6 -0
- package/dist/src/construct/application-configuration/types.js +1 -0
- package/dist/src/construct/event-handler/handler.d.ts +29 -0
- package/dist/src/construct/event-handler/handler.js +21 -0
- package/dist/src/construct/event-handler/index.d.ts +3 -0
- package/dist/src/construct/event-handler/index.js +3 -0
- package/dist/src/construct/event-handler/main.d.ts +91 -0
- package/dist/src/construct/event-handler/main.js +196 -0
- package/dist/src/construct/event-handler/types.d.ts +41 -0
- package/dist/src/construct/event-handler/types.js +1 -0
- package/dist/src/construct/index.d.ts +14 -0
- package/dist/src/construct/index.js +14 -0
- package/dist/src/construct/lambda-with-iam-access/index.d.ts +2 -0
- package/dist/src/construct/lambda-with-iam-access/index.js +2 -0
- package/dist/src/construct/lambda-with-iam-access/main.d.ts +78 -0
- package/dist/src/construct/lambda-with-iam-access/main.js +182 -0
- package/dist/src/construct/lambda-with-iam-access/types.d.ts +20 -0
- package/dist/src/construct/lambda-with-iam-access/types.js +1 -0
- package/dist/src/construct/piped-event-handler/index.d.ts +2 -0
- package/dist/src/construct/piped-event-handler/index.js +2 -0
- package/dist/src/construct/piped-event-handler/main.d.ts +38 -0
- package/dist/src/construct/piped-event-handler/main.js +62 -0
- package/dist/src/construct/piped-event-handler/types.d.ts +9 -0
- package/dist/src/construct/piped-event-handler/types.js +1 -0
- package/dist/src/construct/rest-api-lambda/index.d.ts +2 -0
- package/dist/src/construct/rest-api-lambda/index.js +2 -0
- package/dist/src/construct/rest-api-lambda/main.d.ts +96 -0
- package/dist/src/construct/rest-api-lambda/main.js +170 -0
- package/dist/src/construct/rest-api-lambda/types.d.ts +23 -0
- package/dist/src/construct/rest-api-lambda/types.js +1 -0
- package/dist/src/construct/rest-api-lambda-with-cache/index.d.ts +2 -0
- package/dist/src/construct/rest-api-lambda-with-cache/index.js +2 -0
- package/dist/src/construct/rest-api-lambda-with-cache/main.d.ts +56 -0
- package/dist/src/construct/rest-api-lambda-with-cache/main.js +118 -0
- package/dist/src/construct/rest-api-lambda-with-cache/types.d.ts +11 -0
- package/dist/src/construct/rest-api-lambda-with-cache/types.js +1 -0
- package/dist/src/construct/site-with-ecs-backend/constants.d.ts +4 -0
- package/dist/src/construct/site-with-ecs-backend/constants.js +5 -0
- package/dist/src/construct/site-with-ecs-backend/index.d.ts +3 -0
- package/dist/src/construct/site-with-ecs-backend/index.js +3 -0
- package/dist/src/construct/site-with-ecs-backend/main.d.ts +154 -0
- package/dist/src/construct/site-with-ecs-backend/main.js +437 -0
- package/dist/src/construct/site-with-ecs-backend/types.d.ts +49 -0
- package/dist/src/construct/site-with-ecs-backend/types.js +1 -0
- package/dist/src/construct/site-with-lambda-backend/constants.d.ts +5 -0
- package/dist/src/construct/site-with-lambda-backend/constants.js +6 -0
- package/dist/src/construct/site-with-lambda-backend/index.d.ts +3 -0
- package/dist/src/construct/site-with-lambda-backend/index.js +3 -0
- package/dist/src/construct/site-with-lambda-backend/main.d.ts +116 -0
- package/dist/src/construct/site-with-lambda-backend/main.js +316 -0
- package/dist/src/construct/site-with-lambda-backend/types.d.ts +45 -0
- package/dist/src/construct/site-with-lambda-backend/types.js +1 -0
- package/dist/src/construct/static-asset-deployment/index.d.ts +2 -0
- package/dist/src/construct/static-asset-deployment/index.js +2 -0
- package/dist/src/construct/static-asset-deployment/main.d.ts +41 -0
- package/dist/src/construct/static-asset-deployment/main.js +113 -0
- package/dist/src/construct/static-asset-deployment/types.d.ts +41 -0
- package/dist/src/construct/static-asset-deployment/types.js +1 -0
- package/dist/src/construct/static-site/index.d.ts +2 -0
- package/dist/src/construct/static-site/index.js +2 -0
- package/dist/src/construct/static-site/main.d.ts +84 -0
- package/dist/src/construct/static-site/main.js +136 -0
- package/dist/src/construct/static-site/types.d.ts +30 -0
- package/dist/src/construct/static-site/types.js +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +5 -0
- package/dist/src/services/api-gateway/index.d.ts +2 -0
- package/dist/src/services/api-gateway/index.js +2 -0
- package/dist/src/services/api-gateway/main.d.ts +68 -0
- package/dist/src/services/api-gateway/main.js +173 -0
- package/dist/src/services/api-gateway/types.d.ts +10 -0
- package/dist/src/services/api-gateway/types.js +1 -0
- package/dist/src/services/appconfig/constants.d.ts +12 -0
- package/dist/src/services/appconfig/constants.js +51 -0
- package/dist/src/services/appconfig/index.d.ts +3 -0
- package/dist/src/services/appconfig/index.js +3 -0
- package/dist/src/services/appconfig/main.d.ts +63 -0
- package/dist/src/services/appconfig/main.js +119 -0
- package/dist/src/services/appconfig/types.d.ts +17 -0
- package/dist/src/services/appconfig/types.js +1 -0
- package/dist/src/services/certificate-manager/index.d.ts +2 -0
- package/dist/src/services/certificate-manager/index.js +2 -0
- package/dist/src/services/certificate-manager/main.d.ts +41 -0
- package/dist/src/services/certificate-manager/main.js +62 -0
- package/dist/src/services/certificate-manager/types.d.ts +11 -0
- package/dist/src/services/certificate-manager/types.js +1 -0
- package/dist/src/services/cloudfront/index.d.ts +2 -0
- package/dist/src/services/cloudfront/index.js +2 -0
- package/dist/src/services/cloudfront/main.d.ts +96 -0
- package/dist/src/services/cloudfront/main.js +233 -0
- package/dist/src/services/cloudfront/types.d.ts +13 -0
- package/dist/src/services/cloudfront/types.js +1 -0
- package/dist/src/services/cloudtrail/index.d.ts +2 -0
- package/dist/src/services/cloudtrail/index.js +2 -0
- package/dist/src/services/cloudtrail/main.d.ts +44 -0
- package/dist/src/services/cloudtrail/main.js +71 -0
- package/dist/src/services/cloudtrail/types.d.ts +5 -0
- package/dist/src/services/cloudtrail/types.js +1 -0
- package/dist/src/services/cloudwatch/index.d.ts +3 -0
- package/dist/src/services/cloudwatch/index.js +3 -0
- package/dist/src/services/cloudwatch/logs.d.ts +47 -0
- package/dist/src/services/cloudwatch/logs.js +98 -0
- package/dist/src/services/cloudwatch/main.d.ts +207 -0
- package/dist/src/services/cloudwatch/main.js +552 -0
- package/dist/src/services/cloudwatch/types.d.ts +89 -0
- package/dist/src/services/cloudwatch/types.js +1 -0
- package/dist/src/services/codebuild/index.d.ts +1 -0
- package/dist/src/services/codebuild/index.js +1 -0
- package/dist/src/services/codebuild/main.d.ts +36 -0
- package/dist/src/services/codebuild/main.js +67 -0
- package/dist/src/services/constants.d.ts +4 -0
- package/dist/src/services/constants.js +5 -0
- package/dist/src/services/dynamodb/index.d.ts +2 -0
- package/dist/src/services/dynamodb/index.js +2 -0
- package/dist/src/services/dynamodb/main.d.ts +35 -0
- package/dist/src/services/dynamodb/main.js +72 -0
- package/dist/src/services/dynamodb/types.d.ts +10 -0
- package/dist/src/services/dynamodb/types.js +1 -0
- package/dist/src/services/elastic-container-registry/index.d.ts +1 -0
- package/dist/src/services/elastic-container-registry/index.js +1 -0
- package/dist/src/services/elastic-container-registry/main.d.ts +27 -0
- package/dist/src/services/elastic-container-registry/main.js +33 -0
- package/dist/src/services/elastic-container-service/index.d.ts +2 -0
- package/dist/src/services/elastic-container-service/index.js +2 -0
- package/dist/src/services/elastic-container-service/main.d.ts +56 -0
- package/dist/src/services/elastic-container-service/main.js +149 -0
- package/dist/src/services/elastic-container-service/types.d.ts +45 -0
- package/dist/src/services/elastic-container-service/types.js +1 -0
- package/dist/src/services/elastic-file-system/index.d.ts +2 -0
- package/dist/src/services/elastic-file-system/index.js +2 -0
- package/dist/src/services/elastic-file-system/main.d.ts +42 -0
- package/dist/src/services/elastic-file-system/main.js +76 -0
- package/dist/src/services/elastic-file-system/types.d.ts +15 -0
- package/dist/src/services/elastic-file-system/types.js +1 -0
- package/dist/src/services/elastic-kubernetes-service/index.d.ts +2 -0
- package/dist/src/services/elastic-kubernetes-service/index.js +2 -0
- package/dist/src/services/elastic-kubernetes-service/main.d.ts +32 -0
- package/dist/src/services/elastic-kubernetes-service/main.js +85 -0
- package/dist/src/services/elastic-kubernetes-service/types.d.ts +7 -0
- package/dist/src/services/elastic-kubernetes-service/types.js +1 -0
- package/dist/src/services/elasticache/index.d.ts +2 -0
- package/dist/src/services/elasticache/index.js +2 -0
- package/dist/src/services/elasticache/main.d.ts +47 -0
- package/dist/src/services/elasticache/main.js +90 -0
- package/dist/src/services/elasticache/types.d.ts +9 -0
- package/dist/src/services/elasticache/types.js +1 -0
- package/dist/src/services/eventbridge/index.d.ts +3 -0
- package/dist/src/services/eventbridge/index.js +3 -0
- package/dist/src/services/eventbridge/main.d.ts +93 -0
- package/dist/src/services/eventbridge/main.js +295 -0
- package/dist/src/services/eventbridge/target.d.ts +57 -0
- package/dist/src/services/eventbridge/target.js +61 -0
- package/dist/src/services/eventbridge/types.d.ts +43 -0
- package/dist/src/services/eventbridge/types.js +1 -0
- package/dist/src/services/evidently/index.d.ts +2 -0
- package/dist/src/services/evidently/index.js +2 -0
- package/dist/src/services/evidently/main.d.ts +56 -0
- package/dist/src/services/evidently/main.js +114 -0
- package/dist/src/services/evidently/types.d.ts +21 -0
- package/dist/src/services/evidently/types.js +1 -0
- package/dist/src/services/identity-access-management/index.d.ts +1 -0
- package/dist/src/services/identity-access-management/index.js +1 -0
- package/dist/src/services/identity-access-management/main.d.ts +263 -0
- package/dist/src/services/identity-access-management/main.js +609 -0
- package/dist/src/services/index.d.ts +28 -0
- package/dist/src/services/index.js +28 -0
- package/dist/src/services/key-management-service/index.d.ts +2 -0
- package/dist/src/services/key-management-service/index.js +2 -0
- package/dist/src/services/key-management-service/main.d.ts +28 -0
- package/dist/src/services/key-management-service/main.js +39 -0
- package/dist/src/services/key-management-service/types.d.ts +5 -0
- package/dist/src/services/key-management-service/types.js +1 -0
- package/dist/src/services/lambda/index.d.ts +2 -0
- package/dist/src/services/lambda/index.js +2 -0
- package/dist/src/services/lambda/main.d.ts +89 -0
- package/dist/src/services/lambda/main.js +232 -0
- package/dist/src/services/lambda/types.d.ts +54 -0
- package/dist/src/services/lambda/types.js +1 -0
- package/dist/src/services/route53/index.d.ts +2 -0
- package/dist/src/services/route53/index.js +2 -0
- package/dist/src/services/route53/main.d.ts +66 -0
- package/dist/src/services/route53/main.js +136 -0
- package/dist/src/services/route53/types.d.ts +6 -0
- package/dist/src/services/route53/types.js +1 -0
- package/dist/src/services/secrets-manager/index.d.ts +2 -0
- package/dist/src/services/secrets-manager/index.js +2 -0
- package/dist/src/services/secrets-manager/main.d.ts +43 -0
- package/dist/src/services/secrets-manager/main.js +71 -0
- package/dist/src/services/secrets-manager/types.d.ts +3 -0
- package/dist/src/services/secrets-manager/types.js +1 -0
- package/dist/src/services/simple-notification-service/index.d.ts +2 -0
- package/dist/src/services/simple-notification-service/index.js +2 -0
- package/dist/src/services/simple-notification-service/main.d.ts +38 -0
- package/dist/src/services/simple-notification-service/main.js +68 -0
- package/dist/src/services/simple-notification-service/types.d.ts +5 -0
- package/dist/src/services/simple-notification-service/types.js +1 -0
- package/dist/src/services/simple-queue-service/index.d.ts +2 -0
- package/dist/src/services/simple-queue-service/index.js +2 -0
- package/dist/src/services/simple-queue-service/main.d.ts +45 -0
- package/dist/src/services/simple-queue-service/main.js +101 -0
- package/dist/src/services/simple-queue-service/types.d.ts +15 -0
- package/dist/src/services/simple-queue-service/types.js +1 -0
- package/dist/src/services/simple-storage-service/index.d.ts +2 -0
- package/dist/src/services/simple-storage-service/index.js +2 -0
- package/dist/src/services/simple-storage-service/main.d.ts +79 -0
- package/dist/src/services/simple-storage-service/main.js +191 -0
- package/dist/src/services/simple-storage-service/types.d.ts +25 -0
- package/dist/src/services/simple-storage-service/types.js +1 -0
- package/dist/src/services/step-function/index.d.ts +2 -0
- package/dist/src/services/step-function/index.js +2 -0
- package/dist/src/services/step-function/main.d.ts +161 -0
- package/dist/src/services/step-function/main.js +380 -0
- package/dist/src/services/step-function/types.d.ts +88 -0
- package/dist/src/services/step-function/types.js +1 -0
- package/dist/src/services/systems-manager/index.d.ts +2 -0
- package/dist/src/services/systems-manager/index.js +2 -0
- package/dist/src/services/systems-manager/main.d.ts +55 -0
- package/dist/src/services/systems-manager/main.js +97 -0
- package/dist/src/services/systems-manager/types.d.ts +9 -0
- package/dist/src/services/systems-manager/types.js +1 -0
- package/dist/src/services/virtual-private-cloud/index.d.ts +2 -0
- package/dist/src/services/virtual-private-cloud/index.js +2 -0
- package/dist/src/services/virtual-private-cloud/ipv6.d.ts +7 -0
- package/dist/src/services/virtual-private-cloud/ipv6.js +38 -0
- package/dist/src/services/virtual-private-cloud/main.d.ts +43 -0
- package/dist/src/services/virtual-private-cloud/main.js +87 -0
- package/dist/src/services/virtual-private-cloud/types.d.ts +4 -0
- package/dist/src/services/virtual-private-cloud/types.js +1 -0
- package/dist/src/services/web-application-firewall/index.d.ts +2 -0
- package/dist/src/services/web-application-firewall/index.js +2 -0
- package/dist/src/services/web-application-firewall/main.d.ts +35 -0
- package/dist/src/services/web-application-firewall/main.js +61 -0
- package/dist/src/services/web-application-firewall/types.d.ts +9 -0
- package/dist/src/services/web-application-firewall/types.js +1 -0
- package/dist/src/types/index.d.ts +6 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/utils/index.d.ts +45 -0
- package/dist/src/utils/index.js +61 -0
- package/package.json +44 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager';
|
|
2
|
+
import { CachePolicy, Distribution, FunctionAssociation, IFunction, OriginRequestPolicy, ResponseHeadersPolicy } from 'aws-cdk-lib/aws-cloudfront';
|
|
3
|
+
import { HttpOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';
|
|
4
|
+
import { IVpc } from 'aws-cdk-lib/aws-ec2';
|
|
5
|
+
import { AssetImage, Cluster, FargateService, FargateTaskDefinition } from 'aws-cdk-lib/aws-ecs';
|
|
6
|
+
import { FileSystem } from 'aws-cdk-lib/aws-efs';
|
|
7
|
+
import { ApplicationListener, ApplicationLoadBalancer, ApplicationTargetGroup } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
|
|
8
|
+
import { PolicyDocument, Role } from 'aws-cdk-lib/aws-iam';
|
|
9
|
+
import { LogGroup } from 'aws-cdk-lib/aws-logs';
|
|
10
|
+
import { IHostedZone } from 'aws-cdk-lib/aws-route53';
|
|
11
|
+
import { IBucket } from 'aws-cdk-lib/aws-s3';
|
|
12
|
+
import { Construct } from 'constructs';
|
|
13
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
14
|
+
import { SiteCachePolicyProps, SiteResponseHeadersPolicyProps, SiteWithEcsBackendProps } from './types.js';
|
|
15
|
+
/**
|
|
16
|
+
* @classdesc Provides a construct to create and deploy a site hosted with an clustered ECS/ELB backend
|
|
17
|
+
* @example
|
|
18
|
+
* import { SiteWithEcsBackend, SiteWithEcsBackendProps } '@gradientedge/cdk-utils'
|
|
19
|
+
* import { Construct } from 'constructs'
|
|
20
|
+
*
|
|
21
|
+
* class CustomConstruct extends SiteWithEcsBackend {
|
|
22
|
+
* constructor(parent: Construct, id: string, props: SiteWithEcsBackendProps) {
|
|
23
|
+
* super(parent, id, props)
|
|
24
|
+
* this.props = props
|
|
25
|
+
* this.id = id
|
|
26
|
+
* this.initResources()
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*/
|
|
30
|
+
export declare class SiteWithEcsBackend extends CommonConstruct {
|
|
31
|
+
props: SiteWithEcsBackendProps;
|
|
32
|
+
id: string;
|
|
33
|
+
siteHostedZone: IHostedZone;
|
|
34
|
+
siteCertificate: ICertificate;
|
|
35
|
+
siteRegionalCertificate: ICertificate;
|
|
36
|
+
siteEcsPolicy: PolicyDocument;
|
|
37
|
+
siteEcsRole: Role;
|
|
38
|
+
siteEcsEnvironment: {
|
|
39
|
+
[key: string]: string;
|
|
40
|
+
};
|
|
41
|
+
siteVpc: IVpc;
|
|
42
|
+
siteSecrets: any;
|
|
43
|
+
siteEcsCluster: Cluster;
|
|
44
|
+
siteEcsLogGroup: LogGroup;
|
|
45
|
+
siteEcsBuildArgs: any;
|
|
46
|
+
siteEcsContainerImage: AssetImage;
|
|
47
|
+
siteEcsService: FargateService;
|
|
48
|
+
siteEcsTaskDefinition: FargateTaskDefinition;
|
|
49
|
+
siteEcsListener: ApplicationListener;
|
|
50
|
+
siteEcsLoadBalancer: ApplicationLoadBalancer;
|
|
51
|
+
siteEcsTargetGroup: ApplicationTargetGroup;
|
|
52
|
+
siteFileSystem: FileSystem;
|
|
53
|
+
siteLogBucket: IBucket;
|
|
54
|
+
siteOrigin: HttpOrigin;
|
|
55
|
+
siteDistribution: Distribution;
|
|
56
|
+
siteInternalDomainName: string;
|
|
57
|
+
siteExternalDomainName: string;
|
|
58
|
+
siteDomainNames: string[];
|
|
59
|
+
siteCloudfrontFunction: IFunction;
|
|
60
|
+
siteFunctionAssociations: FunctionAssociation[];
|
|
61
|
+
siteOriginRequestPolicy: OriginRequestPolicy;
|
|
62
|
+
siteOriginResponseHeadersPolicy?: ResponseHeadersPolicy;
|
|
63
|
+
siteCachePolicy: CachePolicy;
|
|
64
|
+
constructor(parent: Construct, id: string, props: SiteWithEcsBackendProps);
|
|
65
|
+
/**
|
|
66
|
+
* @summary Initialise and provision resources
|
|
67
|
+
*/
|
|
68
|
+
initResources(): void;
|
|
69
|
+
/**
|
|
70
|
+
* @summary Method to resolve a hosted zone based on domain attributes
|
|
71
|
+
*/
|
|
72
|
+
protected resolveHostedZone(): void;
|
|
73
|
+
/**
|
|
74
|
+
* @summary Method to resolve a certificate based on attributes
|
|
75
|
+
*/
|
|
76
|
+
protected resolveCertificate(): void;
|
|
77
|
+
protected resolveGlobalCertificate(): void;
|
|
78
|
+
protected resolveRegionalCertificate(): void;
|
|
79
|
+
/**
|
|
80
|
+
* @summary Method to resolve secrets from SecretsManager
|
|
81
|
+
* - To be implemented in the overriding method in the implementation class
|
|
82
|
+
*/
|
|
83
|
+
protected resolveSiteSecrets(): void;
|
|
84
|
+
/**
|
|
85
|
+
* @summary Method to resolve site domain names
|
|
86
|
+
*/
|
|
87
|
+
protected resolveSiteDomainNames(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Create VPC
|
|
90
|
+
*/
|
|
91
|
+
protected createVpc(): void;
|
|
92
|
+
/**
|
|
93
|
+
* @summary Method to create iam policy for ECS Task
|
|
94
|
+
*/
|
|
95
|
+
protected createEcsPolicy(): void;
|
|
96
|
+
/**
|
|
97
|
+
* @summary Method to create iam role for ECS Task
|
|
98
|
+
*/
|
|
99
|
+
protected createEcsRole(): void;
|
|
100
|
+
/**
|
|
101
|
+
* @summary Method to create environment variables used by ECS task
|
|
102
|
+
*/
|
|
103
|
+
protected createEcsEnvironment(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Method to create an ECS cluster
|
|
106
|
+
*/
|
|
107
|
+
protected createEcsCluster(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Method to create log group used by ECS task
|
|
110
|
+
*/
|
|
111
|
+
protected createEcsLogGroup(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Method to create docker build arguments for ECS Image step
|
|
114
|
+
*/
|
|
115
|
+
protected createEcsBuildArgs(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Method to create container image for ECS task
|
|
118
|
+
*/
|
|
119
|
+
protected createEcsContainerImage(): void;
|
|
120
|
+
/**
|
|
121
|
+
* Method to create Application Load balanced ECS Fargate Service
|
|
122
|
+
*/
|
|
123
|
+
protected createEcsService(): void;
|
|
124
|
+
/**
|
|
125
|
+
* Method to create log bucket for site distribution
|
|
126
|
+
*/
|
|
127
|
+
protected createSiteLogBucket(): void;
|
|
128
|
+
protected createSiteCachePolicy(id: string, siteCachePolicy: SiteCachePolicyProps): CachePolicy;
|
|
129
|
+
protected createSiteOriginCachePolicy(): void;
|
|
130
|
+
protected createSiteOriginRequestPolicy(): void;
|
|
131
|
+
protected createResponseHeaderPolicy(props: SiteResponseHeadersPolicyProps): ResponseHeadersPolicy | undefined;
|
|
132
|
+
protected createSiteOriginResponseHeadersPolicy(): void;
|
|
133
|
+
protected createSiteOrigin(): void;
|
|
134
|
+
/**
|
|
135
|
+
* @summary Method to create a site cloudfront function
|
|
136
|
+
*/
|
|
137
|
+
protected createSiteCloudfrontFunction(): void;
|
|
138
|
+
/**
|
|
139
|
+
* @summary Method to create a site cloudfront function associations
|
|
140
|
+
*/
|
|
141
|
+
protected resolveSiteFunctionAssociations(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Method to create Site distribution
|
|
144
|
+
*/
|
|
145
|
+
protected createDistribution(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Method to create Route53 records for distribution
|
|
148
|
+
*/
|
|
149
|
+
protected createNetworkMappings(): void;
|
|
150
|
+
/**
|
|
151
|
+
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
152
|
+
*/
|
|
153
|
+
protected invalidateDistributionCache(): void;
|
|
154
|
+
}
|
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
import { Duration } from 'aws-cdk-lib';
|
|
2
|
+
import { CachePolicy, FunctionEventType, OriginProtocolPolicy, OriginRequestPolicy, ResponseHeadersPolicy, } from 'aws-cdk-lib/aws-cloudfront';
|
|
3
|
+
import { HttpOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';
|
|
4
|
+
import { ContainerImage, LogDriver, } from 'aws-cdk-lib/aws-ecs';
|
|
5
|
+
import { ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns';
|
|
6
|
+
import { PolicyDocument, PolicyStatement } from 'aws-cdk-lib/aws-iam';
|
|
7
|
+
import _ from 'lodash';
|
|
8
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Provides a construct to create and deploy a site hosted with an clustered ECS/ELB backend
|
|
11
|
+
* @example
|
|
12
|
+
* import { SiteWithEcsBackend, SiteWithEcsBackendProps } '@gradientedge/cdk-utils'
|
|
13
|
+
* import { Construct } from 'constructs'
|
|
14
|
+
*
|
|
15
|
+
* class CustomConstruct extends SiteWithEcsBackend {
|
|
16
|
+
* constructor(parent: Construct, id: string, props: SiteWithEcsBackendProps) {
|
|
17
|
+
* super(parent, id, props)
|
|
18
|
+
* this.props = props
|
|
19
|
+
* this.id = id
|
|
20
|
+
* this.initResources()
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export class SiteWithEcsBackend extends CommonConstruct {
|
|
25
|
+
/* site properties */
|
|
26
|
+
props;
|
|
27
|
+
id;
|
|
28
|
+
/* site resources */
|
|
29
|
+
siteHostedZone;
|
|
30
|
+
siteCertificate;
|
|
31
|
+
siteRegionalCertificate;
|
|
32
|
+
siteEcsPolicy;
|
|
33
|
+
siteEcsRole;
|
|
34
|
+
siteEcsEnvironment;
|
|
35
|
+
siteVpc;
|
|
36
|
+
siteSecrets;
|
|
37
|
+
siteEcsCluster;
|
|
38
|
+
siteEcsLogGroup;
|
|
39
|
+
siteEcsBuildArgs = {};
|
|
40
|
+
siteEcsContainerImage;
|
|
41
|
+
siteEcsService;
|
|
42
|
+
siteEcsTaskDefinition;
|
|
43
|
+
siteEcsListener;
|
|
44
|
+
siteEcsLoadBalancer;
|
|
45
|
+
siteEcsTargetGroup;
|
|
46
|
+
siteFileSystem;
|
|
47
|
+
siteLogBucket;
|
|
48
|
+
siteOrigin;
|
|
49
|
+
siteDistribution;
|
|
50
|
+
siteInternalDomainName;
|
|
51
|
+
siteExternalDomainName;
|
|
52
|
+
siteDomainNames;
|
|
53
|
+
siteCloudfrontFunction;
|
|
54
|
+
siteFunctionAssociations;
|
|
55
|
+
siteOriginRequestPolicy;
|
|
56
|
+
siteOriginResponseHeadersPolicy;
|
|
57
|
+
siteCachePolicy;
|
|
58
|
+
constructor(parent, id, props) {
|
|
59
|
+
super(parent, id, props);
|
|
60
|
+
this.props = props;
|
|
61
|
+
this.id = id;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @summary Initialise and provision resources
|
|
65
|
+
*/
|
|
66
|
+
initResources() {
|
|
67
|
+
this.resolveHostedZone();
|
|
68
|
+
this.resolveCertificate();
|
|
69
|
+
this.resolveSiteSecrets();
|
|
70
|
+
this.resolveSiteDomainNames();
|
|
71
|
+
this.createSiteLogBucket();
|
|
72
|
+
this.createVpc();
|
|
73
|
+
this.createEcsPolicy();
|
|
74
|
+
this.createEcsRole();
|
|
75
|
+
this.createEcsEnvironment();
|
|
76
|
+
this.createEcsCluster();
|
|
77
|
+
this.createEcsLogGroup();
|
|
78
|
+
this.createEcsBuildArgs();
|
|
79
|
+
this.createEcsContainerImage();
|
|
80
|
+
this.createEcsService();
|
|
81
|
+
this.createSiteOriginCachePolicy();
|
|
82
|
+
this.createSiteOriginRequestPolicy();
|
|
83
|
+
this.createSiteOriginResponseHeadersPolicy();
|
|
84
|
+
this.createSiteOrigin();
|
|
85
|
+
this.createSiteCloudfrontFunction();
|
|
86
|
+
this.resolveSiteFunctionAssociations();
|
|
87
|
+
this.createDistribution();
|
|
88
|
+
this.createNetworkMappings();
|
|
89
|
+
this.invalidateDistributionCache();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* @summary Method to resolve a hosted zone based on domain attributes
|
|
93
|
+
*/
|
|
94
|
+
resolveHostedZone() {
|
|
95
|
+
this.siteHostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @summary Method to resolve a certificate based on attributes
|
|
99
|
+
*/
|
|
100
|
+
resolveCertificate() {
|
|
101
|
+
this.resolveGlobalCertificate();
|
|
102
|
+
this.resolveRegionalCertificate();
|
|
103
|
+
}
|
|
104
|
+
resolveGlobalCertificate() {
|
|
105
|
+
if (this.props.siteCertificate.useExistingCertificate &&
|
|
106
|
+
this.props.siteCertificate.certificateSsmName &&
|
|
107
|
+
this.props.siteCertificate.certificateRegion) {
|
|
108
|
+
this.props.siteCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-parameter`, this, this.props.siteCertificate.certificateSsmName, this.props.siteCertificate.certificateRegion);
|
|
109
|
+
}
|
|
110
|
+
this.siteCertificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.siteCertificate);
|
|
111
|
+
}
|
|
112
|
+
resolveRegionalCertificate() {
|
|
113
|
+
if (this.props.siteRegionalCertificate.useExistingCertificate &&
|
|
114
|
+
this.props.siteRegionalCertificate.certificateSsmName &&
|
|
115
|
+
this.props.siteRegionalCertificate.certificateRegion) {
|
|
116
|
+
this.props.siteRegionalCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-regional-certificate-parameter`, this, this.props.siteRegionalCertificate.certificateSsmName, this.props.siteRegionalCertificate.certificateRegion);
|
|
117
|
+
}
|
|
118
|
+
this.siteRegionalCertificate = this.acmManager.resolveCertificate(`${this.id}-regional-certificate`, this, this.props.siteRegionalCertificate, this.siteHostedZone);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @summary Method to resolve secrets from SecretsManager
|
|
122
|
+
* - To be implemented in the overriding method in the implementation class
|
|
123
|
+
*/
|
|
124
|
+
resolveSiteSecrets() { }
|
|
125
|
+
/**
|
|
126
|
+
* @summary Method to resolve site domain names
|
|
127
|
+
*/
|
|
128
|
+
resolveSiteDomainNames() {
|
|
129
|
+
/* the internal domain name used by ELB */
|
|
130
|
+
this.siteInternalDomainName =
|
|
131
|
+
this.isProductionStage() || this.props.skipStageForARecords
|
|
132
|
+
? `${this.props.siteSubDomain}-internal.${this.fullyQualifiedDomainName}`
|
|
133
|
+
: `${this.props.siteSubDomain}-internal-${this.props.stage}.${this.fullyQualifiedDomainName}`;
|
|
134
|
+
/* the external domain name exposed to CloudFront */
|
|
135
|
+
this.siteExternalDomainName =
|
|
136
|
+
this.isProductionStage() || this.props.skipStageForARecords
|
|
137
|
+
? `${this.props.siteSubDomain}.${this.fullyQualifiedDomainName}`
|
|
138
|
+
: `${this.props.siteSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`;
|
|
139
|
+
this.siteDomainNames = [this.siteExternalDomainName];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Create VPC
|
|
143
|
+
*/
|
|
144
|
+
createVpc() {
|
|
145
|
+
if (this.props.useExistingVpc) {
|
|
146
|
+
this.siteVpc = this.vpcManager.retrieveCommonVpc(`${this.id}-vpc`, this, this.props.siteVpc.vpcName);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.siteVpc = this.vpcManager.createCommonVpc(`${this.id}-vpc`, this, this.props.siteVpc, this.props.siteVpc.vpcName);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @summary Method to create iam policy for ECS Task
|
|
154
|
+
*/
|
|
155
|
+
createEcsPolicy() {
|
|
156
|
+
this.siteEcsPolicy = new PolicyDocument({
|
|
157
|
+
statements: [this.iamManager.statementForCreateAnyLogStream()],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @summary Method to create iam role for ECS Task
|
|
162
|
+
*/
|
|
163
|
+
createEcsRole() {
|
|
164
|
+
this.siteEcsRole = this.iamManager.createRoleForEcsExecution(`${this.id}-ecs-role`, this, this.siteEcsPolicy);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @summary Method to create environment variables used by ECS task
|
|
168
|
+
*/
|
|
169
|
+
createEcsEnvironment() {
|
|
170
|
+
this.siteEcsEnvironment = {
|
|
171
|
+
LOG_LEVEL: this.props.logLevel,
|
|
172
|
+
NODE_ENV: this.props.nodeEnv,
|
|
173
|
+
TZ: this.props.timezone,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Method to create an ECS cluster
|
|
178
|
+
*/
|
|
179
|
+
createEcsCluster() {
|
|
180
|
+
this.siteEcsCluster = this.ecsManager.createEcsCluster(`${this.id}-cluster`, this, this.props.siteCluster, this.siteVpc);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Method to create log group used by ECS task
|
|
184
|
+
*/
|
|
185
|
+
createEcsLogGroup() {
|
|
186
|
+
this.siteEcsLogGroup = this.logManager.createLogGroup(`${this.id}-ecs-log-group`, this, this.props.siteLog);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Method to create docker build arguments for ECS Image step
|
|
190
|
+
*/
|
|
191
|
+
createEcsBuildArgs() {
|
|
192
|
+
this.siteEcsBuildArgs = {};
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Method to create container image for ECS task
|
|
196
|
+
*/
|
|
197
|
+
createEcsContainerImage() {
|
|
198
|
+
this.siteEcsContainerImage = ContainerImage.fromAsset(this.props.siteEcsContainerImagePath, {
|
|
199
|
+
buildArgs: this.siteEcsBuildArgs,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Method to create Application Load balanced ECS Fargate Service
|
|
204
|
+
*/
|
|
205
|
+
createEcsService() {
|
|
206
|
+
const fargateService = new ApplicationLoadBalancedFargateService(this, `${this.id}-ecs-service`, {
|
|
207
|
+
assignPublicIp: true,
|
|
208
|
+
certificate: this.siteRegionalCertificate,
|
|
209
|
+
cluster: this.siteEcsCluster,
|
|
210
|
+
cpu: this.props.siteTask.cpu,
|
|
211
|
+
desiredCount: this.props.siteTask.desiredCount,
|
|
212
|
+
domainName: this.siteInternalDomainName,
|
|
213
|
+
domainZone: this.siteHostedZone,
|
|
214
|
+
enableECSManagedTags: true,
|
|
215
|
+
healthCheckGracePeriod: Duration.seconds(60),
|
|
216
|
+
listenerPort: this.props.siteTask.listenerPort,
|
|
217
|
+
loadBalancerName: this.resourceNameFormatter.format(this.props.siteTask.loadBalancerName ?? this.id),
|
|
218
|
+
maxHealthyPercent: this.props.siteTask.maxHealthyPercent,
|
|
219
|
+
memoryLimitMiB: this.props.siteTask.memoryLimitMiB,
|
|
220
|
+
minHealthyPercent: this.props.siteTask.minHealthyPercent,
|
|
221
|
+
serviceName: this.resourceNameFormatter.format(this.props.siteTask.serviceName ?? this.id),
|
|
222
|
+
taskDefinition: this.props.siteTask.taskDefinition,
|
|
223
|
+
taskImageOptions: {
|
|
224
|
+
containerPort: this.props.siteTask.taskImageOptions?.containerPort,
|
|
225
|
+
enableLogging: true,
|
|
226
|
+
environment: this.siteEcsEnvironment,
|
|
227
|
+
executionRole: this.siteEcsRole,
|
|
228
|
+
image: this.siteEcsContainerImage,
|
|
229
|
+
logDriver: LogDriver.awsLogs({
|
|
230
|
+
logGroup: this.siteEcsLogGroup,
|
|
231
|
+
logRetention: this.props.siteTask.logging?.logRetention,
|
|
232
|
+
multilinePattern: this.props.siteTask.logging?.multilinePattern,
|
|
233
|
+
streamPrefix: `${this.id}-${this.props.stage}/ecs`,
|
|
234
|
+
}),
|
|
235
|
+
secrets: this.siteSecrets,
|
|
236
|
+
taskRole: this.siteEcsRole,
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
if (this.props.siteHealthCheck) {
|
|
240
|
+
fargateService.targetGroup.configureHealthCheck({
|
|
241
|
+
enabled: this.props.siteHealthCheck.enabled ?? true,
|
|
242
|
+
healthyGrpcCodes: this.props.siteHealthCheck.healthyGrpcCodes,
|
|
243
|
+
healthyHttpCodes: this.props.siteHealthCheck.healthyHttpCodes,
|
|
244
|
+
healthyThresholdCount: this.props.siteHealthCheck.healthyThresholdCount,
|
|
245
|
+
interval: Duration.seconds(this.props.siteHealthCheck.intervalInSecs),
|
|
246
|
+
path: this.props.siteHealthCheck.path ?? '/',
|
|
247
|
+
port: this.props.siteHealthCheck.port,
|
|
248
|
+
protocol: this.props.siteHealthCheck.protocol,
|
|
249
|
+
timeout: Duration.seconds(this.props.siteHealthCheck.timeoutInSecs),
|
|
250
|
+
unhealthyThresholdCount: this.props.siteHealthCheck.unhealthyThresholdCount,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
this.siteEcsService = fargateService.service;
|
|
254
|
+
this.siteEcsTaskDefinition = fargateService.taskDefinition;
|
|
255
|
+
this.siteEcsListener = fargateService.listener;
|
|
256
|
+
this.siteEcsLoadBalancer = fargateService.loadBalancer;
|
|
257
|
+
this.siteEcsTargetGroup = fargateService.targetGroup;
|
|
258
|
+
fargateService.loadBalancer.logAccessLogs(this.siteLogBucket, 'alb');
|
|
259
|
+
if (this.props.siteTask.siteScaling) {
|
|
260
|
+
const scalableTaskCount = this.siteEcsService.autoScaleTaskCount({
|
|
261
|
+
maxCapacity: this.props.siteTask.siteScaling.maxCapacity ?? 4,
|
|
262
|
+
minCapacity: this.props.siteTask.siteScaling.minCapacity,
|
|
263
|
+
});
|
|
264
|
+
if (this.props.siteTask.siteScaling.scaleOnCpuUtilization) {
|
|
265
|
+
scalableTaskCount.scaleOnCpuUtilization(`${this.id}-cpu-scaling`, {
|
|
266
|
+
targetUtilizationPercent: this.props.siteTask.siteScaling.scaleOnCpuUtilization ?? 50,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
if (this.props.siteTask.siteScaling.scaleOnMemoryUtilization) {
|
|
270
|
+
scalableTaskCount.scaleOnMemoryUtilization(`${this.id}-mem-scaling`, {
|
|
271
|
+
targetUtilizationPercent: this.props.siteTask.siteScaling.scaleOnMemoryUtilization ?? 50,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (this.props.siteTask.siteScaling.scaleOnRequestsPerTarget) {
|
|
275
|
+
scalableTaskCount.scaleOnRequestCount(`${this.id}-req-count`, {
|
|
276
|
+
requestsPerTarget: this.props.siteTask.siteScaling.scaleOnRequestsPerTarget ?? 10000,
|
|
277
|
+
targetGroup: this.siteEcsTargetGroup,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (this.props.siteTask.siteScaling.scaleOnSchedule) {
|
|
281
|
+
scalableTaskCount.scaleOnSchedule(`${this.id}-schedule`, this.props.siteTask.siteScaling.scaleOnSchedule);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/* if enabled, add efs with access point and mount */
|
|
285
|
+
if (this.props.siteFileSystem) {
|
|
286
|
+
this.siteFileSystem = this.efsManager.createFileSystem(`${this.id}-fs`, this, this.props.siteFileSystem, this.siteVpc, this.props.siteFileSystemAccessPoints);
|
|
287
|
+
/* allow access to/from EFS from Fargate ECS service */
|
|
288
|
+
this.siteFileSystem.connections.allowDefaultPortFrom(this.siteEcsService.connections);
|
|
289
|
+
this.siteFileSystem.connections.allowDefaultPortTo(this.siteEcsService.connections);
|
|
290
|
+
/* add EFS permissions to ECS Role */
|
|
291
|
+
this.siteEcsRole.addToPolicy(new PolicyStatement(this.iamManager.statementForWriteEfs([this.siteFileSystem.fileSystemArn])));
|
|
292
|
+
/* add the efs volume to ecs task definition */
|
|
293
|
+
this.siteEcsTaskDefinition.addVolume({
|
|
294
|
+
efsVolumeConfiguration: {
|
|
295
|
+
authorizationConfig: this.props.siteFileSystem.authorizationConfig,
|
|
296
|
+
fileSystemId: this.siteFileSystem.fileSystemId,
|
|
297
|
+
rootDirectory: this.props.siteFileSystem.rootDirectory,
|
|
298
|
+
transitEncryption: this.props.siteFileSystem.transitEncryption,
|
|
299
|
+
transitEncryptionPort: this.props.siteFileSystem.transitEncryptionPort,
|
|
300
|
+
},
|
|
301
|
+
name: this.resourceNameFormatter.format(this.props.siteFileSystem?.fileSystemName ?? this.id),
|
|
302
|
+
});
|
|
303
|
+
if (this.props.siteTask.mountPoints && !_.isEmpty(this.props.siteTask.mountPoints)) {
|
|
304
|
+
_.forEach(this.props.siteTask.mountPoints, mountPoint => {
|
|
305
|
+
this.siteEcsTaskDefinition.defaultContainer?.addMountPoints({
|
|
306
|
+
containerPath: mountPoint.containerPath,
|
|
307
|
+
readOnly: mountPoint.readOnly,
|
|
308
|
+
sourceVolume: this.resourceNameFormatter.format(this.props.siteFileSystem?.fileSystemName ?? this.id),
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
this.addCfnOutput(`${this.id}-loadBalancerArn`, this.siteEcsLoadBalancer.loadBalancerArn ?? '');
|
|
314
|
+
this.addCfnOutput(`${this.id}-loadBalancerName`, this.siteEcsLoadBalancer.loadBalancerName ?? '');
|
|
315
|
+
this.addCfnOutput(`${this.id}-loadBalancerFullName`, this.siteEcsLoadBalancer.loadBalancerFullName ?? '');
|
|
316
|
+
this.addCfnOutput(`${this.id}-loadBalancerDnsName`, this.siteEcsLoadBalancer.loadBalancerDnsName ?? '');
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Method to create log bucket for site distribution
|
|
320
|
+
*/
|
|
321
|
+
createSiteLogBucket() {
|
|
322
|
+
this.siteLogBucket = this.s3Manager.createS3Bucket(`${this.id}-site-logs`, this, this.props.siteLogBucket);
|
|
323
|
+
}
|
|
324
|
+
createSiteCachePolicy(id, siteCachePolicy) {
|
|
325
|
+
if (!siteCachePolicy.cachePolicyName)
|
|
326
|
+
throw `SiteCachePolicy cachePolicyName undefined for ${id}`;
|
|
327
|
+
return new CachePolicy(this, `${id}`, {
|
|
328
|
+
cachePolicyName: this.resourceNameFormatter.format(siteCachePolicy.cachePolicyName),
|
|
329
|
+
comment: `Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
330
|
+
cookieBehavior: siteCachePolicy.cookieBehavior,
|
|
331
|
+
enableAcceptEncodingBrotli: siteCachePolicy.enableAcceptEncodingBrotli,
|
|
332
|
+
enableAcceptEncodingGzip: siteCachePolicy.enableAcceptEncodingGzip,
|
|
333
|
+
headerBehavior: siteCachePolicy.headerBehavior,
|
|
334
|
+
maxTtl: Duration.seconds(siteCachePolicy.maxTtlInSeconds),
|
|
335
|
+
minTtl: Duration.seconds(siteCachePolicy.minTtlInSeconds),
|
|
336
|
+
queryStringBehavior: siteCachePolicy.queryStringBehavior,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
createSiteOriginCachePolicy() {
|
|
340
|
+
if (!this.props.siteCachePolicy)
|
|
341
|
+
return;
|
|
342
|
+
this.siteCachePolicy = this.createSiteCachePolicy(`${this.id}-site-cache-policy`, this.props.siteCachePolicy);
|
|
343
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
344
|
+
cachePolicy: this.siteCachePolicy,
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
createSiteOriginRequestPolicy() {
|
|
348
|
+
if (!this.props.siteOriginRequestPolicy)
|
|
349
|
+
return;
|
|
350
|
+
if (!this.props.siteOriginRequestPolicy.originRequestPolicyName)
|
|
351
|
+
throw `SiteOriginRequestPolicy originRequestPolicyName undefined for ${this.id}`;
|
|
352
|
+
this.siteOriginRequestPolicy = new OriginRequestPolicy(this, `${this.id}-sorp`, {
|
|
353
|
+
comment: `Request Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
354
|
+
cookieBehavior: this.props.siteOriginRequestPolicy.cookieBehavior,
|
|
355
|
+
headerBehavior: this.props.siteOriginRequestPolicy.headerBehavior,
|
|
356
|
+
originRequestPolicyName: this.resourceNameFormatter.format(this.props.siteOriginRequestPolicy.originRequestPolicyName),
|
|
357
|
+
queryStringBehavior: this.props.siteOriginRequestPolicy.queryStringBehavior,
|
|
358
|
+
});
|
|
359
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
360
|
+
originRequestPolicy: this.siteOriginRequestPolicy,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
createResponseHeaderPolicy(props) {
|
|
364
|
+
if (!props)
|
|
365
|
+
return undefined;
|
|
366
|
+
if (!props.responseHeadersPolicyName)
|
|
367
|
+
throw `SiteResponseHeadersPolicy responseHeadersPolicyName undefined for ${this.id}`;
|
|
368
|
+
return new ResponseHeadersPolicy(this, `${this.id}-${props.type}-srhp`, {
|
|
369
|
+
...props,
|
|
370
|
+
comment: `Response Header Policy for ${props.type} for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
371
|
+
responseHeadersPolicyName: this.resourceNameFormatter.format(props.responseHeadersPolicyName),
|
|
372
|
+
securityHeadersBehavior: {
|
|
373
|
+
...props.securityHeadersBehavior,
|
|
374
|
+
strictTransportSecurity: {
|
|
375
|
+
...props.securityHeadersBehavior?.strictTransportSecurity,
|
|
376
|
+
accessControlMaxAge: Duration.seconds(props.securityHeadersBehavior?.strictTransportSecurity?.accessControlMaxAgeInSeconds),
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
createSiteOriginResponseHeadersPolicy() {
|
|
382
|
+
if (!this.props.siteOriginResponseHeadersPolicy)
|
|
383
|
+
return;
|
|
384
|
+
this.siteOriginResponseHeadersPolicy = this.createResponseHeaderPolicy(this.props.siteOriginResponseHeadersPolicy);
|
|
385
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
386
|
+
responseHeadersPolicy: this.siteOriginResponseHeadersPolicy,
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
createSiteOrigin() {
|
|
390
|
+
this.siteOrigin = new HttpOrigin(this.siteInternalDomainName, {
|
|
391
|
+
httpPort: this.props.siteTask.listenerPort,
|
|
392
|
+
originId: `${this.id}-server`,
|
|
393
|
+
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* @summary Method to create a site cloudfront function
|
|
398
|
+
*/
|
|
399
|
+
createSiteCloudfrontFunction() {
|
|
400
|
+
if (this.props.siteCloudfrontFunctionProps) {
|
|
401
|
+
this.siteCloudfrontFunction = this.cloudFrontManager.createCloudfrontFunction(`${this.id}-function`, this, this.props.siteCloudfrontFunctionProps);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* @summary Method to create a site cloudfront function associations
|
|
406
|
+
*/
|
|
407
|
+
resolveSiteFunctionAssociations() {
|
|
408
|
+
if (this.props.siteCloudfrontFunctionProps) {
|
|
409
|
+
this.siteFunctionAssociations = [
|
|
410
|
+
{
|
|
411
|
+
eventType: FunctionEventType.VIEWER_REQUEST,
|
|
412
|
+
function: this.siteCloudfrontFunction,
|
|
413
|
+
},
|
|
414
|
+
];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Method to create Site distribution
|
|
419
|
+
*/
|
|
420
|
+
createDistribution() {
|
|
421
|
+
this.siteDistribution = this.cloudFrontManager.createDistributionWithHttpOrigin(`${this.id}-distribution`, this, this.props.siteDistribution, this.siteOrigin, this.siteDomainNames, this.siteLogBucket, this.siteCertificate, this.siteFunctionAssociations, this.props.siteDistribution.defaultBehavior.responseHeadersPolicy);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Method to create Route53 records for distribution
|
|
425
|
+
*/
|
|
426
|
+
createNetworkMappings() {
|
|
427
|
+
this.route53Manager.createCloudFrontTargetARecord(`${this.id}-a-record`, this, this.siteDistribution, this.siteHostedZone, this.props.siteRecordName, this.props.skipStageForARecords);
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
431
|
+
*/
|
|
432
|
+
invalidateDistributionCache() {
|
|
433
|
+
if (this.props.siteCacheInvalidationDockerFilePath) {
|
|
434
|
+
this.cloudFrontManager.invalidateCache(`${this.id}-cache-invalidation`, this, this.props.siteCacheInvalidationDockerFilePath, this.siteDistribution.distributionId);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CommonStackProps } from '../../common/index.js';
|
|
2
|
+
import { AcmProps, CloudfrontFunctionProps, DistributionProps, EcsApplicationLoadBalancedFargateServiceProps, EcsClusterProps, EfsAccessPointOptions, EfsFileSystemProps, HealthCheck, LogProps, S3BucketProps } from '../../services/index.js';
|
|
3
|
+
import { VpcProps } from 'aws-cdk-lib/aws-ec2';
|
|
4
|
+
import { OriginRequestPolicyProps, ResponseHeadersStrictTransportSecurity, ResponseSecurityHeadersBehavior, ResponseHeadersPolicyProps, CachePolicyProps } from 'aws-cdk-lib/aws-cloudfront';
|
|
5
|
+
import { SiteResponseHeaderPolicyType } from './constants.js';
|
|
6
|
+
/**
|
|
7
|
+
*/
|
|
8
|
+
export interface SiteWithEcsBackendProps extends CommonStackProps {
|
|
9
|
+
logLevel: string;
|
|
10
|
+
nodeEnv: string;
|
|
11
|
+
siteCacheInvalidationDockerFilePath?: string;
|
|
12
|
+
siteCertificate: AcmProps;
|
|
13
|
+
siteCloudfrontFunctionProps?: CloudfrontFunctionProps;
|
|
14
|
+
siteCluster: EcsClusterProps;
|
|
15
|
+
siteDistribution: DistributionProps;
|
|
16
|
+
siteEcsContainerImagePath: string;
|
|
17
|
+
siteFileSystem?: EfsFileSystemProps;
|
|
18
|
+
siteFileSystemAccessPoints?: EfsAccessPointOptions[];
|
|
19
|
+
siteFunctionFilePath?: string;
|
|
20
|
+
siteHealthCheck: HealthCheck;
|
|
21
|
+
siteLog: LogProps;
|
|
22
|
+
siteLogBucket: S3BucketProps;
|
|
23
|
+
siteCachePolicy?: SiteCachePolicyProps;
|
|
24
|
+
siteOriginRequestPolicy: OriginRequestPolicyProps;
|
|
25
|
+
siteOriginResponseHeadersPolicy: SiteResponseHeadersPolicyProps;
|
|
26
|
+
siteRecordName?: string;
|
|
27
|
+
siteRegionalCertificate: AcmProps;
|
|
28
|
+
siteSubDomain: string;
|
|
29
|
+
siteTask: EcsApplicationLoadBalancedFargateServiceProps;
|
|
30
|
+
siteVpc: VpcProps;
|
|
31
|
+
timezone: string;
|
|
32
|
+
useExistingHostedZone: boolean;
|
|
33
|
+
useExistingVpc: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface SiteResponseHeadersStrictTransportSecurity extends ResponseHeadersStrictTransportSecurity {
|
|
36
|
+
accessControlMaxAgeInSeconds: number;
|
|
37
|
+
}
|
|
38
|
+
export interface SiteSecurityHeadersBehavior extends ResponseSecurityHeadersBehavior {
|
|
39
|
+
strictTransportSecurity: SiteResponseHeadersStrictTransportSecurity;
|
|
40
|
+
}
|
|
41
|
+
export interface SiteResponseHeadersPolicyProps extends ResponseHeadersPolicyProps {
|
|
42
|
+
securityHeadersBehavior: SiteSecurityHeadersBehavior;
|
|
43
|
+
type: SiteResponseHeaderPolicyType;
|
|
44
|
+
}
|
|
45
|
+
export interface SiteCachePolicyProps extends CachePolicyProps {
|
|
46
|
+
defaultTtlInSeconds: number;
|
|
47
|
+
minTtlInSeconds: number;
|
|
48
|
+
maxTtlInSeconds: number;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export var SiteWithLambdaBackendResponseHeaderPolicyType;
|
|
2
|
+
(function (SiteWithLambdaBackendResponseHeaderPolicyType) {
|
|
3
|
+
SiteWithLambdaBackendResponseHeaderPolicyType["ORIGIN"] = "origin";
|
|
4
|
+
SiteWithLambdaBackendResponseHeaderPolicyType["STATIC"] = "static";
|
|
5
|
+
})(SiteWithLambdaBackendResponseHeaderPolicyType || (SiteWithLambdaBackendResponseHeaderPolicyType = {}));
|
|
6
|
+
export const LAMBDA_ALIAS_NAME_CURRENT = 'latest';
|