simalexan
Until you reach AWS
CloudFormation
Did I miss some
space here?!
Max 200
resources??
Ack, this is
ugly!
Slide 13
Slide 13 text
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…
Slide 14
Slide 14 text
simalexan
“Two birds - one stone”
Building serverless apps
with AWS CDK
Aleksandar Simović
Slide 15
Slide 15 text
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.
Slide 16
Slide 16 text
simalexan
The “agenda”
• Infrastructure Management Journey
• AWS CDK
• Short Demo
• More examples
Slide 17
Slide 17 text
simalexan
In the beginning
there was a console
Slide 18
Slide 18 text
simalexan
Console
• Easy to get started
• Not reproducible
• Error prone
• Time Consuming
Slide 19
Slide 19 text
simalexan
Scripted Resources
(pre 2010)
Slide 20
Slide 20 text
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?
simalexan
Resource Provisioning
Engines
• Easy to automate
• Reproducible
• Good Rollbacks and Updates
• Awful syntax
• No abstraction, lots of details
Slide 24
Slide 24 text
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
simalexan
Document Object Models
(DOMs)
• Real code
• Desired state (builds upon CloudFormation)
• Abstractions are not built-in
Slide 27
Slide 27 text
simalexan
AWS CDK
(Cloud Development Kit)
Software Development Framework
Cloud Infrastructure and Applications
Slide 28
Slide 28 text
simalexan
Slide 29
Slide 29 text
simalexan
Slide 30
Slide 30 text
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
Slide 31
Slide 31 text
simalexan
Language support
• TypeScript
• Python
• Java
• C#
Slide 32
Slide 32 text
simalexan
How does it look like
Slide 33
Slide 33 text
simalexan
What would you write?
Slide 34
Slide 34 text
simalexan
Slide 35
Slide 35 text
simalexan
How do you start
• npm install -g [email protected]
• A configured AWS account + AWS CLI
Slide 36
Slide 36 text
simalexan
Demo
• CDK CLI workflow
• Demonstrate the workflow
simalexan
cdk build
• Simply compiles the TypeScript files to javascript
• A watch is available too
Slide 39
Slide 39 text
simalexan
cdk synth
• Synthesizes a template from your CDK app.
• A traditional CloudFormation template
• Adds AWS::CDK::Metadata to every stack.
Slide 40
Slide 40 text
simalexan
cdk diff
Slide 41
Slide 41 text
simalexan
cdk deploy
Slide 42
Slide 42 text
simalexan
cdk destroy
Slide 43
Slide 43 text
simalexan
testing?
• Standard testing for your codebase
• cdk synth
(you can test the CF output)
• programmable infrastructure tests
Slide 44
Slide 44 text
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
Slide 45
Slide 45 text
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
Slide 46
Slide 46 text
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
Slide 47
Slide 47 text
simalexan
Slide 48
Slide 48 text
simalexan
Questions?
@simalexan serverless.pub
Twitter Blog
“Serverless Applications
with Node.js"
claudia40
40% off
Thank you