cdk-simplewebsite-deploy 2.1.9 → 2.2.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/.jsii +5145 -261
- package/.tool-versions +3 -0
- package/API.md +77 -3
- package/README.md +118 -49
- package/lib/cdk-simplewebsite-deploy.d.ts +13 -0
- package/lib/cdk-simplewebsite-deploy.js +10 -4
- package/package.json +17 -10
package/.tool-versions
CHANGED
package/API.md
CHANGED
|
@@ -43,10 +43,11 @@ new CreateBasicSite(scope: Construct, id: string, props: BasicSiteConfiguration)
|
|
|
43
43
|
| **Name** | **Description** |
|
|
44
44
|
| --- | --- |
|
|
45
45
|
| <code><a href="#cdk-simplewebsite-deploy.CreateBasicSite.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
46
|
+
| <code><a href="#cdk-simplewebsite-deploy.CreateBasicSite.with">with</a></code> | Applies one or more mixins to this construct. |
|
|
46
47
|
|
|
47
48
|
---
|
|
48
49
|
|
|
49
|
-
#####
|
|
50
|
+
##### ~~`toString`~~ <a name="toString" id="cdk-simplewebsite-deploy.CreateBasicSite.toString"></a>
|
|
50
51
|
|
|
51
52
|
```typescript
|
|
52
53
|
public toString(): string
|
|
@@ -54,6 +55,27 @@ public toString(): string
|
|
|
54
55
|
|
|
55
56
|
Returns a string representation of this construct.
|
|
56
57
|
|
|
58
|
+
##### ~~`with`~~ <a name="with" id="cdk-simplewebsite-deploy.CreateBasicSite.with"></a>
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
public with(mixins: ...IMixin[]): IConstruct
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Applies one or more mixins to this construct.
|
|
65
|
+
|
|
66
|
+
Mixins are applied in order. The list of constructs is captured at the
|
|
67
|
+
start of the call, so constructs added by a mixin will not be visited.
|
|
68
|
+
Use multiple `with()` calls if subsequent mixins should apply to added
|
|
69
|
+
constructs.
|
|
70
|
+
|
|
71
|
+
###### `mixins`<sup>Required</sup> <a name="mixins" id="cdk-simplewebsite-deploy.CreateBasicSite.with.parameter.mixins"></a>
|
|
72
|
+
|
|
73
|
+
- *Type:* ...constructs.IMixin[]
|
|
74
|
+
|
|
75
|
+
The mixins to apply.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
57
79
|
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
58
80
|
|
|
59
81
|
| **Name** | **Description** |
|
|
@@ -62,7 +84,7 @@ Returns a string representation of this construct.
|
|
|
62
84
|
|
|
63
85
|
---
|
|
64
86
|
|
|
65
|
-
#####
|
|
87
|
+
##### ~~`isConstruct`~~ <a name="isConstruct" id="cdk-simplewebsite-deploy.CreateBasicSite.isConstruct"></a>
|
|
66
88
|
|
|
67
89
|
```typescript
|
|
68
90
|
import { CreateBasicSite } from 'cdk-simplewebsite-deploy'
|
|
@@ -102,7 +124,9 @@ Any object.
|
|
|
102
124
|
|
|
103
125
|
---
|
|
104
126
|
|
|
105
|
-
#####
|
|
127
|
+
##### ~~`node`~~<sup>Required</sup> <a name="node" id="cdk-simplewebsite-deploy.CreateBasicSite.property.node"></a>
|
|
128
|
+
|
|
129
|
+
- *Deprecated:* Use CreateCloudfrontSite instead. CreateBasicSite configures a public S3 website endpoint.
|
|
106
130
|
|
|
107
131
|
```typescript
|
|
108
132
|
public readonly node: Node;
|
|
@@ -156,6 +180,7 @@ new CreateCloudfrontSite(scope: Construct, id: string, props: CloudfrontSiteConf
|
|
|
156
180
|
| **Name** | **Description** |
|
|
157
181
|
| --- | --- |
|
|
158
182
|
| <code><a href="#cdk-simplewebsite-deploy.CreateCloudfrontSite.toString">toString</a></code> | Returns a string representation of this construct. |
|
|
183
|
+
| <code><a href="#cdk-simplewebsite-deploy.CreateCloudfrontSite.with">with</a></code> | Applies one or more mixins to this construct. |
|
|
159
184
|
|
|
160
185
|
---
|
|
161
186
|
|
|
@@ -167,6 +192,27 @@ public toString(): string
|
|
|
167
192
|
|
|
168
193
|
Returns a string representation of this construct.
|
|
169
194
|
|
|
195
|
+
##### `with` <a name="with" id="cdk-simplewebsite-deploy.CreateCloudfrontSite.with"></a>
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
public with(mixins: ...IMixin[]): IConstruct
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Applies one or more mixins to this construct.
|
|
202
|
+
|
|
203
|
+
Mixins are applied in order. The list of constructs is captured at the
|
|
204
|
+
start of the call, so constructs added by a mixin will not be visited.
|
|
205
|
+
Use multiple `with()` calls if subsequent mixins should apply to added
|
|
206
|
+
constructs.
|
|
207
|
+
|
|
208
|
+
###### `mixins`<sup>Required</sup> <a name="mixins" id="cdk-simplewebsite-deploy.CreateCloudfrontSite.with.parameter.mixins"></a>
|
|
209
|
+
|
|
210
|
+
- *Type:* ...constructs.IMixin[]
|
|
211
|
+
|
|
212
|
+
The mixins to apply.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
170
216
|
#### Static Functions <a name="Static Functions" id="Static Functions"></a>
|
|
171
217
|
|
|
172
218
|
| **Name** | **Description** |
|
|
@@ -324,7 +370,9 @@ const cloudfrontSiteConfiguration: CloudfrontSiteConfiguration = { ... }
|
|
|
324
370
|
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.enableLogging">enableLogging</a></code> | <code>boolean</code> | Enable CloudFront access logging. |
|
|
325
371
|
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.enableSecurityHeaders">enableSecurityHeaders</a></code> | <code>boolean</code> | Enable response headers policy for security headers. |
|
|
326
372
|
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.errorDoc">errorDoc</a></code> | <code>string</code> | The error document of the website. |
|
|
373
|
+
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.functionAssociations">functionAssociations</a></code> | <code>aws-cdk-lib.aws_cloudfront.FunctionAssociation[]</code> | CloudFront Functions to associate with the default behavior. |
|
|
327
374
|
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.logsBucket">logsBucket</a></code> | <code>aws-cdk-lib.aws_s3.IBucket</code> | S3 bucket for CloudFront access logs. |
|
|
375
|
+
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.originAccessLevels">originAccessLevels</a></code> | <code>aws-cdk-lib.aws_cloudfront.AccessLevel[]</code> | Additional permissions granted to the CloudFront Origin Access Control for the website bucket. |
|
|
328
376
|
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.priceClass">priceClass</a></code> | <code>aws-cdk-lib.aws_cloudfront.PriceClass</code> | The price class determines how many edge locations CloudFront will use for your distribution. |
|
|
329
377
|
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.subDomain">subDomain</a></code> | <code>string</code> | The subdomain name you want to deploy. |
|
|
330
378
|
| <code><a href="#cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.webAclId">webAclId</a></code> | <code>string</code> | Optional WAF Web ACL ARN for enhanced security. |
|
|
@@ -462,6 +510,19 @@ The error document of the website.
|
|
|
462
510
|
|
|
463
511
|
---
|
|
464
512
|
|
|
513
|
+
##### `functionAssociations`<sup>Optional</sup> <a name="functionAssociations" id="cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.functionAssociations"></a>
|
|
514
|
+
|
|
515
|
+
```typescript
|
|
516
|
+
public readonly functionAssociations: FunctionAssociation[];
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
- *Type:* aws-cdk-lib.aws_cloudfront.FunctionAssociation[]
|
|
520
|
+
- *Default:* No CloudFront Function associations.
|
|
521
|
+
|
|
522
|
+
CloudFront Functions to associate with the default behavior.
|
|
523
|
+
|
|
524
|
+
---
|
|
525
|
+
|
|
465
526
|
##### `logsBucket`<sup>Optional</sup> <a name="logsBucket" id="cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.logsBucket"></a>
|
|
466
527
|
|
|
467
528
|
```typescript
|
|
@@ -477,6 +538,19 @@ If not provided and logging is enabled, a new bucket will be created.
|
|
|
477
538
|
|
|
478
539
|
---
|
|
479
540
|
|
|
541
|
+
##### `originAccessLevels`<sup>Optional</sup> <a name="originAccessLevels" id="cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.originAccessLevels"></a>
|
|
542
|
+
|
|
543
|
+
```typescript
|
|
544
|
+
public readonly originAccessLevels: AccessLevel[];
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
- *Type:* aws-cdk-lib.aws_cloudfront.AccessLevel[]
|
|
548
|
+
- *Default:* [cloudfront.AccessLevel.READ]
|
|
549
|
+
|
|
550
|
+
Additional permissions granted to the CloudFront Origin Access Control for the website bucket.
|
|
551
|
+
|
|
552
|
+
---
|
|
553
|
+
|
|
480
554
|
##### `priceClass`<sup>Optional</sup> <a name="priceClass" id="cdk-simplewebsite-deploy.CloudfrontSiteConfiguration.property.priceClass"></a>
|
|
481
555
|
|
|
482
556
|
```typescript
|
package/README.md
CHANGED
|
@@ -3,29 +3,30 @@
|
|
|
3
3
|

|
|
4
4
|
|
|
5
5
|
# cdk-simplewebsite-deploy
|
|
6
|
-
This is an AWS CDK
|
|
6
|
+
This is an AWS CDK v2 construct library for deploying a single-page website with S3, CloudFront, Route 53, and ACM. `CreateCloudfrontSite` is the recommended construct because it uses a private S3 origin with CloudFront Origin Access Control (OAC), while `CreateBasicSite` is deprecated because it creates a public S3 website endpoint.
|
|
7
7
|
|
|
8
8
|
## Installation and Usage
|
|
9
9
|
|
|
10
|
-
### [
|
|
11
|
-
#### Creates a
|
|
10
|
+
### [CreateCloudfrontSite](https://github.com/snappetal/cdk-simplewebsite-deploy/blob/main/API.md#cdk-cloudfront-deploy-createcloudfrontsite)
|
|
11
|
+
#### Creates a website using a private S3 bucket, a CloudFront distribution, and DNS records in Route 53.
|
|
12
12
|
##### Typescript
|
|
13
13
|
```console
|
|
14
14
|
yarn add cdk-simplewebsite-deploy
|
|
15
15
|
```
|
|
16
16
|
```typescript
|
|
17
17
|
import * as cdk from 'aws-cdk-lib';
|
|
18
|
-
import {
|
|
18
|
+
import { CreateCloudfrontSite } from 'cdk-simplewebsite-deploy';
|
|
19
19
|
import { Construct } from 'constructs';
|
|
20
20
|
|
|
21
21
|
export class PipelineStack extends cdk.Stack {
|
|
22
22
|
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
|
23
23
|
super(scope, id, props);
|
|
24
24
|
|
|
25
|
-
new
|
|
26
|
-
websiteFolder: './src/
|
|
25
|
+
new CreateCloudfrontSite(this, 'test-website', {
|
|
26
|
+
websiteFolder: './src/dist',
|
|
27
27
|
indexDoc: 'index.html',
|
|
28
28
|
hostedZone: 'example.com',
|
|
29
|
+
subDomain: 'www.example.com',
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -36,6 +37,7 @@ dotnet add package ThonBecker.CDK.SimpleWebsiteDeploy
|
|
|
36
37
|
```
|
|
37
38
|
```cs
|
|
38
39
|
using Amazon.CDK;
|
|
40
|
+
using Constructs;
|
|
39
41
|
using ThonBecker.CDK.SimpleWebsiteDeploy;
|
|
40
42
|
|
|
41
43
|
namespace SimpleWebsiteDeploy
|
|
@@ -44,11 +46,12 @@ namespace SimpleWebsiteDeploy
|
|
|
44
46
|
{
|
|
45
47
|
internal PipelineStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
|
|
46
48
|
{
|
|
47
|
-
new
|
|
49
|
+
new CreateCloudfrontSite(scope, "test-website", new CloudfrontSiteConfiguration()
|
|
48
50
|
{
|
|
49
51
|
WebsiteFolder = "./src/build",
|
|
50
52
|
IndexDoc = "index.html",
|
|
51
53
|
HostedZone = "example.com",
|
|
54
|
+
SubDomain = "www.example.com",
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -65,10 +68,10 @@ namespace SimpleWebsiteDeploy
|
|
|
65
68
|
```java
|
|
66
69
|
package com.myorg;
|
|
67
70
|
|
|
68
|
-
import
|
|
69
|
-
import software.amazon.awscdk.
|
|
70
|
-
import software.amazon.awscdk.
|
|
71
|
-
import
|
|
71
|
+
import com.thonbecker.simplewebsitedeploy.CreateCloudfrontSite;
|
|
72
|
+
import software.amazon.awscdk.Stack;
|
|
73
|
+
import software.amazon.awscdk.StackProps;
|
|
74
|
+
import software.constructs.Construct;
|
|
72
75
|
|
|
73
76
|
public class MyProjectStack extends Stack {
|
|
74
77
|
public MyProjectStack(final Construct scope, final String id) {
|
|
@@ -77,11 +80,13 @@ public class MyProjectStack extends Stack {
|
|
|
77
80
|
|
|
78
81
|
public MyProjectStack(final Construct scope, final String id, final StackProps props) {
|
|
79
82
|
super(scope, id, props);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
|
|
84
|
+
CreateCloudfrontSite.Builder.create(this, "test-website")
|
|
85
|
+
.websiteFolder("./src/build")
|
|
86
|
+
.indexDoc("index.html")
|
|
87
|
+
.hostedZone("example.com")
|
|
88
|
+
.subDomain("www.example.com")
|
|
89
|
+
.build();
|
|
85
90
|
}
|
|
86
91
|
}
|
|
87
92
|
```
|
|
@@ -91,38 +96,41 @@ pip install cdk-simplewebsite-deploy
|
|
|
91
96
|
```
|
|
92
97
|
```python
|
|
93
98
|
from aws_cdk import Stack
|
|
94
|
-
from cdk_simplewebsite_deploy import
|
|
99
|
+
from cdk_simplewebsite_deploy import CreateCloudfrontSite
|
|
95
100
|
from constructs import Construct
|
|
96
101
|
|
|
102
|
+
|
|
97
103
|
class MyProjectStack(Stack):
|
|
98
104
|
|
|
99
105
|
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
100
106
|
super().__init__(scope, construct_id, **kwargs)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
|
|
108
|
+
CreateCloudfrontSite(self, 'test-website', website_folder='./src/build',
|
|
109
|
+
index_doc='index.html',
|
|
110
|
+
hosted_zone='example.com',
|
|
111
|
+
sub_domain='www.example.com')
|
|
105
112
|
```
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
|
|
114
|
+
### [CreateBasicSite](https://github.com/snappetal/cdk-simplewebsite-deploy/blob/main/API.md#cdk-cloudfront-deploy-createbasicsite)
|
|
115
|
+
#### Deprecated. Creates a website using public S3 website endpoints with a domain hosted in Route 53.
|
|
116
|
+
Use `CreateCloudfrontSite` for new sites. `CreateBasicSite` configures public bucket access so Route 53 can alias directly to the S3 website endpoint.
|
|
108
117
|
##### Typescript
|
|
109
118
|
```console
|
|
110
119
|
yarn add cdk-simplewebsite-deploy
|
|
111
120
|
```
|
|
112
121
|
```typescript
|
|
113
122
|
import * as cdk from 'aws-cdk-lib';
|
|
114
|
-
import {
|
|
123
|
+
import { CreateBasicSite } from 'cdk-simplewebsite-deploy';
|
|
115
124
|
import { Construct } from 'constructs';
|
|
116
125
|
|
|
117
126
|
export class PipelineStack extends cdk.Stack {
|
|
118
127
|
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
|
119
128
|
super(scope, id, props);
|
|
120
129
|
|
|
121
|
-
new
|
|
122
|
-
websiteFolder: './src/
|
|
130
|
+
new CreateBasicSite(this, 'test-website', {
|
|
131
|
+
websiteFolder: './src/build',
|
|
123
132
|
indexDoc: 'index.html',
|
|
124
133
|
hostedZone: 'example.com',
|
|
125
|
-
subDomain: 'www.example.com',
|
|
126
134
|
});
|
|
127
135
|
}
|
|
128
136
|
}
|
|
@@ -133,6 +141,7 @@ dotnet add package ThonBecker.CDK.SimpleWebsiteDeploy
|
|
|
133
141
|
```
|
|
134
142
|
```cs
|
|
135
143
|
using Amazon.CDK;
|
|
144
|
+
using Constructs;
|
|
136
145
|
using ThonBecker.CDK.SimpleWebsiteDeploy;
|
|
137
146
|
|
|
138
147
|
namespace SimpleWebsiteDeploy
|
|
@@ -141,12 +150,11 @@ namespace SimpleWebsiteDeploy
|
|
|
141
150
|
{
|
|
142
151
|
internal PipelineStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
|
|
143
152
|
{
|
|
144
|
-
new
|
|
153
|
+
new CreateBasicSite(scope, "test-website", new BasicSiteConfiguration()
|
|
145
154
|
{
|
|
146
155
|
WebsiteFolder = "./src/build",
|
|
147
156
|
IndexDoc = "index.html",
|
|
148
157
|
HostedZone = "example.com",
|
|
149
|
-
SubDomain = "www.example.com",
|
|
150
158
|
});
|
|
151
159
|
}
|
|
152
160
|
}
|
|
@@ -163,10 +171,10 @@ namespace SimpleWebsiteDeploy
|
|
|
163
171
|
```java
|
|
164
172
|
package com.myorg;
|
|
165
173
|
|
|
166
|
-
import
|
|
167
|
-
import software.amazon.awscdk.
|
|
168
|
-
import software.amazon.awscdk.
|
|
169
|
-
import
|
|
174
|
+
import com.thonbecker.simplewebsitedeploy.CreateBasicSite;
|
|
175
|
+
import software.amazon.awscdk.Stack;
|
|
176
|
+
import software.amazon.awscdk.StackProps;
|
|
177
|
+
import software.constructs.Construct;
|
|
170
178
|
|
|
171
179
|
public class MyProjectStack extends Stack {
|
|
172
180
|
public MyProjectStack(final Construct scope, final String id) {
|
|
@@ -175,12 +183,12 @@ public class MyProjectStack extends Stack {
|
|
|
175
183
|
|
|
176
184
|
public MyProjectStack(final Construct scope, final String id, final StackProps props) {
|
|
177
185
|
super(scope, id, props);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
|
|
187
|
+
CreateBasicSite.Builder.create(this, "test-website")
|
|
188
|
+
.websiteFolder("./src/build")
|
|
189
|
+
.indexDoc("index.html")
|
|
190
|
+
.hostedZone("example.com")
|
|
191
|
+
.build();
|
|
184
192
|
}
|
|
185
193
|
}
|
|
186
194
|
```
|
|
@@ -189,24 +197,23 @@ public class MyProjectStack extends Stack {
|
|
|
189
197
|
pip install cdk-simplewebsite-deploy
|
|
190
198
|
```
|
|
191
199
|
```python
|
|
192
|
-
from aws_cdk import
|
|
193
|
-
from cdk_simplewebsite_deploy import
|
|
194
|
-
|
|
200
|
+
from aws_cdk import Stack
|
|
201
|
+
from cdk_simplewebsite_deploy import CreateBasicSite
|
|
202
|
+
from constructs import Construct
|
|
195
203
|
|
|
196
|
-
class MyProjectStack(
|
|
204
|
+
class MyProjectStack(Stack):
|
|
197
205
|
|
|
198
|
-
def __init__(self, scope:
|
|
206
|
+
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
|
199
207
|
super().__init__(scope, construct_id, **kwargs)
|
|
200
208
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
sub_domain='www.example.com')
|
|
209
|
+
CreateBasicSite(self, 'test-website', website_folder='./src/build',
|
|
210
|
+
index_doc='index.html',
|
|
211
|
+
hosted_zone='example.com')
|
|
205
212
|
```
|
|
206
213
|
|
|
207
214
|
## 🚀 Enhanced Features
|
|
208
215
|
|
|
209
|
-
The `CreateCloudfrontSite` construct
|
|
216
|
+
The `CreateCloudfrontSite` construct includes optional advanced features for security, performance, and monitoring.
|
|
210
217
|
|
|
211
218
|
### Security Headers
|
|
212
219
|
Enable comprehensive security headers including HSTS, X-Frame-Options, Content-Type-Options, and XSS protection:
|
|
@@ -257,6 +264,48 @@ new CreateCloudfrontSite(this, 'waf-protected-website', {
|
|
|
257
264
|
});
|
|
258
265
|
```
|
|
259
266
|
|
|
267
|
+
### Origin Access Levels
|
|
268
|
+
Grant additional OAC permissions to the website bucket. This can be useful when you need CloudFront to distinguish missing objects from access-denied responses.
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
272
|
+
|
|
273
|
+
new CreateCloudfrontSite(this, 'website-with-list-access', {
|
|
274
|
+
websiteFolder: './src/dist',
|
|
275
|
+
indexDoc: 'index.html',
|
|
276
|
+
hostedZone: 'example.com',
|
|
277
|
+
originAccessLevels: [
|
|
278
|
+
cloudfront.AccessLevel.READ,
|
|
279
|
+
cloudfront.AccessLevel.LIST,
|
|
280
|
+
],
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### CloudFront Function Associations
|
|
285
|
+
Attach CloudFront Functions to the default behavior for lightweight viewer request or viewer response logic.
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
|
|
289
|
+
|
|
290
|
+
const rewriteFunction = new cloudfront.Function(this, 'RewriteFunction', {
|
|
291
|
+
code: cloudfront.FunctionCode.fromInline(
|
|
292
|
+
'function handler(event) { return event.request; }',
|
|
293
|
+
),
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
new CreateCloudfrontSite(this, 'website-with-function', {
|
|
297
|
+
websiteFolder: './src/dist',
|
|
298
|
+
indexDoc: 'index.html',
|
|
299
|
+
hostedZone: 'example.com',
|
|
300
|
+
functionAssociations: [
|
|
301
|
+
{
|
|
302
|
+
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
|
|
303
|
+
function: rewriteFunction,
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
260
309
|
### Custom Cache Behaviors
|
|
261
310
|
Add custom cache behaviors for different content types:
|
|
262
311
|
|
|
@@ -314,6 +363,12 @@ export class AdvancedWebsiteStack extends cdk.Stack {
|
|
|
314
363
|
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
|
|
315
364
|
super(scope, id, props);
|
|
316
365
|
|
|
366
|
+
const rewriteFunction = new cloudfront.Function(this, 'RewriteFunction', {
|
|
367
|
+
code: cloudfront.FunctionCode.fromInline(
|
|
368
|
+
'function handler(event) { return event.request; }',
|
|
369
|
+
),
|
|
370
|
+
});
|
|
371
|
+
|
|
317
372
|
new CreateCloudfrontSite(this, 'advanced-website', {
|
|
318
373
|
websiteFolder: './dist',
|
|
319
374
|
indexDoc: 'index.html',
|
|
@@ -325,6 +380,10 @@ export class AdvancedWebsiteStack extends cdk.Stack {
|
|
|
325
380
|
priceClass: cloudfront.PriceClass.PRICE_CLASS_ALL,
|
|
326
381
|
enableSecurityHeaders: true,
|
|
327
382
|
enableIpv6: true,
|
|
383
|
+
originAccessLevels: [
|
|
384
|
+
cloudfront.AccessLevel.READ,
|
|
385
|
+
cloudfront.AccessLevel.LIST,
|
|
386
|
+
],
|
|
328
387
|
|
|
329
388
|
// Monitoring & Protection
|
|
330
389
|
enableLogging: true,
|
|
@@ -337,6 +396,14 @@ export class AdvancedWebsiteStack extends cdk.Stack {
|
|
|
337
396
|
cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
|
|
338
397
|
},
|
|
339
398
|
},
|
|
399
|
+
|
|
400
|
+
// Edge Logic
|
|
401
|
+
functionAssociations: [
|
|
402
|
+
{
|
|
403
|
+
eventType: cloudfront.FunctionEventType.VIEWER_REQUEST,
|
|
404
|
+
function: rewriteFunction,
|
|
405
|
+
},
|
|
406
|
+
],
|
|
340
407
|
|
|
341
408
|
// SPA Error Handling
|
|
342
409
|
customErrorResponses: [
|
|
@@ -357,12 +424,14 @@ export class AdvancedWebsiteStack extends cdk.Stack {
|
|
|
357
424
|
- **Security Headers**: Automatic HSTS, X-Frame-Options, Content-Type-Options, and XSS protection
|
|
358
425
|
- **WAF Integration**: Support for AWS WAF Web ACLs for advanced threat protection
|
|
359
426
|
- **Origin Access Control**: Modern S3 bucket protection (replaces deprecated OAI)
|
|
427
|
+
- **Configurable OAC Permissions**: Optional origin access levels for the website bucket
|
|
360
428
|
|
|
361
429
|
### ⚡ **Optimized Performance**
|
|
362
430
|
- **Smart Caching**: Optimized cache policies for better performance
|
|
363
431
|
- **HTTP/2 & HTTP/3**: Latest protocol support for faster loading
|
|
364
432
|
- **Global Edge Locations**: Configurable price classes for worldwide distribution
|
|
365
433
|
- **IPv6 Support**: Dual-stack networking for better connectivity
|
|
434
|
+
- **CloudFront Functions**: Optional viewer request and response function associations
|
|
366
435
|
|
|
367
436
|
### 📊 **Comprehensive Monitoring**
|
|
368
437
|
- **Access Logging**: CloudFront access logs for analytics
|
|
@@ -65,6 +65,16 @@ export interface CloudfrontSiteConfiguration {
|
|
|
65
65
|
* @default - No additional cache behaviors.
|
|
66
66
|
*/
|
|
67
67
|
readonly additionalBehaviors?: Record<string, cloudfront.BehaviorOptions>;
|
|
68
|
+
/**
|
|
69
|
+
* Additional permissions granted to the CloudFront Origin Access Control for the website bucket.
|
|
70
|
+
* @default [cloudfront.AccessLevel.READ]
|
|
71
|
+
*/
|
|
72
|
+
readonly originAccessLevels?: cloudfront.AccessLevel[];
|
|
73
|
+
/**
|
|
74
|
+
* CloudFront Functions to associate with the default behavior.
|
|
75
|
+
* @default - No CloudFront Function associations.
|
|
76
|
+
*/
|
|
77
|
+
readonly functionAssociations?: cloudfront.FunctionAssociation[];
|
|
68
78
|
/**
|
|
69
79
|
* Enable response headers policy for security headers.
|
|
70
80
|
* @default false - No security headers policy applied.
|
|
@@ -96,6 +106,9 @@ export interface CloudfrontSiteConfiguration {
|
|
|
96
106
|
*/
|
|
97
107
|
readonly webAclId?: string;
|
|
98
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated Use CreateCloudfrontSite instead. CreateBasicSite configures a public S3 website endpoint.
|
|
111
|
+
*/
|
|
99
112
|
export declare class CreateBasicSite extends Construct {
|
|
100
113
|
constructor(scope: Construct, id: string, props: BasicSiteConfiguration);
|
|
101
114
|
}
|