cdk-private-s3-hosting 0.0.0__py3-none-any.whl
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.
- cdk-private-s3-hosting/__init__.py +326 -0
- cdk-private-s3-hosting/_jsii/__init__.py +45 -0
- cdk-private-s3-hosting/_jsii/cdk-private-s3-hosting@0.0.0.jsii.tgz +0 -0
- cdk-private-s3-hosting/py.typed +1 -0
- cdk_private_s3_hosting-0.0.0.dist-info/LICENSE +202 -0
- cdk_private_s3_hosting-0.0.0.dist-info/METADATA +86 -0
- cdk_private_s3_hosting-0.0.0.dist-info/RECORD +9 -0
- cdk_private_s3_hosting-0.0.0.dist-info/WHEEL +5 -0
- cdk_private_s3_hosting-0.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,326 @@
|
|
1
|
+
r'''
|
2
|
+
# CDK Private S3 Hosting Construct
|
3
|
+
|
4
|
+
This is a CDK construct that creates a private S3 bucket and an Application Load Balancer (ALB) with a listener rule that forwards requests to the S3 bucket.
|
5
|
+
|
6
|
+
You can use this construct for a enterprise use case where you want to host a static website in a private network.
|
7
|
+
|
8
|
+
Original idea is from [this blog post](https://aws.amazon.com/jp/blogs/networking-and-content-delivery/hosting-internal-https-static-websites-with-alb-s3-and-privatelink/).
|
9
|
+
|
10
|
+
## Architecture
|
11
|
+
|
12
|
+

|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
To create a private S3 bucket and an ALB with a listener rule that forwards requests to the S3 bucket, you can use the following code:
|
17
|
+
|
18
|
+
```python
|
19
|
+
import { PrivateS3Hosting } from 'cdk-private-s3-hosting';
|
20
|
+
|
21
|
+
const privateS3Hosting = new PrivateS3Hosting(this, 'PrivateS3Hosting', {
|
22
|
+
domainName: 'cryer-nao-domain.com',
|
23
|
+
});
|
24
|
+
```
|
25
|
+
|
26
|
+
After you deploy the stack, you can access the S3 bucket using the ALB's DNS name from the VPC where the stack is deployed.
|
27
|
+
|
28
|
+
For example, if you put the `hoge.txt` file in the S3 bucket, you can access it using the following command:
|
29
|
+
|
30
|
+
```sh
|
31
|
+
curl http://cryer-nao-domain.com/hoge.txt
|
32
|
+
```
|
33
|
+
|
34
|
+
### Deploy the frontend assets
|
35
|
+
|
36
|
+
You can deploy the frontend assets to the S3 bucket like below:
|
37
|
+
|
38
|
+
```python
|
39
|
+
import { PrivateS3Hosting } from 'cdk-private-s3-hosting';
|
40
|
+
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
|
41
|
+
|
42
|
+
const privateS3Hosting = new PrivateS3Hosting(this, 'PrivateS3Hosting', {
|
43
|
+
domainName: 'cryer-nao-domain.com',
|
44
|
+
});
|
45
|
+
|
46
|
+
new s3deploy.BucketDeployment(this, 'DeployWebsite', {
|
47
|
+
sources: [s3deploy.Source.asset('./website-dist')],
|
48
|
+
destinationBucket: websiteBucket,
|
49
|
+
bucket: privateS3Hosting.bucket,
|
50
|
+
});
|
51
|
+
```
|
52
|
+
|
53
|
+
After deploying the stack, you can access the website using the `domainName` you specified from the VPC.
|
54
|
+
|
55
|
+
```sh
|
56
|
+
curl http://cryer-nao-domain.com
|
57
|
+
```
|
58
|
+
|
59
|
+
**Note**: All access to the path pattern `*/` will be redirected to `/index.html`. Therefore, it will function correctly even when the path is set on the frontend and the page is reloaded.
|
60
|
+
'''
|
61
|
+
from pkgutil import extend_path
|
62
|
+
__path__ = extend_path(__path__, __name__)
|
63
|
+
|
64
|
+
import abc
|
65
|
+
import builtins
|
66
|
+
import datetime
|
67
|
+
import enum
|
68
|
+
import typing
|
69
|
+
|
70
|
+
import jsii
|
71
|
+
import publication
|
72
|
+
import typing_extensions
|
73
|
+
|
74
|
+
import typeguard
|
75
|
+
from importlib.metadata import version as _metadata_package_version
|
76
|
+
TYPEGUARD_MAJOR_VERSION = int(_metadata_package_version('typeguard').split('.')[0])
|
77
|
+
|
78
|
+
def check_type(argname: str, value: object, expected_type: typing.Any) -> typing.Any:
|
79
|
+
if TYPEGUARD_MAJOR_VERSION <= 2:
|
80
|
+
return typeguard.check_type(argname=argname, value=value, expected_type=expected_type) # type:ignore
|
81
|
+
else:
|
82
|
+
if isinstance(value, jsii._reference_map.InterfaceDynamicProxy): # pyright: ignore [reportAttributeAccessIssue]
|
83
|
+
pass
|
84
|
+
else:
|
85
|
+
if TYPEGUARD_MAJOR_VERSION == 3:
|
86
|
+
typeguard.config.collection_check_strategy = typeguard.CollectionCheckStrategy.ALL_ITEMS # type:ignore
|
87
|
+
typeguard.check_type(value=value, expected_type=expected_type) # type:ignore
|
88
|
+
else:
|
89
|
+
typeguard.check_type(value=value, expected_type=expected_type, collection_check_strategy=typeguard.CollectionCheckStrategy.ALL_ITEMS) # type:ignore
|
90
|
+
|
91
|
+
from ._jsii import *
|
92
|
+
|
93
|
+
import aws_cdk.aws_certificatemanager as _aws_cdk_aws_certificatemanager_ceddda9d
|
94
|
+
import aws_cdk.aws_ec2 as _aws_cdk_aws_ec2_ceddda9d
|
95
|
+
import aws_cdk.aws_elasticloadbalancingv2 as _aws_cdk_aws_elasticloadbalancingv2_ceddda9d
|
96
|
+
import aws_cdk.aws_s3 as _aws_cdk_aws_s3_ceddda9d
|
97
|
+
import constructs as _constructs_77d1e7e8
|
98
|
+
|
99
|
+
|
100
|
+
class PrivateS3Hosting(
|
101
|
+
_constructs_77d1e7e8.Construct,
|
102
|
+
metaclass=jsii.JSIIMeta,
|
103
|
+
jsii_type="cdk-private-s3-hosting.PrivateS3Hosting",
|
104
|
+
):
|
105
|
+
'''A construct to host a private S3 website.'''
|
106
|
+
|
107
|
+
def __init__(
|
108
|
+
self,
|
109
|
+
scope: _constructs_77d1e7e8.Construct,
|
110
|
+
id: builtins.str,
|
111
|
+
*,
|
112
|
+
bucket_props: typing.Union[_aws_cdk_aws_s3_ceddda9d.BucketProps, typing.Dict[builtins.str, typing.Any]],
|
113
|
+
domain_name: builtins.str,
|
114
|
+
certificate: typing.Optional[_aws_cdk_aws_certificatemanager_ceddda9d.ICertificate] = None,
|
115
|
+
enable_private_dns: typing.Optional[builtins.bool] = None,
|
116
|
+
internet_facing: typing.Optional[builtins.bool] = None,
|
117
|
+
vpc: typing.Optional[_aws_cdk_aws_ec2_ceddda9d.IVpc] = None,
|
118
|
+
) -> None:
|
119
|
+
'''
|
120
|
+
:param scope: -
|
121
|
+
:param id: -
|
122
|
+
:param bucket_props: The properties for the S3 bucket. Default: - use default properties
|
123
|
+
:param domain_name: The domain name for the website. This will be used to create the S3 bucket and the ALB listener
|
124
|
+
:param certificate: The certificate for the website. Default: - use HTTP
|
125
|
+
:param enable_private_dns: Enable private DNS for the website. By eneabling this, a private hosted zone will be created for the domain name and an alias record will be created for the ALB You can access to the alb by the ``http(s)://<domainName>`` from the VPC Default: true
|
126
|
+
:param internet_facing: Whether the ALB is internet facing. Default: false
|
127
|
+
:param vpc: The VPC for the website. Default: - create a new VPC with 2 AZs and 0 NAT gateways
|
128
|
+
'''
|
129
|
+
if __debug__:
|
130
|
+
type_hints = typing.get_type_hints(_typecheckingstub__1f6a3822c2541f3c785fce5f3187d688039409f4677b681948fb4a3ae13d4292)
|
131
|
+
check_type(argname="argument scope", value=scope, expected_type=type_hints["scope"])
|
132
|
+
check_type(argname="argument id", value=id, expected_type=type_hints["id"])
|
133
|
+
props = PrivateS3HostingProps(
|
134
|
+
bucket_props=bucket_props,
|
135
|
+
domain_name=domain_name,
|
136
|
+
certificate=certificate,
|
137
|
+
enable_private_dns=enable_private_dns,
|
138
|
+
internet_facing=internet_facing,
|
139
|
+
vpc=vpc,
|
140
|
+
)
|
141
|
+
|
142
|
+
jsii.create(self.__class__, self, [scope, id, props])
|
143
|
+
|
144
|
+
@builtins.property
|
145
|
+
@jsii.member(jsii_name="alb")
|
146
|
+
def alb(
|
147
|
+
self,
|
148
|
+
) -> _aws_cdk_aws_elasticloadbalancingv2_ceddda9d.ApplicationLoadBalancer:
|
149
|
+
'''The ALB to access the website.'''
|
150
|
+
return typing.cast(_aws_cdk_aws_elasticloadbalancingv2_ceddda9d.ApplicationLoadBalancer, jsii.get(self, "alb"))
|
151
|
+
|
152
|
+
@builtins.property
|
153
|
+
@jsii.member(jsii_name="bucket")
|
154
|
+
def bucket(self) -> _aws_cdk_aws_s3_ceddda9d.Bucket:
|
155
|
+
'''The S3 bucket for hosting the website.'''
|
156
|
+
return typing.cast(_aws_cdk_aws_s3_ceddda9d.Bucket, jsii.get(self, "bucket"))
|
157
|
+
|
158
|
+
@builtins.property
|
159
|
+
@jsii.member(jsii_name="vpc")
|
160
|
+
def vpc(self) -> _aws_cdk_aws_ec2_ceddda9d.IVpc:
|
161
|
+
'''The VPC.'''
|
162
|
+
return typing.cast(_aws_cdk_aws_ec2_ceddda9d.IVpc, jsii.get(self, "vpc"))
|
163
|
+
|
164
|
+
|
165
|
+
@jsii.data_type(
|
166
|
+
jsii_type="cdk-private-s3-hosting.PrivateS3HostingProps",
|
167
|
+
jsii_struct_bases=[],
|
168
|
+
name_mapping={
|
169
|
+
"bucket_props": "bucketProps",
|
170
|
+
"domain_name": "domainName",
|
171
|
+
"certificate": "certificate",
|
172
|
+
"enable_private_dns": "enablePrivateDns",
|
173
|
+
"internet_facing": "internetFacing",
|
174
|
+
"vpc": "vpc",
|
175
|
+
},
|
176
|
+
)
|
177
|
+
class PrivateS3HostingProps:
|
178
|
+
def __init__(
|
179
|
+
self,
|
180
|
+
*,
|
181
|
+
bucket_props: typing.Union[_aws_cdk_aws_s3_ceddda9d.BucketProps, typing.Dict[builtins.str, typing.Any]],
|
182
|
+
domain_name: builtins.str,
|
183
|
+
certificate: typing.Optional[_aws_cdk_aws_certificatemanager_ceddda9d.ICertificate] = None,
|
184
|
+
enable_private_dns: typing.Optional[builtins.bool] = None,
|
185
|
+
internet_facing: typing.Optional[builtins.bool] = None,
|
186
|
+
vpc: typing.Optional[_aws_cdk_aws_ec2_ceddda9d.IVpc] = None,
|
187
|
+
) -> None:
|
188
|
+
'''Properties for PrivateS3Hosting.
|
189
|
+
|
190
|
+
:param bucket_props: The properties for the S3 bucket. Default: - use default properties
|
191
|
+
:param domain_name: The domain name for the website. This will be used to create the S3 bucket and the ALB listener
|
192
|
+
:param certificate: The certificate for the website. Default: - use HTTP
|
193
|
+
:param enable_private_dns: Enable private DNS for the website. By eneabling this, a private hosted zone will be created for the domain name and an alias record will be created for the ALB You can access to the alb by the ``http(s)://<domainName>`` from the VPC Default: true
|
194
|
+
:param internet_facing: Whether the ALB is internet facing. Default: false
|
195
|
+
:param vpc: The VPC for the website. Default: - create a new VPC with 2 AZs and 0 NAT gateways
|
196
|
+
'''
|
197
|
+
if isinstance(bucket_props, dict):
|
198
|
+
bucket_props = _aws_cdk_aws_s3_ceddda9d.BucketProps(**bucket_props)
|
199
|
+
if __debug__:
|
200
|
+
type_hints = typing.get_type_hints(_typecheckingstub__5f3ff047cbd8e8c18995347a63899f04375c4e4a279cffb2f203e5b1009daff0)
|
201
|
+
check_type(argname="argument bucket_props", value=bucket_props, expected_type=type_hints["bucket_props"])
|
202
|
+
check_type(argname="argument domain_name", value=domain_name, expected_type=type_hints["domain_name"])
|
203
|
+
check_type(argname="argument certificate", value=certificate, expected_type=type_hints["certificate"])
|
204
|
+
check_type(argname="argument enable_private_dns", value=enable_private_dns, expected_type=type_hints["enable_private_dns"])
|
205
|
+
check_type(argname="argument internet_facing", value=internet_facing, expected_type=type_hints["internet_facing"])
|
206
|
+
check_type(argname="argument vpc", value=vpc, expected_type=type_hints["vpc"])
|
207
|
+
self._values: typing.Dict[builtins.str, typing.Any] = {
|
208
|
+
"bucket_props": bucket_props,
|
209
|
+
"domain_name": domain_name,
|
210
|
+
}
|
211
|
+
if certificate is not None:
|
212
|
+
self._values["certificate"] = certificate
|
213
|
+
if enable_private_dns is not None:
|
214
|
+
self._values["enable_private_dns"] = enable_private_dns
|
215
|
+
if internet_facing is not None:
|
216
|
+
self._values["internet_facing"] = internet_facing
|
217
|
+
if vpc is not None:
|
218
|
+
self._values["vpc"] = vpc
|
219
|
+
|
220
|
+
@builtins.property
|
221
|
+
def bucket_props(self) -> _aws_cdk_aws_s3_ceddda9d.BucketProps:
|
222
|
+
'''The properties for the S3 bucket.
|
223
|
+
|
224
|
+
:default: - use default properties
|
225
|
+
'''
|
226
|
+
result = self._values.get("bucket_props")
|
227
|
+
assert result is not None, "Required property 'bucket_props' is missing"
|
228
|
+
return typing.cast(_aws_cdk_aws_s3_ceddda9d.BucketProps, result)
|
229
|
+
|
230
|
+
@builtins.property
|
231
|
+
def domain_name(self) -> builtins.str:
|
232
|
+
'''The domain name for the website.
|
233
|
+
|
234
|
+
This will be used to create the S3 bucket and the ALB listener
|
235
|
+
'''
|
236
|
+
result = self._values.get("domain_name")
|
237
|
+
assert result is not None, "Required property 'domain_name' is missing"
|
238
|
+
return typing.cast(builtins.str, result)
|
239
|
+
|
240
|
+
@builtins.property
|
241
|
+
def certificate(
|
242
|
+
self,
|
243
|
+
) -> typing.Optional[_aws_cdk_aws_certificatemanager_ceddda9d.ICertificate]:
|
244
|
+
'''The certificate for the website.
|
245
|
+
|
246
|
+
:default: - use HTTP
|
247
|
+
'''
|
248
|
+
result = self._values.get("certificate")
|
249
|
+
return typing.cast(typing.Optional[_aws_cdk_aws_certificatemanager_ceddda9d.ICertificate], result)
|
250
|
+
|
251
|
+
@builtins.property
|
252
|
+
def enable_private_dns(self) -> typing.Optional[builtins.bool]:
|
253
|
+
'''Enable private DNS for the website.
|
254
|
+
|
255
|
+
By eneabling this, a private hosted zone will be created for the domain name
|
256
|
+
and an alias record will be created for the ALB
|
257
|
+
|
258
|
+
You can access to the alb by the ``http(s)://<domainName>`` from the VPC
|
259
|
+
|
260
|
+
:default: true
|
261
|
+
'''
|
262
|
+
result = self._values.get("enable_private_dns")
|
263
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
264
|
+
|
265
|
+
@builtins.property
|
266
|
+
def internet_facing(self) -> typing.Optional[builtins.bool]:
|
267
|
+
'''Whether the ALB is internet facing.
|
268
|
+
|
269
|
+
:default: false
|
270
|
+
'''
|
271
|
+
result = self._values.get("internet_facing")
|
272
|
+
return typing.cast(typing.Optional[builtins.bool], result)
|
273
|
+
|
274
|
+
@builtins.property
|
275
|
+
def vpc(self) -> typing.Optional[_aws_cdk_aws_ec2_ceddda9d.IVpc]:
|
276
|
+
'''The VPC for the website.
|
277
|
+
|
278
|
+
:default: - create a new VPC with 2 AZs and 0 NAT gateways
|
279
|
+
'''
|
280
|
+
result = self._values.get("vpc")
|
281
|
+
return typing.cast(typing.Optional[_aws_cdk_aws_ec2_ceddda9d.IVpc], result)
|
282
|
+
|
283
|
+
def __eq__(self, rhs: typing.Any) -> builtins.bool:
|
284
|
+
return isinstance(rhs, self.__class__) and rhs._values == self._values
|
285
|
+
|
286
|
+
def __ne__(self, rhs: typing.Any) -> builtins.bool:
|
287
|
+
return not (rhs == self)
|
288
|
+
|
289
|
+
def __repr__(self) -> str:
|
290
|
+
return "PrivateS3HostingProps(%s)" % ", ".join(
|
291
|
+
k + "=" + repr(v) for k, v in self._values.items()
|
292
|
+
)
|
293
|
+
|
294
|
+
|
295
|
+
__all__ = [
|
296
|
+
"PrivateS3Hosting",
|
297
|
+
"PrivateS3HostingProps",
|
298
|
+
]
|
299
|
+
|
300
|
+
publication.publish()
|
301
|
+
|
302
|
+
def _typecheckingstub__1f6a3822c2541f3c785fce5f3187d688039409f4677b681948fb4a3ae13d4292(
|
303
|
+
scope: _constructs_77d1e7e8.Construct,
|
304
|
+
id: builtins.str,
|
305
|
+
*,
|
306
|
+
bucket_props: typing.Union[_aws_cdk_aws_s3_ceddda9d.BucketProps, typing.Dict[builtins.str, typing.Any]],
|
307
|
+
domain_name: builtins.str,
|
308
|
+
certificate: typing.Optional[_aws_cdk_aws_certificatemanager_ceddda9d.ICertificate] = None,
|
309
|
+
enable_private_dns: typing.Optional[builtins.bool] = None,
|
310
|
+
internet_facing: typing.Optional[builtins.bool] = None,
|
311
|
+
vpc: typing.Optional[_aws_cdk_aws_ec2_ceddda9d.IVpc] = None,
|
312
|
+
) -> None:
|
313
|
+
"""Type checking stubs"""
|
314
|
+
pass
|
315
|
+
|
316
|
+
def _typecheckingstub__5f3ff047cbd8e8c18995347a63899f04375c4e4a279cffb2f203e5b1009daff0(
|
317
|
+
*,
|
318
|
+
bucket_props: typing.Union[_aws_cdk_aws_s3_ceddda9d.BucketProps, typing.Dict[builtins.str, typing.Any]],
|
319
|
+
domain_name: builtins.str,
|
320
|
+
certificate: typing.Optional[_aws_cdk_aws_certificatemanager_ceddda9d.ICertificate] = None,
|
321
|
+
enable_private_dns: typing.Optional[builtins.bool] = None,
|
322
|
+
internet_facing: typing.Optional[builtins.bool] = None,
|
323
|
+
vpc: typing.Optional[_aws_cdk_aws_ec2_ceddda9d.IVpc] = None,
|
324
|
+
) -> None:
|
325
|
+
"""Type checking stubs"""
|
326
|
+
pass
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from pkgutil import extend_path
|
2
|
+
__path__ = extend_path(__path__, __name__)
|
3
|
+
|
4
|
+
import abc
|
5
|
+
import builtins
|
6
|
+
import datetime
|
7
|
+
import enum
|
8
|
+
import typing
|
9
|
+
|
10
|
+
import jsii
|
11
|
+
import publication
|
12
|
+
import typing_extensions
|
13
|
+
|
14
|
+
import typeguard
|
15
|
+
from importlib.metadata import version as _metadata_package_version
|
16
|
+
TYPEGUARD_MAJOR_VERSION = int(_metadata_package_version('typeguard').split('.')[0])
|
17
|
+
|
18
|
+
def check_type(argname: str, value: object, expected_type: typing.Any) -> typing.Any:
|
19
|
+
if TYPEGUARD_MAJOR_VERSION <= 2:
|
20
|
+
return typeguard.check_type(argname=argname, value=value, expected_type=expected_type) # type:ignore
|
21
|
+
else:
|
22
|
+
if isinstance(value, jsii._reference_map.InterfaceDynamicProxy): # pyright: ignore [reportAttributeAccessIssue]
|
23
|
+
pass
|
24
|
+
else:
|
25
|
+
if TYPEGUARD_MAJOR_VERSION == 3:
|
26
|
+
typeguard.config.collection_check_strategy = typeguard.CollectionCheckStrategy.ALL_ITEMS # type:ignore
|
27
|
+
typeguard.check_type(value=value, expected_type=expected_type) # type:ignore
|
28
|
+
else:
|
29
|
+
typeguard.check_type(value=value, expected_type=expected_type, collection_check_strategy=typeguard.CollectionCheckStrategy.ALL_ITEMS) # type:ignore
|
30
|
+
|
31
|
+
import aws_cdk._jsii
|
32
|
+
import constructs._jsii
|
33
|
+
|
34
|
+
__jsii_assembly__ = jsii.JSIIAssembly.load(
|
35
|
+
"cdk-private-s3-hosting",
|
36
|
+
"0.0.0",
|
37
|
+
__name__[0:-6],
|
38
|
+
"cdk-private-s3-hosting@0.0.0.jsii.tgz",
|
39
|
+
)
|
40
|
+
|
41
|
+
__all__ = [
|
42
|
+
"__jsii_assembly__",
|
43
|
+
]
|
44
|
+
|
45
|
+
publication.publish()
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
@@ -0,0 +1,86 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: cdk-private-s3-hosting
|
3
|
+
Version: 0.0.0
|
4
|
+
Summary: CDK Construct for a private frontend hosting S3 bucket
|
5
|
+
Home-page: https://github.com/badmintoncryer/cdk-private-s3-hosting.git
|
6
|
+
Author: Kazuho CryerShinozuka<malaysia.cryer@gmail.com>
|
7
|
+
License: Apache-2.0
|
8
|
+
Project-URL: Source, https://github.com/badmintoncryer/cdk-private-s3-hosting.git
|
9
|
+
Classifier: Intended Audience :: Developers
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: JavaScript
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
17
|
+
Classifier: Typing :: Typed
|
18
|
+
Classifier: Development Status :: 5 - Production/Stable
|
19
|
+
Classifier: License :: OSI Approved
|
20
|
+
Requires-Python: ~=3.8
|
21
|
+
Description-Content-Type: text/markdown
|
22
|
+
License-File: LICENSE
|
23
|
+
Requires-Dist: aws-cdk-lib<3.0.0,>=2.130.0
|
24
|
+
Requires-Dist: constructs<11.0.0,>=10.0.5
|
25
|
+
Requires-Dist: jsii<2.0.0,>=1.103.1
|
26
|
+
Requires-Dist: publication>=0.0.3
|
27
|
+
Requires-Dist: typeguard<5.0.0,>=2.13.3
|
28
|
+
|
29
|
+
# CDK Private S3 Hosting Construct
|
30
|
+
|
31
|
+
This is a CDK construct that creates a private S3 bucket and an Application Load Balancer (ALB) with a listener rule that forwards requests to the S3 bucket.
|
32
|
+
|
33
|
+
You can use this construct for a enterprise use case where you want to host a static website in a private network.
|
34
|
+
|
35
|
+
Original idea is from [this blog post](https://aws.amazon.com/jp/blogs/networking-and-content-delivery/hosting-internal-https-static-websites-with-alb-s3-and-privatelink/).
|
36
|
+
|
37
|
+
## Architecture
|
38
|
+
|
39
|
+

|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
To create a private S3 bucket and an ALB with a listener rule that forwards requests to the S3 bucket, you can use the following code:
|
44
|
+
|
45
|
+
```python
|
46
|
+
import { PrivateS3Hosting } from 'cdk-private-s3-hosting';
|
47
|
+
|
48
|
+
const privateS3Hosting = new PrivateS3Hosting(this, 'PrivateS3Hosting', {
|
49
|
+
domainName: 'cryer-nao-domain.com',
|
50
|
+
});
|
51
|
+
```
|
52
|
+
|
53
|
+
After you deploy the stack, you can access the S3 bucket using the ALB's DNS name from the VPC where the stack is deployed.
|
54
|
+
|
55
|
+
For example, if you put the `hoge.txt` file in the S3 bucket, you can access it using the following command:
|
56
|
+
|
57
|
+
```sh
|
58
|
+
curl http://cryer-nao-domain.com/hoge.txt
|
59
|
+
```
|
60
|
+
|
61
|
+
### Deploy the frontend assets
|
62
|
+
|
63
|
+
You can deploy the frontend assets to the S3 bucket like below:
|
64
|
+
|
65
|
+
```python
|
66
|
+
import { PrivateS3Hosting } from 'cdk-private-s3-hosting';
|
67
|
+
import * as s3deploy from 'aws-cdk-lib/aws-s3-deployment';
|
68
|
+
|
69
|
+
const privateS3Hosting = new PrivateS3Hosting(this, 'PrivateS3Hosting', {
|
70
|
+
domainName: 'cryer-nao-domain.com',
|
71
|
+
});
|
72
|
+
|
73
|
+
new s3deploy.BucketDeployment(this, 'DeployWebsite', {
|
74
|
+
sources: [s3deploy.Source.asset('./website-dist')],
|
75
|
+
destinationBucket: websiteBucket,
|
76
|
+
bucket: privateS3Hosting.bucket,
|
77
|
+
});
|
78
|
+
```
|
79
|
+
|
80
|
+
After deploying the stack, you can access the website using the `domainName` you specified from the VPC.
|
81
|
+
|
82
|
+
```sh
|
83
|
+
curl http://cryer-nao-domain.com
|
84
|
+
```
|
85
|
+
|
86
|
+
**Note**: All access to the path pattern `*/` will be redirected to `/index.html`. Therefore, it will function correctly even when the path is set on the frontend and the page is reloaded.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
cdk-private-s3-hosting/__init__.py,sha256=0E0ebc4eyTwCrP2dkjoWDvR21eax1Rd94o4901qgba8,13927
|
2
|
+
cdk-private-s3-hosting/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
3
|
+
cdk-private-s3-hosting/_jsii/__init__.py,sha256=qgUE_8RUQ9641T_uEvgydrQnBQCPcQ2Ruprl7LjAlZA,1468
|
4
|
+
cdk-private-s3-hosting/_jsii/cdk-private-s3-hosting@0.0.0.jsii.tgz,sha256=_eo4mRwUAIh6oreMLMrSF8R16vp4sNy9sDMyBBxhMmQ,42789
|
5
|
+
cdk_private_s3_hosting-0.0.0.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
6
|
+
cdk_private_s3_hosting-0.0.0.dist-info/METADATA,sha256=esybgyfS6WQ8SAV0i9lT_7xlQhMRvDGsTUsHKjX4dAM,3205
|
7
|
+
cdk_private_s3_hosting-0.0.0.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
8
|
+
cdk_private_s3_hosting-0.0.0.dist-info/top_level.txt,sha256=Garilimgavjx7-oTth2AD47uG-twwl6dTXCfLYQ1lqY,23
|
9
|
+
cdk_private_s3_hosting-0.0.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
cdk-private-s3-hosting
|