merge files from the blockchain infra repo (#59)

This commit is contained in:
autistic-symposium-helper 2024-11-17 17:03:20 -08:00 committed by GitHub
parent 23f56ef195
commit 2a6449bb85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
346 changed files with 29097 additions and 132 deletions

View 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>
```

View 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()

View file

@ -0,0 +1,3 @@
{
"app": "python3 app.py"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 771 KiB

View file

@ -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

View 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",
],
)

View file

@ -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)