Skip to content

Commit 17a3511

Browse files
committed
feat: add CDK stack for Interacting Bear static website deployment with S3, CloudFront, and Route53
1 parent 17bdd21 commit 17a3511

7 files changed

Lines changed: 451 additions & 0 deletions

File tree

cdk/.gitignore

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
# CDK specific
132+
*.swp
133+
*.swo
134+
*~
135+
136+
# CDK Context & Staging files
137+
.cdk.staging
138+
cdk.context.json
139+
140+
# CDK output
141+
cdk.out/
142+
143+
# Node modules (if using TypeScript CDK)
144+
node_modules/
145+
146+
# IDE
147+
.vscode/
148+
.idea/
149+
*.iml
150+
151+
# OS generated files
152+
.DS_Store
153+
.DS_Store?
154+
._*
155+
.Spotlight-V100
156+
.Trashes
157+
ehthumbs.db
158+
Thumbs.db
159+
160+
# Local environment variables
161+
.env.local
162+
.env.development.local
163+
.env.test.local
164+
.env.production.local
165+
166+
# AWS credentials (should never be committed)
167+
.aws/
168+
credentials
169+
config
170+
171+
# Temporary files
172+
*.tmp
173+
*.temp

cdk/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Interacting Bear Static Website CDK Deployment
2+
3+
This CDK project deploys the infrastructure for the Interacting Bear static website at `interactingbear.jackjapar.com`.
4+
5+
## Infrastructure Components
6+
7+
- **S3 Bucket**: Stores the static website files
8+
- **CloudFront Distribution**: CDN for global content delivery
9+
- **SSL Certificate**: Automatic SSL certificate for the custom domain
10+
- **Route53 Record**: DNS record pointing to CloudFront distribution
11+
12+
## Prerequisites
13+
14+
1. AWS CLI configured with appropriate permissions
15+
2. AWS CDK CLI installed (`npm install -g aws-cdk`)
16+
3. Python 3.7+
17+
4. The `jackjapar.com` domain already configured in Route53
18+
19+
## Setup and Deployment
20+
21+
1. **Install CDK dependencies:**
22+
```bash
23+
cd cdk
24+
python3 -m venv .venv
25+
source .venv/bin/activate
26+
pip install --upgrade pip
27+
pip install -r requirements.txt
28+
```
29+
30+
2. **Bootstrap CDK (first time only):**
31+
```bash
32+
cdk bootstrap
33+
```
34+
35+
3. **Deploy the stack:**
36+
```bash
37+
cdk deploy
38+
```
39+
40+
4. **Manual Website Upload:**
41+
After deployment, upload your website files from `./build/web` to the S3 bucket:
42+
```bash
43+
aws s3 sync ../build/web s3://interacting-bear-static-website --delete
44+
```
45+
46+
5. **Invalidate CloudFront cache (if needed):**
47+
```bash
48+
aws cloudfront create-invalidation --distribution-id <DISTRIBUTION_ID> --paths "/*"
49+
```
50+
51+
## Stack Outputs
52+
53+
After deployment, you'll see:
54+
- **BucketName**: S3 bucket name for manual uploads
55+
- **DistributionId**: CloudFront distribution ID for cache invalidation
56+
- **WebsiteURL**: Your website URL (https://interactingbear.jackjapar.com)
57+
58+
## Manual Upload Process
59+
60+
Since the website files are not automatically deployed by CDK, you'll need to:
61+
62+
1. Build your Flutter web app:
63+
```bash
64+
flutter build web
65+
```
66+
67+
2. Upload to S3:
68+
```bash
69+
aws s3 sync ./build/web s3://interacting-bear-static-website --delete
70+
```
71+
72+
3. Invalidate CloudFront cache:
73+
```bash
74+
aws cloudfront create-invalidation --distribution-id <DISTRIBUTION_ID> --paths "/*"
75+
```
76+
77+
## Security Features
78+
79+
- S3 bucket blocks all public access
80+
- CloudFront uses Origin Access Control (OAC) for secure S3 access
81+
- SSL/TLS certificate automatically provisioned and renewed
82+
- HTTPS redirect enforced
83+
84+
## Cost Optimization
85+
86+
- CloudFront compression enabled
87+
- Optimized caching policies
88+
- Versioned S3 bucket for backup and rollback capabilities

cdk/app.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import aws_cdk as cdk
4+
from static_website.static_website_stack import StaticWebsiteStack
5+
6+
app = cdk.App()
7+
8+
# Get environment variables for AWS account and region
9+
account = os.getenv('CDK_DEFAULT_ACCOUNT')
10+
region = os.getenv('CDK_DEFAULT_REGION', 'us-east-1') # CloudFront requires certificates in us-east-1
11+
12+
StaticWebsiteStack(app, "InteractingBearStaticWebsiteStack",
13+
domain_name="interactingbear.jackjapar.com",
14+
hosted_zone_name="jackjapar.com",
15+
env=cdk.Environment(account=account, region=region),
16+
description="Static website deployment for Interacting Bear Flutter app"
17+
)
18+
19+
app.synth()

cdk/cdk.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"app": "python3 app.py",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"requirements*.txt",
11+
"source.bat",
12+
"**/__pycache__",
13+
"**/*.pyc"
14+
]
15+
},
16+
"context": {
17+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
18+
"@aws-cdk/core:checkSecretUsage": true,
19+
"@aws-cdk/core:target": "aws-cdk-lib.assertions",
20+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
21+
"aws-cdk:enableDiffNoFail": true,
22+
"@aws-cdk/core:stackRelativeExports": true,
23+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
24+
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
25+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
26+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
27+
"@aws-cdk/aws-redshift:columnId": true,
28+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
29+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
30+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
31+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
32+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
33+
"@aws-cdk/core:enablePartitionLiterals": true,
34+
"@aws-cdk/core:disableDeprecatedFlagProcessing": true,
35+
"@aws-cdk/aws-s3-deployment:createDefaultLoggingPolicy": true,
36+
"@aws-cdk/aws-sns:restrictSqsDescryption": true
37+
}
38+
}

cdk/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
aws-cdk-lib>=2.100.0
2+
constructs>=10.0.0
3+
boto3>=1.26.0

cdk/static_website/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Static Website CDK Stack

0 commit comments

Comments
 (0)