Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Latest commit

 

History

History
115 lines (75 loc) · 2.97 KB

README.md

File metadata and controls

115 lines (75 loc) · 2.97 KB

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

  • .git
  • .gitignore
  • .venv
  • README.md
  • app.py
  • cdk.json
  • requirements-dev.txt
  • requirements.txt
  • source.bat
  • tests
  • A folder with the same name as the parent directory which contains a stack python script

The requirements.txt file contains

  • aws-cdk-lib
  • constructs

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