@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,116 @@
|
|
|
1
|
+
import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager';
|
|
2
|
+
import { CachePolicy, IFunction as CfIFunction, Distribution, FunctionAssociation, OriginRequestPolicy, ResponseHeadersPolicy } from 'aws-cdk-lib/aws-cloudfront';
|
|
3
|
+
import { HttpOrigin } from 'aws-cdk-lib/aws-cloudfront-origins';
|
|
4
|
+
import { PolicyDocument, Role } from 'aws-cdk-lib/aws-iam';
|
|
5
|
+
import { AssetCode, FunctionUrl, IFunction, ILayerVersion } from 'aws-cdk-lib/aws-lambda';
|
|
6
|
+
import { IHostedZone } from 'aws-cdk-lib/aws-route53';
|
|
7
|
+
import { IBucket } from 'aws-cdk-lib/aws-s3';
|
|
8
|
+
import { BucketDeployment } from 'aws-cdk-lib/aws-s3-deployment';
|
|
9
|
+
import { Construct } from 'constructs';
|
|
10
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
11
|
+
import { SiteWithLambdaBackendCachePolicyProps, SiteWithLambdaBackendProps, SiteWithLambdaBackendResponseHeadersPolicyProps } from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* @classdesc Provides a construct to create and deploy a site hosted with an clustered ECS/ELB backend
|
|
14
|
+
* @example
|
|
15
|
+
* import { SiteWithLambdaBackend, SiteWithLambdaBackendProps } '@gradientedge/cdk-utils'
|
|
16
|
+
* import { Construct } from 'constructs'
|
|
17
|
+
*
|
|
18
|
+
* class CustomConstruct extends SiteWithLambdaBackend {
|
|
19
|
+
* constructor(parent: Construct, id: string, props: SiteWithLambdaBackendProps) {
|
|
20
|
+
* super(parent, id, props)
|
|
21
|
+
* this.props = props
|
|
22
|
+
* this.id = id
|
|
23
|
+
* this.initResources()
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
*/
|
|
27
|
+
export declare class SiteWithLambdaBackend extends CommonConstruct {
|
|
28
|
+
props: SiteWithLambdaBackendProps;
|
|
29
|
+
id: string;
|
|
30
|
+
siteHostedZone: IHostedZone;
|
|
31
|
+
siteCertificate: ICertificate;
|
|
32
|
+
siteRegionalCertificate: ICertificate;
|
|
33
|
+
siteSecrets: any;
|
|
34
|
+
siteLogBucket: IBucket;
|
|
35
|
+
siteOrigin: HttpOrigin;
|
|
36
|
+
siteDistribution: Distribution;
|
|
37
|
+
siteInternalDomainName: string;
|
|
38
|
+
siteExternalDomainName: string;
|
|
39
|
+
siteDomainNames: string[];
|
|
40
|
+
siteCloudfrontFunction: CfIFunction;
|
|
41
|
+
siteFunctionAssociations: FunctionAssociation[];
|
|
42
|
+
siteOriginRequestPolicy: OriginRequestPolicy;
|
|
43
|
+
siteOriginResponseHeadersPolicy?: ResponseHeadersPolicy;
|
|
44
|
+
siteCachePolicy: CachePolicy;
|
|
45
|
+
siteStaticAssetDeployment: BucketDeployment;
|
|
46
|
+
siteLambdaPolicy: PolicyDocument;
|
|
47
|
+
siteLambdaRole: Role;
|
|
48
|
+
siteLambdaEnvironment: any;
|
|
49
|
+
siteLambdaLayers: ILayerVersion[];
|
|
50
|
+
siteLambdaApplication: AssetCode;
|
|
51
|
+
siteLambdaFunction: IFunction;
|
|
52
|
+
siteLambdaUrl: FunctionUrl;
|
|
53
|
+
constructor(parent: Construct, id: string, props: SiteWithLambdaBackendProps);
|
|
54
|
+
/**
|
|
55
|
+
* @summary Initialise and provision resources
|
|
56
|
+
*/
|
|
57
|
+
initResources(): void;
|
|
58
|
+
/**
|
|
59
|
+
* @summary Method to resolve a hosted zone based on domain attributes
|
|
60
|
+
*/
|
|
61
|
+
protected resolveHostedZone(): void;
|
|
62
|
+
/**
|
|
63
|
+
* @summary Method to resolve a certificate based on attributes
|
|
64
|
+
*/
|
|
65
|
+
protected resolveCertificate(): void;
|
|
66
|
+
protected resolveGlobalCertificate(): void;
|
|
67
|
+
protected resolveRegionalCertificate(): void;
|
|
68
|
+
/**
|
|
69
|
+
* @summary Method to resolve secrets from SecretsManager
|
|
70
|
+
* - To be implemented in the overriding method in the implementation class
|
|
71
|
+
*/
|
|
72
|
+
protected resolveSiteSecrets(): void;
|
|
73
|
+
/**
|
|
74
|
+
* @summary Method to resolve site domain names
|
|
75
|
+
*/
|
|
76
|
+
protected resolveSiteDomainNames(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Method to create log bucket for site distribution
|
|
79
|
+
*/
|
|
80
|
+
protected createSiteLogBucket(): void;
|
|
81
|
+
protected createSiteCachePolicy(id: string, siteCachePolicy: SiteWithLambdaBackendCachePolicyProps): CachePolicy;
|
|
82
|
+
protected createSiteOriginCachePolicy(): void;
|
|
83
|
+
protected createSiteOriginRequestPolicy(): void;
|
|
84
|
+
protected createResponseHeaderPolicy(props: SiteWithLambdaBackendResponseHeadersPolicyProps): ResponseHeadersPolicy | undefined;
|
|
85
|
+
protected createSiteOriginResponseHeadersPolicy(): void;
|
|
86
|
+
protected createSiteOrigin(): void;
|
|
87
|
+
protected createSiteOriginResources(): void;
|
|
88
|
+
protected createSiteStaticAssetDeployment(): void;
|
|
89
|
+
protected createSiteLambdaPolicy(): void;
|
|
90
|
+
protected createSiteLambdaRole(): void;
|
|
91
|
+
protected createSiteLambdaEnvironment(): void;
|
|
92
|
+
protected createSiteLambdaLayers(): void;
|
|
93
|
+
protected createSiteLambdaApplication(): void;
|
|
94
|
+
protected createSiteLambda(): void;
|
|
95
|
+
protected createSiteLambdaUrl(): void;
|
|
96
|
+
/**
|
|
97
|
+
* @summary Method to create a site cloudfront function
|
|
98
|
+
*/
|
|
99
|
+
protected createSiteCloudfrontFunction(): void;
|
|
100
|
+
/**
|
|
101
|
+
* @summary Method to create a site cloudfront function associations
|
|
102
|
+
*/
|
|
103
|
+
protected resolveSiteFunctionAssociations(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Method to create Site distribution
|
|
106
|
+
*/
|
|
107
|
+
protected createDistribution(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Method to create Route53 records for distribution
|
|
110
|
+
*/
|
|
111
|
+
protected createNetworkMappings(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
114
|
+
*/
|
|
115
|
+
protected invalidateDistributionCache(): void;
|
|
116
|
+
}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { Duration, Fn } 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 { AnyPrincipal, Effect, PolicyDocument, PolicyStatement } from 'aws-cdk-lib/aws-iam';
|
|
5
|
+
import { Function, FunctionUrlAuthType } from 'aws-cdk-lib/aws-lambda';
|
|
6
|
+
import _ from 'lodash';
|
|
7
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
8
|
+
import { LAMBDA_ALIAS_NAME_CURRENT } from './constants.js';
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Provides a construct to create and deploy a site hosted with an clustered ECS/ELB backend
|
|
11
|
+
* @example
|
|
12
|
+
* import { SiteWithLambdaBackend, SiteWithLambdaBackendProps } '@gradientedge/cdk-utils'
|
|
13
|
+
* import { Construct } from 'constructs'
|
|
14
|
+
*
|
|
15
|
+
* class CustomConstruct extends SiteWithLambdaBackend {
|
|
16
|
+
* constructor(parent: Construct, id: string, props: SiteWithLambdaBackendProps) {
|
|
17
|
+
* super(parent, id, props)
|
|
18
|
+
* this.props = props
|
|
19
|
+
* this.id = id
|
|
20
|
+
* this.initResources()
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export class SiteWithLambdaBackend extends CommonConstruct {
|
|
25
|
+
/* site properties */
|
|
26
|
+
props;
|
|
27
|
+
id;
|
|
28
|
+
/* site resources */
|
|
29
|
+
siteHostedZone;
|
|
30
|
+
siteCertificate;
|
|
31
|
+
siteRegionalCertificate;
|
|
32
|
+
siteSecrets;
|
|
33
|
+
siteLogBucket;
|
|
34
|
+
siteOrigin;
|
|
35
|
+
siteDistribution;
|
|
36
|
+
siteInternalDomainName;
|
|
37
|
+
siteExternalDomainName;
|
|
38
|
+
siteDomainNames;
|
|
39
|
+
siteCloudfrontFunction;
|
|
40
|
+
siteFunctionAssociations;
|
|
41
|
+
siteOriginRequestPolicy;
|
|
42
|
+
siteOriginResponseHeadersPolicy;
|
|
43
|
+
siteCachePolicy;
|
|
44
|
+
siteStaticAssetDeployment;
|
|
45
|
+
siteLambdaPolicy;
|
|
46
|
+
siteLambdaRole;
|
|
47
|
+
siteLambdaEnvironment;
|
|
48
|
+
siteLambdaLayers;
|
|
49
|
+
siteLambdaApplication;
|
|
50
|
+
siteLambdaFunction;
|
|
51
|
+
siteLambdaUrl;
|
|
52
|
+
constructor(parent, id, props) {
|
|
53
|
+
super(parent, id, props);
|
|
54
|
+
this.props = props;
|
|
55
|
+
this.id = id;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @summary Initialise and provision resources
|
|
59
|
+
*/
|
|
60
|
+
initResources() {
|
|
61
|
+
this.resolveHostedZone();
|
|
62
|
+
this.resolveCertificate();
|
|
63
|
+
this.resolveSiteSecrets();
|
|
64
|
+
this.resolveSiteDomainNames();
|
|
65
|
+
this.createSiteLogBucket();
|
|
66
|
+
this.createSiteOriginCachePolicy();
|
|
67
|
+
this.createSiteOriginRequestPolicy();
|
|
68
|
+
this.createSiteOriginResponseHeadersPolicy();
|
|
69
|
+
this.createSiteOrigin();
|
|
70
|
+
this.createSiteCloudfrontFunction();
|
|
71
|
+
this.resolveSiteFunctionAssociations();
|
|
72
|
+
this.createDistribution();
|
|
73
|
+
this.createNetworkMappings();
|
|
74
|
+
this.invalidateDistributionCache();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @summary Method to resolve a hosted zone based on domain attributes
|
|
78
|
+
*/
|
|
79
|
+
resolveHostedZone() {
|
|
80
|
+
this.siteHostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @summary Method to resolve a certificate based on attributes
|
|
84
|
+
*/
|
|
85
|
+
resolveCertificate() {
|
|
86
|
+
this.resolveGlobalCertificate();
|
|
87
|
+
this.resolveRegionalCertificate();
|
|
88
|
+
}
|
|
89
|
+
resolveGlobalCertificate() {
|
|
90
|
+
if (this.props.siteCertificate.useExistingCertificate &&
|
|
91
|
+
this.props.siteCertificate.certificateSsmName &&
|
|
92
|
+
this.props.siteCertificate.certificateRegion) {
|
|
93
|
+
this.props.siteCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-parameter`, this, this.props.siteCertificate.certificateSsmName, this.props.siteCertificate.certificateRegion);
|
|
94
|
+
}
|
|
95
|
+
this.siteCertificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.siteCertificate);
|
|
96
|
+
}
|
|
97
|
+
resolveRegionalCertificate() {
|
|
98
|
+
if (this.props.siteRegionalCertificate.useExistingCertificate &&
|
|
99
|
+
this.props.siteRegionalCertificate.certificateSsmName &&
|
|
100
|
+
this.props.siteRegionalCertificate.certificateRegion) {
|
|
101
|
+
this.props.siteRegionalCertificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-regional-certificate-parameter`, this, this.props.siteRegionalCertificate.certificateSsmName, this.props.siteRegionalCertificate.certificateRegion);
|
|
102
|
+
}
|
|
103
|
+
this.siteRegionalCertificate = this.acmManager.resolveCertificate(`${this.id}-regional-certificate`, this, this.props.siteRegionalCertificate, this.siteHostedZone);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @summary Method to resolve secrets from SecretsManager
|
|
107
|
+
* - To be implemented in the overriding method in the implementation class
|
|
108
|
+
*/
|
|
109
|
+
resolveSiteSecrets() { }
|
|
110
|
+
/**
|
|
111
|
+
* @summary Method to resolve site domain names
|
|
112
|
+
*/
|
|
113
|
+
resolveSiteDomainNames() {
|
|
114
|
+
/* the internal domain name used by ELB */
|
|
115
|
+
this.siteInternalDomainName =
|
|
116
|
+
this.isProductionStage() || this.props.skipStageForARecords
|
|
117
|
+
? `${this.props.siteSubDomain}-internal.${this.fullyQualifiedDomainName}`
|
|
118
|
+
: `${this.props.siteSubDomain}-internal-${this.props.stage}.${this.fullyQualifiedDomainName}`;
|
|
119
|
+
/* the external domain name exposed to CloudFront */
|
|
120
|
+
this.siteExternalDomainName =
|
|
121
|
+
this.isProductionStage() || this.props.skipStageForARecords
|
|
122
|
+
? `${this.props.siteSubDomain}.${this.fullyQualifiedDomainName}`
|
|
123
|
+
: `${this.props.siteSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`;
|
|
124
|
+
this.siteDomainNames = [this.siteExternalDomainName];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Method to create log bucket for site distribution
|
|
128
|
+
*/
|
|
129
|
+
createSiteLogBucket() {
|
|
130
|
+
this.siteLogBucket = this.s3Manager.createS3Bucket(`${this.id}-site-logs`, this, this.props.siteLogBucket);
|
|
131
|
+
}
|
|
132
|
+
createSiteCachePolicy(id, siteCachePolicy) {
|
|
133
|
+
if (!siteCachePolicy.cachePolicyName)
|
|
134
|
+
throw `SiteCachePolicy cachePolicyName undefined for ${id}`;
|
|
135
|
+
return new CachePolicy(this, `${id}`, {
|
|
136
|
+
cachePolicyName: this.resourceNameFormatter.format(siteCachePolicy.cachePolicyName),
|
|
137
|
+
comment: `Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
138
|
+
cookieBehavior: siteCachePolicy.cookieBehavior,
|
|
139
|
+
enableAcceptEncodingBrotli: siteCachePolicy.enableAcceptEncodingBrotli,
|
|
140
|
+
enableAcceptEncodingGzip: siteCachePolicy.enableAcceptEncodingGzip,
|
|
141
|
+
headerBehavior: siteCachePolicy.headerBehavior,
|
|
142
|
+
maxTtl: Duration.seconds(siteCachePolicy.maxTtlInSeconds),
|
|
143
|
+
minTtl: Duration.seconds(siteCachePolicy.minTtlInSeconds),
|
|
144
|
+
queryStringBehavior: siteCachePolicy.queryStringBehavior,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
createSiteOriginCachePolicy() {
|
|
148
|
+
if (!this.props.siteCachePolicy)
|
|
149
|
+
return;
|
|
150
|
+
this.siteCachePolicy = this.createSiteCachePolicy(`${this.id}-site-cache-policy`, this.props.siteCachePolicy);
|
|
151
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
152
|
+
cachePolicy: this.siteCachePolicy,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
createSiteOriginRequestPolicy() {
|
|
156
|
+
if (!this.props.siteOriginRequestPolicy)
|
|
157
|
+
return;
|
|
158
|
+
if (!this.props.siteOriginRequestPolicy.originRequestPolicyName)
|
|
159
|
+
throw `SiteOriginRequestPolicy originRequestPolicyName undefined for ${this.id}`;
|
|
160
|
+
this.siteOriginRequestPolicy = new OriginRequestPolicy(this, `${this.id}-sorp`, {
|
|
161
|
+
comment: `Request Policy for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
162
|
+
cookieBehavior: this.props.siteOriginRequestPolicy.cookieBehavior,
|
|
163
|
+
headerBehavior: this.props.siteOriginRequestPolicy.headerBehavior,
|
|
164
|
+
originRequestPolicyName: this.resourceNameFormatter.format(this.props.siteOriginRequestPolicy.originRequestPolicyName),
|
|
165
|
+
queryStringBehavior: this.props.siteOriginRequestPolicy.queryStringBehavior,
|
|
166
|
+
});
|
|
167
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
168
|
+
originRequestPolicy: this.siteOriginRequestPolicy,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
createResponseHeaderPolicy(props) {
|
|
172
|
+
if (!props)
|
|
173
|
+
return undefined;
|
|
174
|
+
if (!props.responseHeadersPolicyName)
|
|
175
|
+
throw `SiteResponseHeadersPolicy responseHeadersPolicyName undefined for ${this.id}`;
|
|
176
|
+
return new ResponseHeadersPolicy(this, `${this.id}-${props.type}-srhp`, {
|
|
177
|
+
...props,
|
|
178
|
+
comment: `Response Header Policy for ${props.type} for ${this.id}-distribution - ${this.props.stage} stage`,
|
|
179
|
+
responseHeadersPolicyName: this.resourceNameFormatter.format(props.responseHeadersPolicyName),
|
|
180
|
+
securityHeadersBehavior: {
|
|
181
|
+
...props.securityHeadersBehavior,
|
|
182
|
+
strictTransportSecurity: {
|
|
183
|
+
...props.securityHeadersBehavior?.strictTransportSecurity,
|
|
184
|
+
accessControlMaxAge: Duration.seconds(props.securityHeadersBehavior?.strictTransportSecurity?.accessControlMaxAgeInSeconds),
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
createSiteOriginResponseHeadersPolicy() {
|
|
190
|
+
if (!this.props.siteOriginResponseHeadersPolicy)
|
|
191
|
+
return;
|
|
192
|
+
this.siteOriginResponseHeadersPolicy = this.createResponseHeaderPolicy(this.props.siteOriginResponseHeadersPolicy);
|
|
193
|
+
_.assign(this.props.siteDistribution.defaultBehavior, {
|
|
194
|
+
responseHeadersPolicy: this.siteOriginResponseHeadersPolicy,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
createSiteOrigin() {
|
|
198
|
+
this.createSiteOriginResources();
|
|
199
|
+
this.siteOrigin = new HttpOrigin(Fn.select(2, Fn.split('/', this.siteLambdaUrl.url)), {
|
|
200
|
+
httpPort: 443,
|
|
201
|
+
originId: `${this.id}-server`,
|
|
202
|
+
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
createSiteOriginResources() {
|
|
206
|
+
this.createSiteStaticAssetDeployment();
|
|
207
|
+
this.createSiteLambdaPolicy();
|
|
208
|
+
this.createSiteLambdaRole();
|
|
209
|
+
this.createSiteLambdaEnvironment();
|
|
210
|
+
this.createSiteLambdaLayers();
|
|
211
|
+
this.createSiteLambdaApplication();
|
|
212
|
+
this.createSiteLambda();
|
|
213
|
+
this.createSiteLambdaUrl();
|
|
214
|
+
}
|
|
215
|
+
createSiteStaticAssetDeployment() { }
|
|
216
|
+
createSiteLambdaPolicy() {
|
|
217
|
+
this.siteLambdaPolicy = new PolicyDocument({
|
|
218
|
+
statements: [
|
|
219
|
+
new PolicyStatement({
|
|
220
|
+
actions: ['lambda:InvokeFunctionUrl'],
|
|
221
|
+
effect: Effect.ALLOW,
|
|
222
|
+
resources: ['*'],
|
|
223
|
+
}),
|
|
224
|
+
],
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
createSiteLambdaRole() {
|
|
228
|
+
this.siteLambdaRole = this.iamManager.createRoleForLambda(`${this.id}-role`, this, this.siteLambdaPolicy);
|
|
229
|
+
}
|
|
230
|
+
createSiteLambdaEnvironment() {
|
|
231
|
+
this.siteLambdaEnvironment = {
|
|
232
|
+
AWS_LAMBDA_EXEC_WRAPPER: this.props.siteExecWrapperPath ?? '/opt/bootstrap',
|
|
233
|
+
LOG_LEVEL: this.props.logLevel,
|
|
234
|
+
NODE_ENV: this.props.nodeEnv,
|
|
235
|
+
PORT: this.props.sitePort,
|
|
236
|
+
READINESS_CHECK_PATH: this.props.siteHealthEndpoint,
|
|
237
|
+
READINESS_CHECK_PORT: this.props.sitePort,
|
|
238
|
+
STAGE: this.props.stage,
|
|
239
|
+
TZ: this.props.timezone,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
createSiteLambdaLayers() {
|
|
243
|
+
this.siteLambdaLayers = this.lambdaManager.createWebAdapterLayer(`${this.id}-web-adapter`, this);
|
|
244
|
+
}
|
|
245
|
+
createSiteLambdaApplication() { }
|
|
246
|
+
createSiteLambda() {
|
|
247
|
+
this.siteLambdaFunction = this.lambdaManager.createLambdaFunction(`${this.id}-lambda`, this, this.props.siteLambda, this.siteLambdaRole, this.siteLambdaLayers, this.siteLambdaApplication, this.props.siteLambda.handler, this.siteLambdaEnvironment);
|
|
248
|
+
}
|
|
249
|
+
createSiteLambdaUrl() {
|
|
250
|
+
const lambdaAlias = _.find(this.props.siteLambda.lambdaAliases, alias => alias.aliasName === LAMBDA_ALIAS_NAME_CURRENT);
|
|
251
|
+
const lambdaFn = lambdaAlias
|
|
252
|
+
? Function.fromFunctionAttributes(this, `${this.id}-fn-alias`, {
|
|
253
|
+
functionArn: `${this.siteLambdaFunction.functionArn}:${lambdaAlias.aliasName}`,
|
|
254
|
+
sameEnvironment: true,
|
|
255
|
+
})
|
|
256
|
+
: this.siteLambdaFunction;
|
|
257
|
+
lambdaFn.node.addDependency(this.siteLambdaFunction);
|
|
258
|
+
this.siteLambdaUrl = lambdaFn.addFunctionUrl({
|
|
259
|
+
authType: FunctionUrlAuthType.NONE,
|
|
260
|
+
});
|
|
261
|
+
this.siteLambdaUrl.node.addDependency(this.siteLambdaFunction);
|
|
262
|
+
this.siteLambdaUrl.node.addDependency(lambdaFn);
|
|
263
|
+
const principal = new AnyPrincipal();
|
|
264
|
+
principal.addToPolicy(new PolicyStatement({
|
|
265
|
+
actions: ['lambda:InvokeFunctionUrl'],
|
|
266
|
+
conditions: { StringEquals: { 'lambda:FunctionUrlAuthType': FunctionUrlAuthType.NONE } },
|
|
267
|
+
effect: Effect.ALLOW,
|
|
268
|
+
resources: ['*'],
|
|
269
|
+
}));
|
|
270
|
+
lambdaFn.grantInvokeUrl({ grantPrincipal: principal });
|
|
271
|
+
this.addCfnOutput(`${this.id}-url`, this.siteLambdaUrl.url);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* @summary Method to create a site cloudfront function
|
|
275
|
+
*/
|
|
276
|
+
createSiteCloudfrontFunction() {
|
|
277
|
+
if (this.props.siteCloudfrontFunctionProps) {
|
|
278
|
+
this.siteCloudfrontFunction = this.cloudFrontManager.createCloudfrontFunction(`${this.id}-function`, this, this.props.siteCloudfrontFunctionProps);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* @summary Method to create a site cloudfront function associations
|
|
283
|
+
*/
|
|
284
|
+
resolveSiteFunctionAssociations() {
|
|
285
|
+
if (this.props.siteCloudfrontFunctionProps) {
|
|
286
|
+
this.siteFunctionAssociations = [
|
|
287
|
+
{
|
|
288
|
+
eventType: FunctionEventType.VIEWER_REQUEST,
|
|
289
|
+
function: this.siteCloudfrontFunction,
|
|
290
|
+
},
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Method to create Site distribution
|
|
296
|
+
*/
|
|
297
|
+
createDistribution() {
|
|
298
|
+
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);
|
|
299
|
+
this.siteDistribution.node.addDependency(this.siteLambdaFunction);
|
|
300
|
+
this.siteDistribution.node.addDependency(this.siteLambdaUrl);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Method to create Route53 records for distribution
|
|
304
|
+
*/
|
|
305
|
+
createNetworkMappings() {
|
|
306
|
+
this.route53Manager.createCloudFrontTargetARecord(`${this.id}-a-record`, this, this.siteDistribution, this.siteHostedZone, this.props.siteRecordName, this.props.skipStageForARecords);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Method to invalidation the cloudfront distribution cache after a deployment
|
|
310
|
+
*/
|
|
311
|
+
invalidateDistributionCache() {
|
|
312
|
+
if (this.props.siteCacheInvalidationDockerFilePath) {
|
|
313
|
+
this.cloudFrontManager.invalidateCache(`${this.id}-cache-invalidation`, this, this.props.siteCacheInvalidationDockerFilePath, this.siteDistribution.distributionId);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CachePolicyProps, OriginRequestPolicyProps, ResponseHeadersPolicyProps, ResponseHeadersStrictTransportSecurity, ResponseSecurityHeadersBehavior } from 'aws-cdk-lib/aws-cloudfront';
|
|
2
|
+
import { CommonStackProps } from '../../common/index.js';
|
|
3
|
+
import { AcmProps, CloudfrontFunctionProps, DistributionProps, LambdaProps, LogProps, S3BucketProps } from '../../services/index.js';
|
|
4
|
+
import { SiteWithLambdaBackendResponseHeaderPolicyType } from './constants.js';
|
|
5
|
+
/**
|
|
6
|
+
*/
|
|
7
|
+
export interface SiteWithLambdaBackendProps extends CommonStackProps {
|
|
8
|
+
logLevel: string;
|
|
9
|
+
nodeEnv: string;
|
|
10
|
+
siteCacheInvalidationDockerFilePath?: string;
|
|
11
|
+
siteCertificate: AcmProps;
|
|
12
|
+
siteCloudfrontFunctionProps?: CloudfrontFunctionProps;
|
|
13
|
+
siteDistribution: DistributionProps;
|
|
14
|
+
siteExecWrapperPath: string;
|
|
15
|
+
siteFunctionFilePath?: string;
|
|
16
|
+
siteHealthEndpoint: string;
|
|
17
|
+
siteLambda: LambdaProps;
|
|
18
|
+
siteLog: LogProps;
|
|
19
|
+
siteLogBucket: S3BucketProps;
|
|
20
|
+
sitePort: string;
|
|
21
|
+
siteCachePolicy?: SiteWithLambdaBackendCachePolicyProps;
|
|
22
|
+
siteOriginRequestPolicy: OriginRequestPolicyProps;
|
|
23
|
+
siteOriginResponseHeadersPolicy: SiteWithLambdaBackendResponseHeadersPolicyProps;
|
|
24
|
+
siteRecordName?: string;
|
|
25
|
+
siteRegionalCertificate: AcmProps;
|
|
26
|
+
siteSubDomain: string;
|
|
27
|
+
timezone: string;
|
|
28
|
+
useExistingHostedZone: boolean;
|
|
29
|
+
useExistingVpc: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface SiteWithLambdaBackendResponseHeadersStrictTransportSecurity extends ResponseHeadersStrictTransportSecurity {
|
|
32
|
+
accessControlMaxAgeInSeconds: number;
|
|
33
|
+
}
|
|
34
|
+
export interface SiteWithLambdaBackendSecurityHeadersBehavior extends ResponseSecurityHeadersBehavior {
|
|
35
|
+
strictTransportSecurity: SiteWithLambdaBackendResponseHeadersStrictTransportSecurity;
|
|
36
|
+
}
|
|
37
|
+
export interface SiteWithLambdaBackendResponseHeadersPolicyProps extends ResponseHeadersPolicyProps {
|
|
38
|
+
securityHeadersBehavior: SiteWithLambdaBackendSecurityHeadersBehavior;
|
|
39
|
+
type: SiteWithLambdaBackendResponseHeaderPolicyType;
|
|
40
|
+
}
|
|
41
|
+
export interface SiteWithLambdaBackendCachePolicyProps extends CachePolicyProps {
|
|
42
|
+
defaultTtlInSeconds: number;
|
|
43
|
+
minTtlInSeconds: number;
|
|
44
|
+
maxTtlInSeconds: number;
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IBucket } from 'aws-cdk-lib/aws-s3';
|
|
2
|
+
import { IDistribution } from 'aws-cdk-lib/aws-cloudfront';
|
|
3
|
+
import { Construct } from 'constructs';
|
|
4
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
5
|
+
import { StaticAssetDeploymentProps } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc Provides a construct to create and deploy static assets into S3 bucket
|
|
8
|
+
* @example
|
|
9
|
+
* import { StaticAssetDeployment, StaticAssetDeploymentProps } '@gradientedge/cdk-utils'
|
|
10
|
+
* import { Construct } from 'constructs'
|
|
11
|
+
*
|
|
12
|
+
* class CustomConstruct extends StaticAssetDeployment {
|
|
13
|
+
* constructor(parent: Construct, id: string, props: StaticAssetDeploymentProps) {
|
|
14
|
+
* super(parent, id, props)
|
|
15
|
+
* this.initResources()
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export declare class StaticAssetDeployment extends CommonConstruct {
|
|
20
|
+
staticAssetBucket: IBucket;
|
|
21
|
+
cloudfrontDistribution?: IDistribution;
|
|
22
|
+
props: StaticAssetDeploymentProps;
|
|
23
|
+
id: string;
|
|
24
|
+
constructor(parent: Construct, id: string, props: StaticAssetDeploymentProps);
|
|
25
|
+
/**
|
|
26
|
+
* @summary Initialise and provision resources
|
|
27
|
+
*/
|
|
28
|
+
initResources(): void;
|
|
29
|
+
/**
|
|
30
|
+
* @summary Create the static asset bucket
|
|
31
|
+
*/
|
|
32
|
+
protected createAssetBucket(): void;
|
|
33
|
+
/**
|
|
34
|
+
* @summary Distribute the load for the static asset bucket if both distribution and paths are provided
|
|
35
|
+
*/
|
|
36
|
+
protected resolveDistribution(): void;
|
|
37
|
+
/**
|
|
38
|
+
* @summary Deploy the static assets into the static asset bucket
|
|
39
|
+
*/
|
|
40
|
+
protected deployStaticAssets(): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Fn } from 'aws-cdk-lib';
|
|
2
|
+
import { BucketDeployment, Source } from 'aws-cdk-lib/aws-s3-deployment';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import { CommonConstruct } from '../../common/index.js';
|
|
5
|
+
import appRoot from 'app-root-path';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
/**
|
|
8
|
+
* @classdesc Provides a construct to create and deploy static assets into S3 bucket
|
|
9
|
+
* @example
|
|
10
|
+
* import { StaticAssetDeployment, StaticAssetDeploymentProps } '@gradientedge/cdk-utils'
|
|
11
|
+
* import { Construct } from 'constructs'
|
|
12
|
+
*
|
|
13
|
+
* class CustomConstruct extends StaticAssetDeployment {
|
|
14
|
+
* constructor(parent: Construct, id: string, props: StaticAssetDeploymentProps) {
|
|
15
|
+
* super(parent, id, props)
|
|
16
|
+
* this.initResources()
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
export class StaticAssetDeployment extends CommonConstruct {
|
|
21
|
+
/* construct resources */
|
|
22
|
+
staticAssetBucket;
|
|
23
|
+
cloudfrontDistribution;
|
|
24
|
+
props;
|
|
25
|
+
id;
|
|
26
|
+
constructor(parent, id, props) {
|
|
27
|
+
super(parent, id, props);
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.props = props;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @summary Initialise and provision resources
|
|
33
|
+
*/
|
|
34
|
+
initResources() {
|
|
35
|
+
this.createAssetBucket();
|
|
36
|
+
this.resolveDistribution();
|
|
37
|
+
this.deployStaticAssets();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @summary Create the static asset bucket
|
|
41
|
+
*/
|
|
42
|
+
createAssetBucket() {
|
|
43
|
+
this.staticAssetBucket = this.s3Manager.createS3Bucket(`${this.id}-sa-bucket`, this, this.props.staticAssetBucket);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @summary Distribute the load for the static asset bucket if both distribution and paths are provided
|
|
47
|
+
*/
|
|
48
|
+
resolveDistribution() {
|
|
49
|
+
if (this.props.cloudFrontDistribution &&
|
|
50
|
+
(this.props.cloudFrontDistribution.domainName || this.props.cloudFrontDistribution.domainNameRef) &&
|
|
51
|
+
(this.props.cloudFrontDistribution.distributionId || this.props.cloudFrontDistribution.distributionIdRef) &&
|
|
52
|
+
this.props.cloudFrontDistribution.invalidationPaths &&
|
|
53
|
+
this.props.cloudFrontDistribution.invalidationPaths.length > 0) {
|
|
54
|
+
let domainName = this.props.cloudFrontDistribution.domainName;
|
|
55
|
+
if (this.props.cloudFrontDistribution.domainNameRef) {
|
|
56
|
+
domainName = Fn.importValue(this.props.cloudFrontDistribution.domainNameRef);
|
|
57
|
+
}
|
|
58
|
+
let distributionId = this.props.cloudFrontDistribution.distributionId;
|
|
59
|
+
if (this.props.cloudFrontDistribution.distributionIdRef) {
|
|
60
|
+
distributionId = Fn.importValue(this.props.cloudFrontDistribution.distributionIdRef);
|
|
61
|
+
}
|
|
62
|
+
const distributionAttributes = {
|
|
63
|
+
domainName: domainName,
|
|
64
|
+
distributionId: distributionId,
|
|
65
|
+
};
|
|
66
|
+
this.cloudfrontDistribution = this.cloudFrontManager.resolveDistribution(this, distributionAttributes);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @summary Deploy the static assets into the static asset bucket
|
|
71
|
+
*/
|
|
72
|
+
deployStaticAssets() {
|
|
73
|
+
let sources = [];
|
|
74
|
+
if (Array.isArray(this.props.staticAssetSources) &&
|
|
75
|
+
this.props.staticAssetSources.length > 0 &&
|
|
76
|
+
typeof this.props.staticAssetSources[0] === 'string') {
|
|
77
|
+
sources = this.props.staticAssetSources.map(source => {
|
|
78
|
+
const resolvedPath = path.join(appRoot.path, source);
|
|
79
|
+
return Source.asset(resolvedPath);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
sources = this.props.staticAssetSources;
|
|
84
|
+
}
|
|
85
|
+
let distributionOptions = {};
|
|
86
|
+
if (this.cloudfrontDistribution) {
|
|
87
|
+
distributionOptions = {
|
|
88
|
+
distribution: this.cloudfrontDistribution,
|
|
89
|
+
distributionPaths: this.props.cloudFrontDistribution?.invalidationPaths,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
let destinationKeyPrefixOptions = {};
|
|
93
|
+
if (this.props.destinationKeyPrefix) {
|
|
94
|
+
destinationKeyPrefixOptions = {
|
|
95
|
+
destinationKeyPrefix: this.props.destinationKeyPrefix,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
new BucketDeployment(this, `${this.id}-static-deployment`, {
|
|
99
|
+
...this.props.staticAssetDeployment,
|
|
100
|
+
destinationBucket: this.staticAssetBucket,
|
|
101
|
+
sources: sources,
|
|
102
|
+
...destinationKeyPrefixOptions,
|
|
103
|
+
...distributionOptions,
|
|
104
|
+
});
|
|
105
|
+
const staticAssetsForExport = this.props.staticAssetsForExport;
|
|
106
|
+
if (!staticAssetsForExport)
|
|
107
|
+
return;
|
|
108
|
+
/* optional additional exports needed for asset urls */
|
|
109
|
+
_.forEach(staticAssetsForExport, asset => {
|
|
110
|
+
this.addCfnOutput(asset.key, this.staticAssetBucket.s3UrlForObject(asset.value));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|