The goal of this repository is to create the AWS CDK code for my personal cloud infrastructure for study purposes.
npm install -g aws-cdk
cdk --version
mkdir iac
cd iac
cdk init app --language=python
Activate the virtual environment and install requirements:
source .venv/bin/activate
python -m pip install -r requirements.txt
First, install Poetry.
curl -sSL https://install.python-poetry.org | python3 -
poetry --version
Next, create a new boilerplate files and folder using Poetry.
poetry new iac --name src
cd iac
Then, add the following configurations about virtual environments.
poetry config --local virtualenvs.in-project true
poetry config --local virtualenvs.create true
And add CDK to the project.
poetry add aws-cdk-lib
poetry install
And finally you need to create the necessary files expected by CDK.
Below are just examples describing the expected structure of each file.
cdk.json
{ "app":"poetry run python app.py"}
app.py
import aws_cdk as cdk
from src.cdk_stack import MyStack
app=cdk.App()
MyStack(app,"MyStack")
app.synth()
src/cdk_stack.py
import aws_cdk as cdk
from aws_cdk import aws_s3 as s3
from constructs import Construct
class MyStack(cdk.Stack):
"""CreatesaStackwith a bucket."""
def __init__(
self,
scope: Construct,
id:str,
**kwargs,
)-> None:
super().__init__(scope, id, **kwargs)
s3.Bucket(
scope=self,
id="MyBucket",
bucket_name="my-bucket-56e143c0",
removal_policy=cdk.RemovalPolicy.DESTROY,
auto_delete_objects=True
)