import { Appear, Image, Notes, Split } from "mdx-deck"; import { CodeSurfer, CodeSurferColumns, Step, } from "code-surfer"; import { github, vsDark } from "@code-surfer/themes";
export const theme = { ...github, styles: { inlineCode: { bg: 'primary' } }, } ;
<title>A gentle introduction to AWS CDK</title>CDK = Cloud Development Kit
Cloud Infrastructure Management
import launch_instance_wizard from "./images/launch_instance_wizard.png";
No one should be forced
to performrecurring tasks
that are easy toautomate
.
Human Rights (maybe some day)
import scriptDiagram from "./images/script_diag.png";
- ✅ automated
- ❌ what vs HOW
- ❌ Changes are hard
- ❌ Lots of boilerplate code
😒
import cfDiagram from "./images/cf_diag.png";
AWSTemplateFormatVersion: "2010-09-09"
Resources:
FrontendAutoScale:
Type: 'AWS::AutoScaling::AutoScalingGroup'
DependsOn:
- StorageAutoScale
Properties:
VPCZoneIdentifier: !Ref Subnets
DesiredCapacity: !Ref FrontendServers
HealthCheckType: 'ELB'
HealthCheckGracePeriod: '1200'
LaunchConfigurationName: !Ref FrontendLaunchConfig
LoadBalancerNames:
- !Ref FrontendLoadBalancer
- !Ref PagesLoadBalancer
MaxSize: '20'
MinSize: !Ref FrontendServers
TerminationPolicies:
- OldestInstance
{% macro tags(propagate_at_launch=False) %}
{%- set _tags = {
'Name': '!Ref AWS::StackName',
'ouid': '!Ref TagOuid',
'team': '!Ref TagTeam',
'email': '!Ref TagEmail',
'app': '!Ref TagApp',
'env': '!Ref TagEnv',
'uptime': '!Ref TagUptime'
}
%}
Tags:
{%- for t in _tags|dictsort %}
- Key: {{ t[0] }}
Value: {{ t[1] }}
{%- if propagate_at_launch %}
PropagateAtLaunch: true
{%- endif %}
{%- endfor %}
{%- endmacro %}
AWSTemplateFormatVersion: "2010-09-09"
Resources:
FrontendAutoScale:
Type: 'AWS::AutoScaling::AutoScalingGroup'
DependsOn:
- StorageAutoScale
Properties:
VPCZoneIdentifier: !Ref Subnets
DesiredCapacity: !Ref FrontendServers
HealthCheckType: 'ELB'
HealthCheckGracePeriod: '1200'
LaunchConfigurationName: !Ref FrontendLaunchConfig
LoadBalancerNames:
- !Ref FrontendLoadBalancer
- !Ref PagesLoadBalancer
MaxSize: '20'
MinSize: !Ref FrontendServers
TerminationPolicies:
- OldestInstance
{{- macros.tags(propagate_at_launch=True) }}
- ✅ automated
- ✅ WHAT vs how
- ✅ Changes are easy
- ❌ Verbose (1 to 1 relationship)
- ❌ Limited logic
🤨
import cdkDiagram from "./images/cdk_diag.png";
<CodeSurferColumns themes={[vsDark, github]}>
import { Construct, Stack, StackProps } from "@aws-cdk/core";
import * as s3 from "@aws-cdk/aws-s3";
export class S3Stack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const bucket = new s3.Bucket(this, "WebsiteBucket");
}
}
Resources:
WebsiteBucket75C24D94:
Type: AWS::S3::Bucket
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Metadata:
aws:cdk:path: MyFirstStack/WebsiteBucket/Resource
import { Construct, Stack, StackProps } from "@aws-cdk/core";
import * as s3 from "@aws-cdk/aws-s3";
export class S3Stack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new Bucket(this, "WebsiteBucket", {
encryption: s3.BucketEncryption.S3_MANAGED,
});
}
}
Resources:
WebsiteBucket75C24D94:
Type: AWS::S3::Bucket
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Metadata:
aws:cdk:path: MyFirstStack/WebsiteBucket/Resource
- ✅ automated
- ✅ WHAT vs how
- ✅ Changes are easy
- ✅ Concise
- ✅ Real programming
🤓