mirror of
https://github.com/autistic-symposium/backend-and-orchestration-toolkit.git
synced 2025-06-09 07:22:40 -04:00
Clean up this repo
This commit is contained in:
parent
0d4632e7dd
commit
024892437e
309 changed files with 7 additions and 15 deletions
70
kubernetes/python-cdk/python/PostgreSQL_example/README.md
Normal file
70
kubernetes/python-cdk/python/PostgreSQL_example/README.md
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Setting up a PostgreSQL RDS with CDK in Python
|
||||
|
||||
### Create a virtual environment and install dependencies:
|
||||
|
||||
```
|
||||
virtualenv .env
|
||||
source .env/bin/activate
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
### Define You RDS DB
|
||||
|
||||
Add any constant variable in `cdk.json` and then define how you want your RDS instance in `postgre_sql_example/postgre_sql_example_stack.py`:
|
||||
|
||||
```
|
||||
class PostgreSqlExampleStack(core.Stack):
|
||||
|
||||
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
|
||||
super().__init__(scope, id, **kwargs)
|
||||
|
||||
# Database Instance
|
||||
instance = rds.DatabaseInstance(self,
|
||||
'examplepostgresdbinstance',
|
||||
master_username=master_username,
|
||||
engine=rds.DatabaseInstanceEngine.POSTGRES, instance_class=ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
|
||||
vpc=self.vpc,
|
||||
auto_minor_version_upgrade=auto_minor_version_upgrade,
|
||||
availability_zone=availability_zone,
|
||||
database_name=database_name,
|
||||
enable_performance_insights=enable_performance_insights,
|
||||
storage_encrypted=storage_encrypted,
|
||||
multi_az=multi_az,
|
||||
backup_retention=backup_retention,
|
||||
monitoring_interval=monitoring_interval,
|
||||
)
|
||||
```
|
||||
|
||||
### Create synthesized CloudFormation templates
|
||||
|
||||
```
|
||||
cdk synth
|
||||
```
|
||||
|
||||
You can check what changes are introduced into your current AWS resources with:
|
||||
```
|
||||
cdk diff --profile <AWS PROFILE>
|
||||
```
|
||||
|
||||
|
||||
### Deploy to AWS
|
||||
|
||||
If everything looks OK, deploy with:
|
||||
|
||||
```
|
||||
cdk deploy --profile <AWS PROFILE>
|
||||
```
|
||||
|
||||
To check all the stacks in the app:
|
||||
|
||||
```
|
||||
cdk ls
|
||||
```
|
||||
|
||||
### Clean up
|
||||
|
||||
To destroy/remove all the newly created resources, run:
|
||||
|
||||
```
|
||||
cdk destroy --profile <AWS PROFILE>
|
||||
```
|
11
kubernetes/python-cdk/python/PostgreSQL_example/app.py
Normal file
11
kubernetes/python-cdk/python/PostgreSQL_example/app.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from aws_cdk import core
|
||||
|
||||
from postgre_sql_example.postgre_sql_example_stack import PostgreSqlExampleStack
|
||||
|
||||
|
||||
app = core.App()
|
||||
PostgreSqlExampleStack(app, "postgre-sql-example")
|
||||
|
||||
app.synth()
|
16
kubernetes/python-cdk/python/PostgreSQL_example/cdk.json
Normal file
16
kubernetes/python-cdk/python/PostgreSQL_example/cdk.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"app": "python3 app.py",
|
||||
"context": {
|
||||
"rds.auto_minor_version_upgrade": false,
|
||||
"rds.availability_zone":
|
||||
"rds.backup_retention":
|
||||
"rds.database_name": "postgres_db",
|
||||
"rds.enable_performance_insights": true,
|
||||
"rds.master_username": "postgres",
|
||||
"rds.monitoring_interval": 60,
|
||||
"rds.multi_az": false,
|
||||
"rds.storage_encrypted": false,
|
||||
"vpc.cidr": "10.0.0.0/16",
|
||||
"vpc.max_azs":
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
import json
|
||||
import sys
|
||||
from aws_cdk import (
|
||||
aws_ec2 as ec2,
|
||||
aws_rds as rds,
|
||||
core as core,
|
||||
)
|
||||
|
||||
# Python CDK does not have get_context yet.
|
||||
def _get_context():
|
||||
CONTEXT_FILE = 'cdk.json'
|
||||
try:
|
||||
with open(CONTEXT_FILE, 'r') as f:
|
||||
return json.load(f)['context']
|
||||
except IOError:
|
||||
print('Could not open context file {}. Exiting...'.format(CONTEXT_FILE))
|
||||
sys.exit(1)
|
||||
except KeyError as e:
|
||||
print('Context file {0} is misconfigured {1}. Exiting...'.format(CONTEXT_FILE, e))
|
||||
sys.exit(1)
|
||||
|
||||
class PostgreSqlExampleStack(core.Stack):
|
||||
|
||||
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
|
||||
super().__init__(scope, id, **kwargs)
|
||||
|
||||
# Grab variables from cdk.json
|
||||
context = _get_context()
|
||||
auto_minor_version_upgrade = context["rds.auto_minor_version_upgrade"]
|
||||
availability_zone = context["rds.availability_zone"]
|
||||
backup_retention = core.Duration.days(context["rds.backup_retention"])
|
||||
database_name = context["rds.database_name"]
|
||||
enable_performance_insights = context["rds.enable_performance_insights"]
|
||||
master_username = context["rds.master_username"]
|
||||
monitoring_interval = core.Duration.seconds(context["rds.monitoring_interval"])
|
||||
multi_az = context["rds.multi_az"]
|
||||
storage_encrypted = context["rds.storage_encrypted"]
|
||||
cidr = context["vpc.cidr"]
|
||||
max_azs = context["vpc.max_azs"]
|
||||
|
||||
# Set VPC
|
||||
self.vpc = ec2.Vpc(self, "VPCTest", cidr=cidr, max_azs=max_azs)
|
||||
|
||||
# Database Instance
|
||||
instance = rds.DatabaseInstance(self,
|
||||
'storefrontrdspostgresdbinstance',
|
||||
master_username=master_username,
|
||||
engine=rds.DatabaseInstanceEngine.POSTGRES, instance_class=ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
|
||||
vpc=self.vpc,
|
||||
auto_minor_version_upgrade=auto_minor_version_upgrade,
|
||||
availability_zone=availability_zone,
|
||||
database_name=database_name,
|
||||
enable_performance_insights=enable_performance_insights,
|
||||
storage_encrypted=storage_encrypted,
|
||||
multi_az=multi_az,
|
||||
backup_retention=backup_retention,
|
||||
monitoring_interval=monitoring_interval,
|
||||
)
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
astroid==2.2.5
|
||||
attrs==19.1.0
|
||||
aws-cdk.assets==1.10.0
|
||||
aws-cdk.aws-cloudwatch==1.10.0
|
||||
aws-cdk.aws-ec2==1.10.0
|
||||
aws-cdk.aws-events==1.10.0
|
||||
aws-cdk.aws-iam==1.10.0
|
||||
aws-cdk.aws-kms==1.10.0
|
||||
aws-cdk.aws-lambda==1.10.0
|
||||
aws-cdk.aws-logs==1.10.0
|
||||
aws-cdk.aws-rds==1.10.0
|
||||
aws-cdk.aws-s3==1.10.0
|
||||
aws-cdk.aws-s3-assets==1.10.0
|
||||
aws-cdk.aws-sam==1.10.0
|
||||
aws-cdk.aws-secretsmanager==1.10.0
|
||||
aws-cdk.aws-sqs==1.10.0
|
||||
aws-cdk.aws-ssm==1.10.0
|
||||
aws-cdk.core==1.10.0
|
||||
aws-cdk.cx-api==1.10.0
|
||||
aws-cdk.region-info==1.10.0
|
||||
cattrs==0.9.0
|
||||
isort==4.3.21
|
||||
jsii==0.17.1
|
||||
lazy-object-proxy==1.4.2
|
||||
mccabe==0.6.1
|
||||
pep8==1.7.1
|
||||
publication==0.0.3
|
||||
pylint==2.3.1
|
||||
python-dateutil==2.8.0
|
||||
six==1.12.0
|
||||
typed-ast==1.4.0
|
||||
typing-extensions==3.7.4
|
||||
virtualenv==16.7.4
|
||||
wrapt==1.11.2
|
45
kubernetes/python-cdk/python/PostgreSQL_example/setup.py
Normal file
45
kubernetes/python-cdk/python/PostgreSQL_example/setup.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import setuptools
|
||||
|
||||
|
||||
with open("README.md") as fp:
|
||||
long_description = fp.read()
|
||||
|
||||
|
||||
setuptools.setup(
|
||||
name="postgre_sql_example",
|
||||
version="0.0.1",
|
||||
|
||||
description="A postgres CDK Python example",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
author="author",
|
||||
|
||||
package_dir={"": "postgre_sql_example"},
|
||||
packages=setuptools.find_packages(where="postgre_sql_example"),
|
||||
|
||||
install_requires=[
|
||||
"aws-cdk.core",
|
||||
],
|
||||
|
||||
python_requires=">=3.6",
|
||||
|
||||
classifiers=[
|
||||
"Development Status :: 4 - Beta",
|
||||
|
||||
"Intended Audience :: Developers",
|
||||
|
||||
"License :: OSI Approved :: Apache Software License",
|
||||
|
||||
"Programming Language :: JavaScript",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
|
||||
"Topic :: Software Development :: Code Generators",
|
||||
"Topic :: Utilities",
|
||||
|
||||
"Typing :: Typed",
|
||||
],
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue