AWS CDK
Developer Centric > Infrastructure as Code > Next Generation
Digital Transformation – 2019 November
Cloud Development Kit
© DIGITAL TRANSFORMATION AWS CDK 2
KASUN JAYASURIYA
Software Architect @ Digital Transformation
kasundilunika@gmail.com
@dilunika
www.linkedin.com/in/kasundilunika
medium.com/@dilunika
kasun@digitaltransformation.co.nz
@DTL_NZ
www.linkedin.com/company/dtlnz
medium.com/dtlpub
PRESENTATION
AGENDA
Infrastructure as Code (IaC)
IaC in Serverless & CDK
Practical Case Study - Piglet
CDK Concepts & Demo
Pros & Cons
01
02
03
04
05
© DIGITAL TRANSFORMATION AWS CDK 4
INFRASTRUCTURE AS CODE
brings your networks, virtual machines, load balancers, and connection topology into some form of source code
Without IaC, teams must maintain the settings of individual deployment
environments. Over time, each environment becomes a snowflake, that is,
a unique configuration that cannot be reproduced automatically.
SOLVE THE PROBLEM OF ENVIRONMENT DRIFT
Idempotence is the property that a deployment command always sets
the target environment into the same configuration, regardless of the
environment’s starting state. Idempotency is achieved by either
automatically configuring an existing target or by discarding the existing
target and recreating a fresh environment.
MAINTAINS IDEMPOTENCY
Accordingly, with IaC, teams make changes to the environment description
and version the configuration model, which is typically in well-documented
code formats such as JSON. The release pipeline executes the model to
configure target environments. If the team needs to make changes, they
edit the source, not the target.
VERSION EVERY CHANGE
© DIGITAL TRANSFORMATION
PUBLIC CLOUDS & VENDORS
Their Cloud, Their APIs
AWS APIS & SDK
AWS has exposed majority of their cloud resources publicly
using REST APIs. In addition to the APIs, there are SDKs written
in all the major programming languages which makes
programmers life easy.
AWS CLOUD FORMATION
Cloud Formation is the next level abstraction of SDK. It provides
you set of tools that you can define your cloud resources
declaratively using YAML or JSON syntax.
HASHICORP TERRAFORM
Terraform is an open-source infrastructure as code software tool
created by HashiCorp. It enables users to define and provision a
datacenter infrastructure using a high-level configuration language
known as Hashicorp Configuration Language
Terraform
Cloud Formation
SDKs
Web APIs
AWS HAS STRONG SDK
AWS has released SDKs for almost
all services in multiple languages.
BUT SDK DOESN’T
MAINTAIN THE STATE
When you are working with SDK,
you are responsible for maintaining
the state of the infrastructure
created
CDK TAKES CARE OF THE
STATE
CDK is an extension of Cloud
Formation. It does the entire state
management as CF does
WHY CDK? THERE IS SDK
Reinventing wheel?
AWS CDK
Terraform
Cloud Formation
SDKs
Web APIs
State
State
“SERVERLESS APPLICATION
DEVELOPMENT CHALLENGED THE
PRACTICES WE FOLLOWED IN OUR
IAC FRONT”
MORE WORK TO OPS TEAM
1
2
4
5
3
1. Jenkins runs terraform scripts to setup the environment
2. Terraform creates network resources in AWS
3. Serverless configurations files are updated with extracted resources addresses
4. Jenkins trigger serverless deployment scripts
5. Serverless creates application resources in AWS
Single IaC framework for both infrastructure and lambda
Developer friendly and less bulky compared to Cloud Formation
No manual work or bridging code required in between
CDK, A SOLUTION
© DIGITAL TRANSFORMATION
CDK CONCEPTS
Basically three constructs
APPS
STACKS
CONSTRUCTS
A construct represents a "cloud component" and
encapsulates everything AWS CloudFormation
needs to create the component.
The unit of deployment in the AWS CDK is
called a stack. A root construct which
represents a single CloudFormation stack.
A construct which represents an entire CDK
app. This construct is normally the root of the
construct tree.
HAS IT BEEN EVER
USED IN
PRODUCTION?
YES WE DO
PIGLET
Budget & Expense Manager Application Suite
© DIGITAL TRANSFORMATION AWS CDK 13
© DIGITAL TRANSFORMATION AWS CDK 15
RTO DETAILED
Setting up entire infrastructure from the scratch and deploy full application
ALEXA SKILL
DEPLOYMENT
SETTING UP
INFRASTRUCTURE
E2E REGRESSION
TEST RUN
API DEPLOYMENT PORTAL
DEPLOYMENT
5 MINUTES 2 MINUTES 5 MINUTES
10 MINUTES 10 MINUTES*
© DIGITAL TRANSFORMATION AWS CDK 16
© DIGITAL TRANSFORMATION AWS CDK 17
CDK APP
Root of the the entire structure
© DIGITAL TRANSFORMATION AWS CDK 18
MICROSERVICES STACK
This stack deploys all the infrastructure resources related to Piglet APIs
PARENT
STACK PROPS
CONSTRUCTOR
You must instantiate all the construct which you want
to attach with this stack. This is the only public
function interface framework identifies and execute.
Props is the data structure that you use to pass all the
extra details to the stack
Reference of the app should be passed as the parent.
© DIGITAL TRANSFORMATION AWS CDK 19
MICROSERVICE CONSTRUCT
Microservice contains one or more lambda and it associated resources
PARENT
CONSTRUCTOR PROPS
CONSTRUCTOR
You must write all your resource creation code here.
This is the only public function interface framework
identifies and execute.
Props is the data structure that you use to pass all the
extra details to the construct
Reference of the stack should be passed as the
parent.
LET’S SEE SOME CODE
© DIGITAL TRANSFORMATION AWS CDK 22
CDK
PROS
AND
CONS
Most of the services are still in
unstable development stage. With
every update, you will get breaking
changes.
Some of the key services still haven’t
released any CDK module. When
you are working on a project where
lots of AWS services are required,
there is a high chance that you must
use hybrid approach.
Incomplete documentation and lack
of examples in the internet.
Several critical bugs still unresolved
for many releases.
CONS
Usage of general-purpose
programming languages makes its
easy to align on programming best
practices that you follow in the
organization as a development team.
Sensible defaults reduces number of
code lines that you must write.
Ability to build reusable libraries
reduced the amount of copy pastes
you did with its predecessor, Cloud
Formation .
PROS
© DIGITAL TRANSFORMATION AWS CDK 23
Q & A
kasundilunika@gmail.com
@dilunika
www.linkedin.com/in/kasundilunika
medium.com/@dilunika
kasun@digitaltransformation.co.nz
@DTL_NZ
www.linkedin.com/company/dtlnz
medium.com/dtlpub

