mirror of
https://github.com/autistic-symposium/backend-and-orchestration-toolkit.git
synced 2025-06-08 06:53:00 -04:00
merge files from the blockchain infra repo (#59)
This commit is contained in:
parent
23f56ef195
commit
2a6449bb85
346 changed files with 29097 additions and 132 deletions
69
code/kubernetes/python-cdk/python/VPC_example/README.md
Normal file
69
code/kubernetes/python-cdk/python/VPC_example/README.md
Normal file
|
@ -0,0 +1,69 @@
|
|||
# Setting up a VPC with CDK in Python
|
||||
|
||||
[AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/home.html) is a very neat way to write infrastructure as code, enabling you to create and provision AWS infrastructure deployments predictably and repeatedly.
|
||||
|
||||
You choose your favorite language to code what resources (stacks) you want, and CDK synthetizes them to CloudFormation and helps you to deploy them to AWS.
|
||||
|
||||
In this example we see how to setup a VPC using CDK in Python.
|
||||
|
||||
### Install AWS CDK
|
||||
|
||||
Follow [this instructions](https://github.com/aws/aws-cdk#at-a-glance).
|
||||
|
||||
### Create a virtual environment and install dependencies:
|
||||
|
||||
```
|
||||
virtualenv venv
|
||||
source venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Note: If you are starting from a blank project with `cdk init app --language=python` instead, you will we need to manually install resources, such as `pip install aws_cdk.aws_ec2`.
|
||||
|
||||
### Define You VPC
|
||||
|
||||
Define how you want your VPC in the file `vpc_example/vpc_example_stack.py`:
|
||||
|
||||
```
|
||||
class VpcExampleStack(core.Stack):
|
||||
|
||||
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
|
||||
super().__init__(scope, id, **kwargs)
|
||||
|
||||
vpc = aws_ec2.Vpc(self, "MiaVPCTest", cidr="10.0.0.0/16", max_azs=3)
|
||||
```
|
||||
|
||||
|
||||
### Create synthesized CloudFormation template
|
||||
|
||||
```
|
||||
cdk synth
|
||||
```
|
||||
|
||||
You can check what changes this introduces into your AWS account:
|
||||
```
|
||||
cdk diff --profile <AWS PROFILE>
|
||||
```
|
||||
|
||||
### Deploy to AWS
|
||||
|
||||
If everything looks right, deploy:
|
||||
|
||||
```
|
||||
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
code/kubernetes/python-cdk/python/VPC_example/app.py
Normal file
11
code/kubernetes/python-cdk/python/VPC_example/app.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from aws_cdk import core
|
||||
|
||||
from vpc_example.vpc_example_stack import VpcExampleStack
|
||||
|
||||
|
||||
app = core.App()
|
||||
VpcExampleStack(app, "vpc-example")
|
||||
|
||||
app.synth()
|
3
code/kubernetes/python-cdk/python/VPC_example/cdk.json
Normal file
3
code/kubernetes/python-cdk/python/VPC_example/cdk.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"app": "python3 app.py"
|
||||
}
|
BIN
code/kubernetes/python-cdk/python/VPC_example/imgs/vpc.png
Normal file
BIN
code/kubernetes/python-cdk/python/VPC_example/imgs/vpc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 771 KiB |
|
@ -0,0 +1,14 @@
|
|||
attrs==19.1.0
|
||||
aws-cdk.aws-cloudwatch==1.10.0
|
||||
aws-cdk.aws-ec2==1.10.0
|
||||
aws-cdk.aws-iam==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
|
||||
jsii==0.17.1
|
||||
publication==0.0.3
|
||||
python-dateutil==2.8.0
|
||||
six==1.12.0
|
||||
typing-extensions==3.7.4
|
45
code/kubernetes/python-cdk/python/VPC_example/setup.py
Normal file
45
code/kubernetes/python-cdk/python/VPC_example/setup.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import setuptools
|
||||
|
||||
|
||||
with open("README.md") as fp:
|
||||
long_description = fp.read()
|
||||
|
||||
|
||||
setuptools.setup(
|
||||
name="vpc_example",
|
||||
version="0.0.1",
|
||||
|
||||
description="A VPC CDK Python example",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
author="author",
|
||||
|
||||
package_dir={"": "vpc_example"},
|
||||
packages=setuptools.find_packages(where="vpc_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",
|
||||
],
|
||||
)
|
|
@ -0,0 +1,8 @@
|
|||
from aws_cdk import core, aws_ec2
|
||||
|
||||
class VpcExampleStack(core.Stack):
|
||||
|
||||
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
|
||||
super().__init__(scope, id, **kwargs)
|
||||
|
||||
vpc = aws_ec2.Vpc(self, "MiaVPCTest", cidr="10.0.0.0/16", max_azs=3)
|
Loading…
Add table
Add a link
Reference in a new issue