Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Infrastructure as --> is Code with AWS CDK

Infrastructure as --> is Code with AWS CDK

Donnie Prakoso

March 24, 2022
Tweet

More Decks by Donnie Prakoso

Other Decks in Technology

Transcript

  1. © 2022, Amazon Web Services, Inc. or its Affiliates.
    Sr. Developer Advocate, ASEAN
    Amazon Web Services
    Infrastructure as à is Code
    with AWS CDK
    Donnie Prakoso
    Quick Start @donnieprakoso
    donnieprakoso
    go.donnie.id/youtube
    donnieprakoso

    View full-size slide

  2. © 2022, Amazon Web Services, Inc. or its affiliates. All rights reserved.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Donnie Prakoso, MSc
    Senior Developer Advocate, ASEAN
    • 17+ years in software development and system operations
    • Banking industry, telco to startups
    • From software developer to R&D manager to CTO
    • I talk a lot about microservices and machine learning
    • Self-proclaimed Barista and Café Racer enthusiasts
    donnieprakoso
    go.donnie.id/youtube
    @donnieprakoso
    donnieprakoso

    View full-size slide

  3. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    DEMO

    View full-size slide

  4. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Manual
    Scripted
    Declarative
    Wikis, Playbooks
    #!/bin/bash
    CloudFormation, Terraform

    View full-size slide

  5. © 2022, Amazon Web Services, Inc. or its Affiliates.
    • Single source of truth to deploy the whole stack
    • Infrastructure that you can replicate, re-deploy,
    and re-purpose
    • Control versioning on your infrastructure and
    your application together
    • Service rolls back to the last good state on
    failures
    • Build your infrastructure and run it through your
    CI/CD pipeline
    Template
    Stack Stack Stack
    Dev
    Test
    Staging
    Prod
    Demos
    Regions
    Infrastructure as code

    View full-size slide

  6. © 2022, Amazon Web Services, Inc. or its Affiliates.
    • JSON/YAML format template
    • Presents template to AWS CloudFormation
    • AWS CloudFormation translates it to an API request
    • Forms a stack of resources
    • FREE – you only pay for resources
    • All regions
    • APIs are called in parallel
    • Manages dependencies/relationships
    Code in YAML or JSON
    directly or use sample
    templates
    Upload local files or
    from an S3 bucket
    Create stack
    using API via AWS
    CloudFormation
    Stacks and resources are
    provisioned as a running
    environment
    Infrastructure as code

    View full-size slide

  7. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Manual
    Scripted
    Generators
    Abstractions
    Declarative
    Wikis, Playbooks
    #!/bin/bash
    CloudFormation, Terraform
    Troposphere, GoFormation
    AWS CDK, Pulumi

    View full-size slide

  8. © 2022, Amazon Web Services, Inc. or its Affiliates.
    Infrastructure is code
    (in your favorite programming language)
    with the AWS CDK

    View full-size slide

  9. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    AWS Cloud Development Kit
    Your language
    Just classes and methods
    AutoComplete
    Inline documentation
    Sane defaults
    Reusable classes
    DEV PREVIEW

    View full-size slide

  10. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    CDK Example

    View full-size slide

  11. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Main Components
    Core Framework AWS Construct Library AWS CDK CLI
    App
    Stacks
    Resources
    Serverless App Integration / Foundational Services
    Containers CI/CD

    View full-size slide

  12. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Development Workflow
    CDK CLI AWS CloudFormation
    Stacks & Constructs
    Source Code
    Templates + Assets
    Cloud Assembly
    Cloud Resources
    execute synthesize deploy provision
    📙 cdk init // create new project
    🛠 cdk watch // watch changes
    🔎 cdk diff // check what will change
    🧬 cdk synth // create templates and assets
    🚀 cdk deploy // push changes to the cloud

    View full-size slide

  13. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Demo Use Case: Implementing Serverless API

    View full-size slide

  14. © 2022, Amazon Web Services, Inc. or its Affiliates.
    CDK Constructs

    View full-size slide

  15. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    AWS Construct Library
    Serverless Application Integration / Foundational Services
    Containers CI/CD

    View full-size slide

  16. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Construct Levels
    CloudFormation Resources
    L1 Automatically generated
    Purpose-built constructs
    L3+ Opinionated abstractions
    AWS Constructs
    L2 High level service constructs

    View full-size slide

  17. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    L1
    • Generated mappings from CloudFormation Specification
    • abc.CfnXyz → AWS::ABC::XYZ CloudFormation Resource
    • ec2.CfnInstance → AWS::EC2::Instance
    • kms.CfnKey → AWS::KMS::Key
    🧬 cdk synth

    View full-size slide

  18. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    L2

    View full-size slide

  19. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    “amazon-ecs-sample”
    image
    AWS VPC
    • Subnets
    • EIP
    • NAT Gateways
    • Internet Gateway
    • Route
    • Route Table
    Elastic Load Balancer
    • Security Group
    • Security Group Egress
    • Security Group Ingress
    • Task Definition
    • Listener
    • Target Group
    • IAM Roles
    • IAM Policies
    • Log Group
    • Configuration
    Fargate Service
    ECS Task Definition
    • image
    • CPU
    • memory
    • port
    829 line
    CloudFormation
    template
    L3

    View full-size slide

  20. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Demo Use Case: Dev/Prod Parity
    AWS
    CloudFormation
    CDK App
    Source Code
    Stack A
    Template A
    Template B
    AWS
    CloudFormation
    Stack B
    Parameterized
    Template
    Stack 1
    Stack 2
    CloudFormation
    Parameters and
    intrinsic functions
    CDK
    Typed OO language:
    loops, conditions,
    inheritence, etc

    View full-size slide

  21. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Demo Use Case: Terraform Support

    View full-size slide

  22. © 2022, Amazon Web Services, Inc. or its Affiliates.
    @donnieprakoso donnieprakoso go.donnie.id/youtube donnieprakoso
    Demo Use Case: CI/CD using CDK Pipelines
    Region
    Cloud
    Git push
    AWS
    CodeCommit
    AWS
    CodePipeline
    AWS
    CodeBuild
    AWS
    CloudFormation
    Test stack
    Change set
    Staging
    Production

    View full-size slide

  23. © 2022, Amazon Web Services, Inc. or its Affiliates.
    https://go.donnie.id/content
    Donnie Prakoso @donnieprakoso donnieprakoso
    Sr. Developer Advocate, ASEAN
    Amazon Web Services go.donnie.id/youtube donnieprakoso
    Content Title: “Infrastructure as à is Code with AWS CDK”

    View full-size slide