Snippets

Issues

  • doesn't support nested stacks very well
  • weird cyclic dependencies
    • eg: sns topic and sns

Thoughts

  • next

  • love

    • code & config, best of both
    • higher level constructs
    • lots of ways to get values in
      • ssm
    • true infrastructure as code
  • edges

    • some constructs not supported
      • can't rollback, dbsunets error
      • backtrack not there
      • eg. aurora is not well supported
    • all releases come with breaking changes
      • can't mix versions
    • docs
      • cdk latest docs out of date or even missing between 0.31 to 0.33
    • developer preview, changes all this time
      • in sapn of 3 weeks, changed from 0.31 to 0.33, breaking changes each time
      • eg. VpcNetwork -> Vpc
    • /latest/ documentation pointing to 0.31 or unavailable
    • a lot of functionality undocumented or only searchable inside pull request
      • cdk synth --no-staging
      • user guide inside github
    • what is bug in cdk vs cloudformation
  • challenge

    • names of everything is complicated
    • hard to use e
  • nitpick

    • for typescript, install everything as a separate dependency
    • no GA release yet
  • best practices

    • read the code, or the docs in the code, and then the library for the code
    • documentation
      • can't find cloudformation explanation, will use cdk code (eg. cloudformation parameter for cloudformation changeset in pipeline action)

incredible tooling

Whereas I'm always excited at the launch of new AWS services, I always brace myself for the often frustrating getting started process. Happy to say that the AWS challenged my expectations.

  • cdk init to quickly scaffold new projects

  • cdk diff to create a diff of new stack changes

    • as far as I can tell, the cdk will compare the cloudformation generated by the most recent cdk code to the yaml template generated by the previous cdk deploy command
    • this is really powerful because you get diffs in seconds (vs using cloudformation changesets which take longer and require multiple api calls)
    • found cdk diff to be more detailed a lot of the time as certain changes in cloudformation will result in TODO: pipeline change
  • cdk synth to create cloudformation template

    • this is great just to verify that the code is creating the infrastructure that I want
    • provides an eject functionality so I can use native cloudformation if I don't want to use the cdk
  • cdk deploy to validate your code, creates a changeset and deploy it

    • to re-emphasize, cdk diff will create a DIFF OF NEW STACK CHANGES
    • apologies for the caps but this is a big stinkin deal because running cloudformation against existing production stacks in the past was always an ulcer inducing moment as you never knew if this was going to be the deploy that would accidentally replace your database
    • cloudformation introduced changesets in 2016 so that you can do a diff but doing so was always painful

Concepts

  • L1 CloudFormation Resource properties
  • L2 AWS Construct
    • high level
  • tokens that evaluated to CloudFormation intrinsic functions upon synthesis (and only resolved during deployment)

Stacks

These are the equivalent of cloudformation stacks and they consist of a collection of constructs. Example from AWS:

import cdk = require("@aws-cdk/cdk");
import s3 = require("@aws-cdk/aws-s3");

interface MyStackProps extends cdk.StackProps {
  enc: boolean;
}

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props: MyStackProps) {
    super(scope, id, props);

    if (props.enc) {
      new s3.Bucket(this, "MyGroovyBucket", {
        encryption: s3.BucketEncryption.KmsManaged
      });
    } else {
      new s3.Bucket(this, "MyGroovyBucket");
    }
  }
}

Apps

This is a collection of stacks. It is an abstraction over your infrastructure.

import cdk = require("@aws-cdk/cdk");
import { MyStack } from "../lib/MyApp-stack";

const app = new cdk.App();

new MyStack(app, "MyWestCdkStack", {
  env: {
    region: "us-west-2"
  },
  enc: false
});

new MyStack(app, "MyEastCdkStack", {
  env: {
    region: "us-east-1"
  },
  enc: true
});


Backlinks