Francisco Camargo

Logo

Data Scientist & Machine Learning Engineer

View the Project on GitHub francisco-camargo/francisco-camargo

AWS Cloud Development Kit (CDK)

Return to top README.md

TODO: try to do this within a Docker Container

Install CDK

AWS Getting Started Guide

Initialize

To initialize an Application, go to the desired parent directory for the project and run

cdk init app --language=python

There are other language options.

This will initialize this folder as a git repository.

Is this ran properly, a .venv environment folder will have been created unto which you can install any packages of interest. To activate, try

. .venv/bin/activate

Additionally, several other files are made including

The requirements.txt file contains

The requirements-dev.txt file contains pytest

app.py

The app will invoke any Stacks of interest

#!/usr/bin/env python3
import os

import aws_cdk as cdk

from project_name.project_name_stack import ProjectStack
# This is the custom stack definition


app = cdk.App()
ProjectStack(app, "ProjectStack",
    # If you don't specify 'env', this stack will be environment-agnostic.
    # Account/Region-dependent features and context lookups will not work,
    # but a single synthesized template can be deployed anywhere.

    env=cdk.Environment(account=os.getenv('CDK_DEFAULT_ACCOUNT'), region=os.getenv('CDK_DEFAULT_REGION')),

    # For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html
    )

app.synth()

Constructs

A Stack is made up of Constructs, here are references for a few

Synthesize and Deploy

Run

cdk bootstrap

The cdk bootstrap command will deploy a CloudFormation stack named CDKToolkit to the AWS account using the credentials you configured in a previous lab step. The stack consists of an S3 staging bucket that is used for storing any assets used in your CDK application.

To synthesize a CloudFormation template, run

cdk synth

This will create a new folder, cdk.out

To deploy, run

cdk deploy

Once complete you will be given a Stack ARN