Course Objectives: | Understand what is CDK and what are the advantages of using it Understand the basic concepts in CDK (Contsructs, Apps, and Stacks) Understand the development environment of CDK (basic CDK commands, TypeScript) Build basic HTTP Service using CDK |
Estimated Time: | 60 minutes |
Target Audience: | Software Developers |
The AWS CDK is a new software development framework from AWS with the sole purpose of making it fun and easy to define cloud infrastructure in your favorite programming language and deploy it using AWS CloudFormation.
Let’s look at a small but complete example for a Fargate Cluster.
import ec2 = require('@aws-cdk/aws-ec2');
import ecs = require('@aws-cdk/aws-ecs');
import ecs_patterns = require('@aws-cdk/aws-ecs-patterns');
import cdk = require('@aws-cdk/core');
// A Stack
class HelloFargate extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// VPC Construct
const vpc = new ec2.Vpc(this, 'MyVpc', { maxAzs: 2 });
// Cluster Construct
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
// Load Balanced Fargate Construct
const fargateService = new ecs_patterns.LoadBalancedFargateService(this, "FargateService", {
cluster,
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
});
// Output the DNS where you can access your service
new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: fargateService.loadBalancer.loadBalancerDnsName });
}
}
//An App
const app = new cdk.App();
new HelloFargate(app, 'Hello');