chainsaws 0.0.1__tar.gz
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.
- chainsaws-0.0.1/.gitignore +164 -0
- chainsaws-0.0.1/.python-version +1 -0
- chainsaws-0.0.1/LICENSE.txt +21 -0
- chainsaws-0.0.1/PKG-INFO +24 -0
- chainsaws-0.0.1/README.md +3 -0
- chainsaws-0.0.1/TODO.md +1 -0
- chainsaws-0.0.1/chainsaws/__init__.py +0 -0
- chainsaws-0.0.1/chainsaws/aws/__init__.py +0 -0
- chainsaws-0.0.1/chainsaws/aws/cloudfront/README.md +134 -0
- chainsaws-0.0.1/chainsaws/aws/cloudfront/__init__.py +17 -0
- chainsaws-0.0.1/chainsaws/aws/cloudfront/_cloudfront_internal.py +281 -0
- chainsaws-0.0.1/chainsaws/aws/cloudfront/cloudfront.py +475 -0
- chainsaws-0.0.1/chainsaws/aws/cloudfront/cloudfront_models.py +110 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/README.md +297 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/__init__.py +82 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/_cloudwatch_internal.py +365 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/cloudwatch.py +949 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/cloudwatch_models.py +214 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/handler.py +128 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/logger.py +110 -0
- chainsaws-0.0.1/chainsaws/aws/cloudwatch/query.py +104 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/README.md +186 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/__init__.py +31 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/_dynamodb_config.py +16 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/_dynamodb_internal.py +712 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/_dynamodb_utils.py +475 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/dynamodb.py +1756 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/dynamodb_exception.py +31 -0
- chainsaws-0.0.1/chainsaws/aws/dynamodb/dynamodb_models.py +353 -0
- chainsaws-0.0.1/chainsaws/aws/firehose/README.md +220 -0
- chainsaws-0.0.1/chainsaws/aws/firehose/__init__.py +15 -0
- chainsaws-0.0.1/chainsaws/aws/firehose/_firehose_internal.py +107 -0
- chainsaws-0.0.1/chainsaws/aws/firehose/_firehose_utils.py +18 -0
- chainsaws-0.0.1/chainsaws/aws/firehose/firehose.py +310 -0
- chainsaws-0.0.1/chainsaws/aws/firehose/firehose_models.py +41 -0
- chainsaws-0.0.1/chainsaws/aws/iam/__init__.py +11 -0
- chainsaws-0.0.1/chainsaws/aws/iam/_iam_internal.py +129 -0
- chainsaws-0.0.1/chainsaws/aws/iam/iam.py +119 -0
- chainsaws-0.0.1/chainsaws/aws/iam/iam_models.py +43 -0
- chainsaws-0.0.1/chainsaws/aws/lambda_client/__init__.py +25 -0
- chainsaws-0.0.1/chainsaws/aws/lambda_client/_lambda_internal.py +227 -0
- chainsaws-0.0.1/chainsaws/aws/lambda_client/lambda_client.py +548 -0
- chainsaws-0.0.1/chainsaws/aws/lambda_client/lambda_models.py +120 -0
- chainsaws-0.0.1/chainsaws/aws/lambda_client/lambda_utils.py +106 -0
- chainsaws-0.0.1/chainsaws/aws/rds/README.md +565 -0
- chainsaws-0.0.1/chainsaws/aws/rds/__init__.py +53 -0
- chainsaws-0.0.1/chainsaws/aws/rds/_rds_internal.py +636 -0
- chainsaws-0.0.1/chainsaws/aws/rds/rds.py +1125 -0
- chainsaws-0.0.1/chainsaws/aws/rds/rds_models.py +437 -0
- chainsaws-0.0.1/chainsaws/aws/route53/README.md +195 -0
- chainsaws-0.0.1/chainsaws/aws/route53/__init__.py +23 -0
- chainsaws-0.0.1/chainsaws/aws/route53/_route53_internal.py +280 -0
- chainsaws-0.0.1/chainsaws/aws/route53/route53.py +554 -0
- chainsaws-0.0.1/chainsaws/aws/route53/route53_constants.py +120 -0
- chainsaws-0.0.1/chainsaws/aws/route53/route53_models.py +241 -0
- chainsaws-0.0.1/chainsaws/aws/s3/README.md +210 -0
- chainsaws-0.0.1/chainsaws/aws/s3/__init__.py +31 -0
- chainsaws-0.0.1/chainsaws/aws/s3/_s3_internal.py +615 -0
- chainsaws-0.0.1/chainsaws/aws/s3/s3.py +930 -0
- chainsaws-0.0.1/chainsaws/aws/s3/s3_exception.py +3 -0
- chainsaws-0.0.1/chainsaws/aws/s3/s3_models.py +295 -0
- chainsaws-0.0.1/chainsaws/aws/s3/s3_utils.py +98 -0
- chainsaws-0.0.1/chainsaws/aws/scheduler/README.md +139 -0
- chainsaws-0.0.1/chainsaws/aws/scheduler/__init__.py +12 -0
- chainsaws-0.0.1/chainsaws/aws/scheduler/_scheduler_internal.py +128 -0
- chainsaws-0.0.1/chainsaws/aws/scheduler/scheduler.py +108 -0
- chainsaws-0.0.1/chainsaws/aws/scheduler/scheduler_models.py +56 -0
- chainsaws-0.0.1/chainsaws/aws/scheduler/scheduler_utils.py +192 -0
- chainsaws-0.0.1/chainsaws/aws/secrets_manager/README.md +168 -0
- chainsaws-0.0.1/chainsaws/aws/secrets_manager/__init__.py +19 -0
- chainsaws-0.0.1/chainsaws/aws/secrets_manager/_secrets_manager_internal.py +230 -0
- chainsaws-0.0.1/chainsaws/aws/secrets_manager/secrets_manager.py +369 -0
- chainsaws-0.0.1/chainsaws/aws/secrets_manager/secrets_manager_models.py +91 -0
- chainsaws-0.0.1/chainsaws/aws/ses/README.md +210 -0
- chainsaws-0.0.1/chainsaws/aws/ses/__init__.py +67 -0
- chainsaws-0.0.1/chainsaws/aws/ses/_ses_internal.py +199 -0
- chainsaws-0.0.1/chainsaws/aws/ses/ses.py +437 -0
- chainsaws-0.0.1/chainsaws/aws/ses/ses_models.py +147 -0
- chainsaws-0.0.1/chainsaws/aws/shared/__init__.py +0 -0
- chainsaws-0.0.1/chainsaws/aws/shared/config.py +19 -0
- chainsaws-0.0.1/chainsaws/aws/shared/session.py +56 -0
- chainsaws-0.0.1/chainsaws/aws/sqs/README.md +174 -0
- chainsaws-0.0.1/chainsaws/aws/sqs/__init__.py +21 -0
- chainsaws-0.0.1/chainsaws/aws/sqs/_sqs_internal.py +214 -0
- chainsaws-0.0.1/chainsaws/aws/sqs/sqs.py +151 -0
- chainsaws-0.0.1/chainsaws/aws/sqs/sqs_models.py +90 -0
- chainsaws-0.0.1/chainsaws/aws/ssm/README.md +185 -0
- chainsaws-0.0.1/chainsaws/aws/ssm/__init__.py +87 -0
- chainsaws-0.0.1/chainsaws/aws/ssm/_ssm_internal.py +581 -0
- chainsaws-0.0.1/chainsaws/aws/ssm/ssm.py +192 -0
- chainsaws-0.0.1/chainsaws/aws/ssm/ssm_models.py +267 -0
- chainsaws-0.0.1/chainsaws/aws/sts/README.md +108 -0
- chainsaws-0.0.1/chainsaws/aws/sts/__init__.py +19 -0
- chainsaws-0.0.1/chainsaws/aws/sts/_sts_internal.py +86 -0
- chainsaws-0.0.1/chainsaws/aws/sts/sts.py +103 -0
- chainsaws-0.0.1/chainsaws/aws/sts/sts_models.py +87 -0
- chainsaws-0.0.1/chainsaws/utils/__init__.py +0 -0
- chainsaws-0.0.1/chainsaws/utils/dict_utils/__init__.py +36 -0
- chainsaws-0.0.1/chainsaws/utils/dict_utils/dict_utils.py +97 -0
- chainsaws-0.0.1/chainsaws/utils/error_utils/README.md +145 -0
- chainsaws-0.0.1/chainsaws/utils/error_utils/__init__.py +12 -0
- chainsaws-0.0.1/chainsaws/utils/error_utils/error_utils.py +80 -0
- chainsaws-0.0.1/chainsaws/utils/error_utils/error_utils_models.py +83 -0
- chainsaws-0.0.1/chainsaws/utils/handler_utils/README.md +271 -0
- chainsaws-0.0.1/chainsaws/utils/handler_utils/__init__.py +40 -0
- chainsaws-0.0.1/chainsaws/utils/handler_utils/handler_utils.py +128 -0
- chainsaws-0.0.1/chainsaws/utils/handler_utils/handler_utils_models.py +84 -0
- chainsaws-0.0.1/pyproject.toml +67 -0
- chainsaws-0.0.1/requirements.txt +43 -0
- chainsaws-0.0.1/ruff.toml +28 -0
- chainsaws-0.0.1/uv.lock +311 -0
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
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
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# mypy
|
|
144
|
+
.mypy_cache/
|
|
145
|
+
.dmypy.json
|
|
146
|
+
dmypy.json
|
|
147
|
+
|
|
148
|
+
# Pyre type checker
|
|
149
|
+
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
#.idea/
|
|
163
|
+
|
|
164
|
+
chainsaws_playground/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
IT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Joonho Lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
chainsaws-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: chainsaws
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Chain you backend with Simple AWS wrapper
|
|
5
|
+
Project-URL: Homepage, https://github.com/whatisyourname0/chainsaws
|
|
6
|
+
Project-URL: Repository, https://github.com/whatisyourname0/chainsaws.git
|
|
7
|
+
Author-email: whatisyourname0 <mynameisjune111@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Requires-Dist: boto3>=1.35.63
|
|
16
|
+
Requires-Dist: botocore>=1.35.63
|
|
17
|
+
Requires-Dist: croniter>=5.0.1
|
|
18
|
+
Requires-Dist: cryptography>=43.0.3
|
|
19
|
+
Requires-Dist: pydantic>=2.9.2
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Chainsaws
|
|
23
|
+
|
|
24
|
+
Chain you backend with simple aws service
|
chainsaws-0.0.1/TODO.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- [ ] Lambda Event Typing하기
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# AWS CloudFront Wrapper
|
|
2
|
+
|
|
3
|
+
A high-level Python wrapper for AWS CloudFront that simplifies CDN management operations. This wrapper provides an intuitive interface for common CloudFront operations while handling AWS best practices and security configurations automatically.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Distribution Management
|
|
8
|
+
|
|
9
|
+
- Create S3-backed distributions with Origin Access Control (OAC)
|
|
10
|
+
- Create custom origin distributions
|
|
11
|
+
- Manage multiple origins and behaviors
|
|
12
|
+
- Update existing distributions
|
|
13
|
+
- Delete distributions
|
|
14
|
+
|
|
15
|
+
### Security
|
|
16
|
+
|
|
17
|
+
- Automatic Origin Access Control (OAC) setup for S3 buckets
|
|
18
|
+
- Automatic S3 bucket policy configuration
|
|
19
|
+
- WAF integration support
|
|
20
|
+
- SSL/TLS certificate management
|
|
21
|
+
|
|
22
|
+
### Cache Management
|
|
23
|
+
|
|
24
|
+
- Create cache invalidations
|
|
25
|
+
- Invalidate specific paths
|
|
26
|
+
- Bulk invalidate all files
|
|
27
|
+
- Configure cache behaviors
|
|
28
|
+
|
|
29
|
+
### Domain Management
|
|
30
|
+
|
|
31
|
+
- Add custom domains
|
|
32
|
+
- Configure alternate domain names (CNAMEs)
|
|
33
|
+
- SSL/TLS certificate association
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install chainsaws
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage Examples
|
|
42
|
+
|
|
43
|
+
### Create S3-backed Distribution
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from chainsaws.aws.cloudfront import CloudFrontAPI
|
|
47
|
+
|
|
48
|
+
cloudfront = CloudFrontAPI()
|
|
49
|
+
|
|
50
|
+
# Create distribution for S3 bucket
|
|
51
|
+
distribution = cloudfront.create_s3_distribution(
|
|
52
|
+
bucket_name="my-bucket",
|
|
53
|
+
aliases=["cdn.example.com"],
|
|
54
|
+
certificate_arn="arn:aws:acm:ap-northeast-2:123456789012:certificate/xxx",
|
|
55
|
+
default_root_object="index.html"
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Create Custom Origin Distribution
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from chainsaws.aws.cloudfront import CloudFrontAPI, BehaviorConfig
|
|
63
|
+
|
|
64
|
+
cloudfront = CloudFrontAPI()
|
|
65
|
+
|
|
66
|
+
# Define custom cache behavior
|
|
67
|
+
api_behavior = BehaviorConfig(
|
|
68
|
+
path_pattern="/api/*",
|
|
69
|
+
target_origin_id="my-api",
|
|
70
|
+
viewer_protocol_policy="https-only",
|
|
71
|
+
allowed_methods=["GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS", "PATCH"],
|
|
72
|
+
cached_methods=["GET", "HEAD", "OPTIONS"]
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Create distribution with custom origin
|
|
76
|
+
distribution = cloudfront.create_custom_distribution(
|
|
77
|
+
origin_domain="api.example.com",
|
|
78
|
+
origin_id="my-api",
|
|
79
|
+
behaviors=[api_behavior],
|
|
80
|
+
aliases=["cdn.example.com"],
|
|
81
|
+
certificate_arn="arn:aws:acm:ap-northeast-2:123456789012:certificate/xxx"
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Cache Management
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
# Invalidate specific paths
|
|
89
|
+
invalidation_id = cloudfront.invalidate_cache(
|
|
90
|
+
distribution_id="EDFDVBD6EXAMPLE",
|
|
91
|
+
paths=["/images/*", "/css/main.css"]
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Invalidate all files
|
|
95
|
+
invalidation_id = cloudfront.invalidate_all_files(
|
|
96
|
+
distribution_id="EDFDVBD6EXAMPLE"
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Add Custom Domain
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
distribution = cloudfront.add_custom_domain(
|
|
104
|
+
distribution_id="EDFDVBD6EXAMPLE",
|
|
105
|
+
domain_name="cdn.example.com",
|
|
106
|
+
certificate_arn="arn:aws:acm:ap-northeast-2:123456789012:certificate/xxx"
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Enable WAF Protection
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
distribution = cloudfront.enable_waf(
|
|
114
|
+
distribution_id="EDFDVBD6EXAMPLE",
|
|
115
|
+
web_acl_id="arn:aws:wafv2:ap-northeast-2:123456789012:global/webacl/xxx"
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Configuration
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from chainsaws.aws.cloudfront import CloudFrontAPI, CloudFrontAPIConfig
|
|
123
|
+
from chainsaws.aws.shared.config import AWSCredentials
|
|
124
|
+
|
|
125
|
+
config = CloudFrontAPIConfig(
|
|
126
|
+
credentials=AWSCredentials(
|
|
127
|
+
aws_access_key_id="YOUR_ACCESS_KEY",
|
|
128
|
+
aws_secret_access_key="YOUR_SECRET_KEY",
|
|
129
|
+
aws_region="ap-northeast-2"
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
cloudfront = CloudFrontAPI(config)
|
|
134
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from chainsaws.aws.cloudfront.cloudfront import CloudFrontAPI
|
|
2
|
+
from chainsaws.aws.cloudfront.cloudfront_models import (
|
|
3
|
+
BehaviorConfig,
|
|
4
|
+
CloudFrontAPIConfig,
|
|
5
|
+
DistributionConfig,
|
|
6
|
+
DistributionSummary,
|
|
7
|
+
OriginConfig,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"BehaviorConfig",
|
|
12
|
+
"CloudFrontAPI",
|
|
13
|
+
"CloudFrontAPIConfig",
|
|
14
|
+
"DistributionConfig",
|
|
15
|
+
"DistributionSummary",
|
|
16
|
+
"OriginConfig",
|
|
17
|
+
]
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import uuid
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import boto3
|
|
6
|
+
|
|
7
|
+
from chainsaws.aws.cloudfront.cloudfront_models import (
|
|
8
|
+
BehaviorConfig,
|
|
9
|
+
CloudFrontAPIConfig,
|
|
10
|
+
DistributionConfig,
|
|
11
|
+
DistributionSummary,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CloudFront:
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
boto3_session: boto3.Session,
|
|
21
|
+
config: CloudFrontAPIConfig | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
self.config = config or CloudFrontAPIConfig()
|
|
24
|
+
self.client = boto3_session.client("cloudfront")
|
|
25
|
+
|
|
26
|
+
def _build_distribution_config(self, config: DistributionConfig) -> dict[str, Any]:
|
|
27
|
+
"""Build CloudFront distribution configuration."""
|
|
28
|
+
origins = []
|
|
29
|
+
for origin in config.origins:
|
|
30
|
+
origin_config = {
|
|
31
|
+
"Id": origin.origin_id,
|
|
32
|
+
"DomainName": origin.domain_name,
|
|
33
|
+
"OriginPath": origin.origin_path,
|
|
34
|
+
"CustomHeaders": {
|
|
35
|
+
"Quantity": len(origin.custom_headers),
|
|
36
|
+
"Items": [
|
|
37
|
+
{"HeaderName": k, "HeaderValue": v}
|
|
38
|
+
for k, v in origin.custom_headers.items()
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if origin.s3_origin_access_identity:
|
|
44
|
+
origin_config["S3OriginConfig"] = {
|
|
45
|
+
"OriginAccessIdentity": f"origin-access-identity/cloudfront/{origin.s3_origin_access_identity}",
|
|
46
|
+
}
|
|
47
|
+
else:
|
|
48
|
+
origin_config["CustomOriginConfig"] = {
|
|
49
|
+
"HTTPPort": 80,
|
|
50
|
+
"HTTPSPort": 443,
|
|
51
|
+
"OriginProtocolPolicy": "https-only",
|
|
52
|
+
"OriginSslProtocols": {"Quantity": 1, "Items": ["TLSv1.2"]},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
origins.append(origin_config)
|
|
56
|
+
|
|
57
|
+
distribution_config = {
|
|
58
|
+
"Comment": config.comment,
|
|
59
|
+
"Enabled": config.enabled,
|
|
60
|
+
"Aliases": {
|
|
61
|
+
"Quantity": len(config.aliases),
|
|
62
|
+
"Items": config.aliases,
|
|
63
|
+
},
|
|
64
|
+
"DefaultRootObject": config.default_root_object,
|
|
65
|
+
"Origins": {
|
|
66
|
+
"Quantity": len(origins),
|
|
67
|
+
"Items": origins,
|
|
68
|
+
},
|
|
69
|
+
"DefaultCacheBehavior": self._build_cache_behavior(config.default_behavior),
|
|
70
|
+
"CacheBehaviors": {
|
|
71
|
+
"Quantity": len(config.custom_behaviors),
|
|
72
|
+
"Items": [
|
|
73
|
+
self._build_cache_behavior(behavior)
|
|
74
|
+
for behavior in config.custom_behaviors
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
"PriceClass": config.price_class,
|
|
78
|
+
"ViewerCertificate": {
|
|
79
|
+
"CloudFrontDefaultCertificate": True,
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if config.certificate_arn:
|
|
84
|
+
distribution_config["ViewerCertificate"] = {
|
|
85
|
+
"ACMCertificateArn": config.certificate_arn,
|
|
86
|
+
"SSLSupportMethod": "sni-only",
|
|
87
|
+
"MinimumProtocolVersion": "TLSv1.2_2021",
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if config.web_acl_id:
|
|
91
|
+
distribution_config["WebACLId"] = config.web_acl_id
|
|
92
|
+
|
|
93
|
+
return distribution_config
|
|
94
|
+
|
|
95
|
+
def _build_cache_behavior(self, behavior: BehaviorConfig) -> dict[str, Any]:
|
|
96
|
+
"""Build cache behavior configuration."""
|
|
97
|
+
return {
|
|
98
|
+
"PathPattern": behavior.path_pattern,
|
|
99
|
+
"TargetOriginId": behavior.target_origin_id,
|
|
100
|
+
"ViewerProtocolPolicy": behavior.viewer_protocol_policy,
|
|
101
|
+
"AllowedMethods": {
|
|
102
|
+
"Quantity": len(behavior.allowed_methods),
|
|
103
|
+
"Items": behavior.allowed_methods,
|
|
104
|
+
"CachedMethods": {
|
|
105
|
+
"Quantity": len(behavior.cached_methods),
|
|
106
|
+
"Items": behavior.cached_methods,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
"CachePolicyId": behavior.cache_policy_id,
|
|
110
|
+
"OriginRequestPolicyId": behavior.origin_request_policy_id,
|
|
111
|
+
"ResponseHeadersPolicyId": behavior.response_headers_policy_id,
|
|
112
|
+
"FunctionAssociations": {
|
|
113
|
+
"Quantity": len(behavior.function_associations),
|
|
114
|
+
"Items": behavior.function_associations,
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
def create_distribution(self, config: DistributionConfig) -> DistributionSummary:
|
|
119
|
+
"""Create new CloudFront distribution."""
|
|
120
|
+
try:
|
|
121
|
+
response = self.client.create_distribution(
|
|
122
|
+
DistributionConfig=self._build_distribution_config(config),
|
|
123
|
+
)
|
|
124
|
+
distribution = response["Distribution"]
|
|
125
|
+
|
|
126
|
+
return DistributionSummary(
|
|
127
|
+
id=distribution["Id"],
|
|
128
|
+
domain_name=distribution["DomainName"],
|
|
129
|
+
enabled=distribution["Status"] == "Deployed",
|
|
130
|
+
status=distribution["Status"],
|
|
131
|
+
aliases=distribution["DistributionConfig"]["Aliases"].get(
|
|
132
|
+
"Items", []),
|
|
133
|
+
)
|
|
134
|
+
except Exception as ex:
|
|
135
|
+
logger.exception(f"Failed to create distribution: {ex!s}")
|
|
136
|
+
raise
|
|
137
|
+
|
|
138
|
+
def get_distribution(self, distribution_id: str) -> DistributionSummary:
|
|
139
|
+
"""Get CloudFront distribution details."""
|
|
140
|
+
try:
|
|
141
|
+
response = self.client.get_distribution(Id=distribution_id)
|
|
142
|
+
distribution = response["Distribution"]
|
|
143
|
+
|
|
144
|
+
return DistributionSummary(
|
|
145
|
+
id=distribution["Id"],
|
|
146
|
+
domain_name=distribution["DomainName"],
|
|
147
|
+
enabled=distribution["Status"] == "Deployed",
|
|
148
|
+
status=distribution["Status"],
|
|
149
|
+
aliases=distribution["DistributionConfig"]["Aliases"].get(
|
|
150
|
+
"Items", []),
|
|
151
|
+
)
|
|
152
|
+
except Exception as ex:
|
|
153
|
+
logger.exception(f"Failed to get distribution: {ex!s}")
|
|
154
|
+
raise
|
|
155
|
+
|
|
156
|
+
def update_distribution(
|
|
157
|
+
self,
|
|
158
|
+
distribution_id: str,
|
|
159
|
+
config: DistributionConfig,
|
|
160
|
+
) -> DistributionSummary:
|
|
161
|
+
"""Update existing CloudFront distribution."""
|
|
162
|
+
try:
|
|
163
|
+
current = self.client.get_distribution(Id=distribution_id)
|
|
164
|
+
etag = current["ETag"]
|
|
165
|
+
|
|
166
|
+
response = self.client.update_distribution(
|
|
167
|
+
Id=distribution_id,
|
|
168
|
+
DistributionConfig=self._build_distribution_config(config),
|
|
169
|
+
IfMatch=etag,
|
|
170
|
+
)
|
|
171
|
+
distribution = response["Distribution"]
|
|
172
|
+
|
|
173
|
+
return DistributionSummary(
|
|
174
|
+
id=distribution["Id"],
|
|
175
|
+
domain_name=distribution["DomainName"],
|
|
176
|
+
enabled=distribution["Status"] == "Deployed",
|
|
177
|
+
status=distribution["Status"],
|
|
178
|
+
aliases=distribution["DistributionConfig"]["Aliases"].get(
|
|
179
|
+
"Items", []),
|
|
180
|
+
)
|
|
181
|
+
except Exception as ex:
|
|
182
|
+
logger.exception(f"Failed to update distribution: {ex!s}")
|
|
183
|
+
raise
|
|
184
|
+
|
|
185
|
+
def delete_distribution(self, distribution_id: str) -> None:
|
|
186
|
+
"""Delete CloudFront distribution."""
|
|
187
|
+
try:
|
|
188
|
+
current = self.client.get_distribution(Id=distribution_id)
|
|
189
|
+
etag = current["ETag"]
|
|
190
|
+
|
|
191
|
+
if current["Distribution"]["Status"] != "Deployed":
|
|
192
|
+
msg = "Distribution must be deployed before deletion"
|
|
193
|
+
raise ValueError(
|
|
194
|
+
msg)
|
|
195
|
+
|
|
196
|
+
if current["Distribution"]["DistributionConfig"]["Enabled"]:
|
|
197
|
+
# Disable distribution first
|
|
198
|
+
config = current["Distribution"]["DistributionConfig"]
|
|
199
|
+
config["Enabled"] = False
|
|
200
|
+
self.client.update_distribution(
|
|
201
|
+
Id=distribution_id,
|
|
202
|
+
DistributionConfig=config,
|
|
203
|
+
IfMatch=etag,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
self.client.delete_distribution(
|
|
207
|
+
Id=distribution_id,
|
|
208
|
+
IfMatch=etag,
|
|
209
|
+
)
|
|
210
|
+
except Exception as ex:
|
|
211
|
+
logger.exception(f"Failed to delete distribution: {ex!s}")
|
|
212
|
+
raise
|
|
213
|
+
|
|
214
|
+
def invalidate_cache(
|
|
215
|
+
self,
|
|
216
|
+
distribution_id: str,
|
|
217
|
+
paths: list[str],
|
|
218
|
+
) -> str:
|
|
219
|
+
"""Create cache invalidation."""
|
|
220
|
+
try:
|
|
221
|
+
response = self.client.create_invalidation(
|
|
222
|
+
DistributionId=distribution_id,
|
|
223
|
+
InvalidationBatch={
|
|
224
|
+
"Paths": {
|
|
225
|
+
"Quantity": len(paths),
|
|
226
|
+
"Items": paths,
|
|
227
|
+
},
|
|
228
|
+
"CallerReference": str(uuid.uuid4()),
|
|
229
|
+
},
|
|
230
|
+
)
|
|
231
|
+
return response["Invalidation"]["Id"]
|
|
232
|
+
except Exception as ex:
|
|
233
|
+
logger.exception(f"Failed to create invalidation: {ex!s}")
|
|
234
|
+
raise
|
|
235
|
+
|
|
236
|
+
def create_origin_access_control(
|
|
237
|
+
self,
|
|
238
|
+
bucket_name: str,
|
|
239
|
+
) -> str:
|
|
240
|
+
"""Create Origin Access Control for S3 bucket.
|
|
241
|
+
|
|
242
|
+
Args:
|
|
243
|
+
bucket_name: S3 bucket name
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
str: Origin Access Control ID
|
|
247
|
+
|
|
248
|
+
Raises:
|
|
249
|
+
Exception: If creation fails
|
|
250
|
+
|
|
251
|
+
"""
|
|
252
|
+
try:
|
|
253
|
+
response = self.client.create_origin_access_control(
|
|
254
|
+
OriginAccessControlConfig={
|
|
255
|
+
"Name": f"OAC-{bucket_name}",
|
|
256
|
+
"Description": f"OAC for {bucket_name}",
|
|
257
|
+
"SigningProtocol": "sigv4",
|
|
258
|
+
"SigningBehavior": "always",
|
|
259
|
+
"OriginAccessControlOriginType": "s3",
|
|
260
|
+
},
|
|
261
|
+
)
|
|
262
|
+
return response["OriginAccessControl"]["Id"]
|
|
263
|
+
except Exception:
|
|
264
|
+
logger.exception("Failed to create Origin Access Control")
|
|
265
|
+
raise
|
|
266
|
+
|
|
267
|
+
def delete_origin_access_control(self, oac_id: str) -> None:
|
|
268
|
+
"""Delete Origin Access Control.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
oac_id: Origin Access Control ID
|
|
272
|
+
|
|
273
|
+
Raises:
|
|
274
|
+
Exception: If deletion fails
|
|
275
|
+
|
|
276
|
+
"""
|
|
277
|
+
try:
|
|
278
|
+
self.client.delete_origin_access_control(Id=oac_id)
|
|
279
|
+
except Exception:
|
|
280
|
+
logger.exception("Failed to delete Origin Access Control")
|
|
281
|
+
raise
|