AWS CDK Introduction

  • 1.
    AWS CDK Developer Centric> Infrastructure as Code > Next Generation Digital Transformation – 2019 November Cloud Development Kit
  • 2.
    © DIGITAL TRANSFORMATIONAWS CDK 2 KASUN JAYASURIYA Software Architect @ Digital Transformation kasundilunika@gmail.com @dilunika www.linkedin.com/in/kasundilunika medium.com/@dilunika kasun@digitaltransformation.co.nz @DTL_NZ www.linkedin.com/company/dtlnz medium.com/dtlpub
  • 3.
    PRESENTATION AGENDA Infrastructure as Code(IaC) IaC in Serverless & CDK Practical Case Study - Piglet CDK Concepts & Demo Pros & Cons 01 02 03 04 05
  • 4.
    © DIGITAL TRANSFORMATIONAWS CDK 4 INFRASTRUCTURE AS CODE brings your networks, virtual machines, load balancers, and connection topology into some form of source code Without IaC, teams must maintain the settings of individual deployment environments. Over time, each environment becomes a snowflake, that is, a unique configuration that cannot be reproduced automatically. SOLVE THE PROBLEM OF ENVIRONMENT DRIFT Idempotence is the property that a deployment command always sets the target environment into the same configuration, regardless of the environment’s starting state. Idempotency is achieved by either automatically configuring an existing target or by discarding the existing target and recreating a fresh environment. MAINTAINS IDEMPOTENCY Accordingly, with IaC, teams make changes to the environment description and version the configuration model, which is typically in well-documented code formats such as JSON. The release pipeline executes the model to configure target environments. If the team needs to make changes, they edit the source, not the target. VERSION EVERY CHANGE
  • 5.
    © DIGITAL TRANSFORMATION PUBLICCLOUDS & VENDORS Their Cloud, Their APIs AWS APIS & SDK AWS has exposed majority of their cloud resources publicly using REST APIs. In addition to the APIs, there are SDKs written in all the major programming languages which makes programmers life easy. AWS CLOUD FORMATION Cloud Formation is the next level abstraction of SDK. It provides you set of tools that you can define your cloud resources declaratively using YAML or JSON syntax. HASHICORP TERRAFORM Terraform is an open-source infrastructure as code software tool created by HashiCorp. It enables users to define and provision a datacenter infrastructure using a high-level configuration language known as Hashicorp Configuration Language Terraform Cloud Formation SDKs Web APIs
  • 6.
    AWS HAS STRONGSDK AWS has released SDKs for almost all services in multiple languages. BUT SDK DOESN’T MAINTAIN THE STATE When you are working with SDK, you are responsible for maintaining the state of the infrastructure created CDK TAKES CARE OF THE STATE CDK is an extension of Cloud Formation. It does the entire state management as CF does WHY CDK? THERE IS SDK Reinventing wheel? AWS CDK Terraform Cloud Formation SDKs Web APIs State State
  • 7.
    “SERVERLESS APPLICATION DEVELOPMENT CHALLENGEDTHE PRACTICES WE FOLLOWED IN OUR IAC FRONT” MORE WORK TO OPS TEAM
  • 8.
    1 2 4 5 3 1. Jenkins runsterraform scripts to setup the environment 2. Terraform creates network resources in AWS 3. Serverless configurations files are updated with extracted resources addresses 4. Jenkins trigger serverless deployment scripts 5. Serverless creates application resources in AWS
  • 9.
    Single IaC frameworkfor both infrastructure and lambda Developer friendly and less bulky compared to Cloud Formation No manual work or bridging code required in between CDK, A SOLUTION
  • 10.
    © DIGITAL TRANSFORMATION CDKCONCEPTS Basically three constructs APPS STACKS CONSTRUCTS A construct represents a "cloud component" and encapsulates everything AWS CloudFormation needs to create the component. The unit of deployment in the AWS CDK is called a stack. A root construct which represents a single CloudFormation stack. A construct which represents an entire CDK app. This construct is normally the root of the construct tree.
  • 11.
    HAS IT BEENEVER USED IN PRODUCTION? YES WE DO
  • 12.
    PIGLET Budget & ExpenseManager Application Suite
  • 13.
  • 15.
    © DIGITAL TRANSFORMATIONAWS CDK 15 RTO DETAILED Setting up entire infrastructure from the scratch and deploy full application ALEXA SKILL DEPLOYMENT SETTING UP INFRASTRUCTURE E2E REGRESSION TEST RUN API DEPLOYMENT PORTAL DEPLOYMENT 5 MINUTES 2 MINUTES 5 MINUTES 10 MINUTES 10 MINUTES*
  • 16.
  • 17.
    © DIGITAL TRANSFORMATIONAWS CDK 17 CDK APP Root of the the entire structure
  • 18.
    © DIGITAL TRANSFORMATIONAWS CDK 18 MICROSERVICES STACK This stack deploys all the infrastructure resources related to Piglet APIs PARENT STACK PROPS CONSTRUCTOR You must instantiate all the construct which you want to attach with this stack. This is the only public function interface framework identifies and execute. Props is the data structure that you use to pass all the extra details to the stack Reference of the app should be passed as the parent.
  • 19.
    © DIGITAL TRANSFORMATIONAWS CDK 19 MICROSERVICE CONSTRUCT Microservice contains one or more lambda and it associated resources PARENT CONSTRUCTOR PROPS CONSTRUCTOR You must write all your resource creation code here. This is the only public function interface framework identifies and execute. Props is the data structure that you use to pass all the extra details to the construct Reference of the stack should be passed as the parent.
  • 20.
  • 22.
    © DIGITAL TRANSFORMATIONAWS CDK 22 CDK PROS AND CONS Most of the services are still in unstable development stage. With every update, you will get breaking changes. Some of the key services still haven’t released any CDK module. When you are working on a project where lots of AWS services are required, there is a high chance that you must use hybrid approach. Incomplete documentation and lack of examples in the internet. Several critical bugs still unresolved for many releases. CONS Usage of general-purpose programming languages makes its easy to align on programming best practices that you follow in the organization as a development team. Sensible defaults reduces number of code lines that you must write. Ability to build reusable libraries reduced the amount of copy pastes you did with its predecessor, Cloud Formation . PROS
  • 23.
    © DIGITAL TRANSFORMATIONAWS CDK 23 Q & A kasundilunika@gmail.com @dilunika www.linkedin.com/in/kasundilunika medium.com/@dilunika kasun@digitaltransformation.co.nz @DTL_NZ www.linkedin.com/company/dtlnz medium.com/dtlpub