Skip to content

Commit 6a853bf

Browse files
committed
Start to build website deploy custom resource
1 parent 884d5a5 commit 6a853bf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

cdk/quiz_app/quiz_app_stack.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
from aws_cdk import (
77
# Duration,
88
Stack,
9+
aws_s3 as s3,
910
aws_apigateway as apigateway,
1011
aws_dynamodb as dynamodb,
12+
aws_cloudfront as cf,
1113
aws_iam as iam,
1214
aws_lambda as _lambda,
15+
aws_lambda_nodejs as _jslambda,
1316
aws_sns as sns,
1417
aws_stepfunctions as sfn,
1518
aws_pipes as pipes,
@@ -294,6 +297,28 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
294297
role=state_machine_role,
295298
)
296299

300+
webapp_bucket = s3.Bucket(
301+
self,
302+
"WebAppBucket",
303+
auto_delete_objects=True,
304+
removal_policy=aws_cdk.RemovalPolicy.DESTROY,
305+
)
306+
origin_access_identity = cf.OriginAccessIdentity(self, "OriginAccessIdentity")
307+
webapp_bucket.grant_read(origin_access_identity)
308+
custom_resource_lambda = _lambda.Function(
309+
self,
310+
"WebsiteDeployFunction",
311+
runtime=_lambda.Runtime.NODEJS_LATEST,
312+
handler="index.handler",
313+
memory_size=1024,
314+
ephemeral_storage_size=aws_cdk.Size.gibibytes(8),
315+
code=_lambda.Code.from_asset("./website_deploy"),
316+
timeout=aws_cdk.Duration.seconds(300),
317+
# TODO
318+
environment={},
319+
)
320+
webapp_bucket.grant_write(custom_resource_lambda)
321+
297322
@staticmethod
298323
def read_policy_file(file_path: str) -> dict:
299324
"""Reads a JSON policy file and returns it as a dictionary."""

cdk/website_deploy/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exports.handler = async function(event, context) {
2+
return { status: "ok" };
3+
}

0 commit comments

Comments
 (0)