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

“Two birds - one stone” - Building serverless a...

“Two birds - one stone” - Building serverless apps with AWS CDK

Avatar for Aleksandar Simovic

Aleksandar Simovic

June 20, 2019
Tweet

More Decks by Aleksandar Simovic

Other Decks in Programming

Transcript

  1. simalexan Until you reach AWS CloudFormation Did I miss some

    space here?! Max 200 resources?? Ack, this is ugly!
  2. simalexan You said it was easy, now I have to

    write ugly YAML… CloudFormation? There’s a better way… I’ve Wasted hours finding the docs…
  3. simalexan Aleksandar Simović • Senior software engineer / Lead serverless

    engineer
 at ScienceExchange • Coauthor of the “Serverless Applications with Node.js” book • AWS Serverless Hero • AWS SAM / AWS SAM Lambda builders / AWS CDK • Almost 30 serverless apps on 
 AWS Serverless Application Repository • Saved more than $100k at ScienceExchange by implementing several
 serverless solutions.
  4. simalexan Scripted Resources
 (pre 2010) • What if an API

    call fails? • How to make updates? • How do you know if a resource is ready? • How to roll back?
  5. simalexan Resource Provisioning Engines • AWS CloudFormation • Terraform
 Using

    declarative configuration • AWS CloudFormation template (JSON/YAML) • HashiCorp Configuration Language (HCL)
  6. simalexan Resource Provisioning Engines • Easy to automate • Reproducible

    • Good Rollbacks and Updates • Awful syntax • No abstraction, lots of details
  7. simalexan Resource Provisioning Engines • Feels like a shopping list

    / no programming at all • Fair abstractions using Nested Stacks • YAML formatting issues (cfn-lint) • Documentation only online
  8. simalexan Document Object Models (DOMs) • Real code • Desired

    state (builds upon CloudFormation) • Abstractions are not built-in
  9. simalexan Componentized • Application = multiple stacks • Stack =

    multiple constructs • Construct can have multiple levels:
 - can be a component 
 (API GW + Lambda + upload S3 bucket)
 
 - can be a single piece
 (a Lambda) • You write constructs as components
  10. simalexan cdk init • npm install -g aws-cdk • mkdir

    hello-serverless-banjaluka • cdk init app —-language=typescript
 • Setups the project, lib, bin, cdk.json, tsconfig.json
  11. simalexan cdk build • Simply compiles the TypeScript files to

    javascript • A watch is available too
  12. simalexan cdk synth • Synthesizes a template from your CDK

    app. • A traditional CloudFormation template • Adds AWS::CDK::Metadata to every stack.
  13. simalexan testing? • Standard testing for your codebase • cdk

    synth 
 (you can test the CF output) • programmable infrastructure tests
  14. simalexan stages? • Standard environment setup with your services •

    Different AWS accounts, belonging to an an organization • You can setup a CI/CD pipeline with AWS CDK
  15. simalexan Next steps • Try out the CDK • https://cdkworkshop.com

    • https://awslabs.github.io/aws-cdk
 The repository is constantly evolving • https://github/awslabs/aws-cdk
  16. simalexan Examples
 https://github.com/aws-samples/aws-cdk-examples A few serverless ones: • api-cors-lambda-crud-dynamodb •

    appsync-graphql-dynamodb • static-site • fargate-service-with-auto-scaling • … many more