AWS CDK Developer Preview
We are thrilled to announce the AWS Cloud Development Kit (CDK) Developer Preview release for TypeScript, JavaScript, and Java; with .NET, and Python coming soon. The AWS CDK is a software development framework to define cloud infrastructure as code and provision it through CloudFormation. The CDK integrates fully with AWS services and offers a higher-level object-oriented abstraction to define AWS resources imperatively. The CDK improves your end-to-end development experience because you get to use the power of modern programming languages to define your AWS infrastructure in a predictable and efficient manner.
You can think of the CDK as a cloud infrastructure “compiler”. It provides a set of high-level class libraries, called Constructs, that abstract AWS cloud resources and encapsulate AWS best practices. Constructs can be snapped together into object-oriented CDK applications that precisely define your application infrastructure and take care of all the complex boilerplate logic. When you run your CDK application, it is compiled into a CloudFormation Template,
Familiar Tools
With the CDK, we want to meet you where you are the most comfortable and productive by bringing infrastructure definitions into the familiar environments and team workflows you use every day. Because the CDK supports your favorite object-oriented programming languages, you can naturally express code logic, like loops and conditions, to customize your infrastructure for any environment or scenario. Since CDK code is just code, existing IDE functionality such as inline documentation, refactoring tools, code navigation, and unit testing all work as expected. The following code demonstrates the use of infrastructure logic and environmental context, such as availability zones and region-specific AMI IDs, to create different application stacks for different regions from a single code base. No infrastructure definition copy-and-paste required.
// get the list of AZs for the current region/account
const azs = new cdk.AvailabilityZoneProvider(this).availabilityZones;
// get the AMI ID for a specific Windows version in this region
const ami = new ec2.WindowsImage(ec2.WindowsVersion.WindowsServer2016EnglishNanoBase).getImage(this);
for (const az of azs) {
// render construct name based on it’s availability zone
const constructName = `InstanceFor${az.replace(/-/g, ”).toUpperCase()}`;
new ec2.cloudformation.InstanceResource(this, constructName, {
imageId: ami.imageId,
availabilityZone: az,
});
}
Abstract the Details
The CDK is not the first solution that allows developers to use modern programming languages and object-oriented techniques to generate CloudFormation Templates. What sets the CDK apart is that it fully integrates with AWS services to provide useful APIs that automatically synthesize key resources such as IAM policies, security groups, and network configuration. For instance, to add an Amazon Virtual Private Cloud (VPC) to your infrastructure, you simply add the following line of code to your CDK application.
new ec2.VpcNetwork(this, ‘MyVPC’);
When the CDK application is compiled, a lengthy CloudFormation Template is generated that defines a subnet for each availability zone in the targeted region, as well as the Routes, Route Tables, Subnet Route Table Associations, NAT Gateways, Internet Gateway, and Elastic IPs required to make it all work. If any of our smart defaults don’t meet your requirements, you can easily override the VPC parameters with values of your own.
Extensible
In addition to leveraging the useful APIs provided by AWS authored CDK Constructs, you can define your own best practices in predictable, reusable code. For example, you can author a CDK application that always creates S3 buckets with encryption enabled so your teams do this naturally by default.
new s3.Bucket(this, ‘EncryptedBucket’, {
encryption: s3.BucketEncryption.KmsManaged
});
You can define even higher level CDK applications that encode opinionated, cloud-native design patterns, focused on specific use cases, and share them internally or with the whole world. We can’t wait to see the cool stuff you build.
Visit the Bazaar
We are building the CDK like an open bazaar, not a closed cathedral, and we’re not done yet! For those unfamiliar with the reference, The Cathedral and the Bazaar, is an essay by Eric S. Raymond that contrasts two fundamental software development styles, and makes the argument that, in open-source, “Given enough eyeballs, all bugs are shallow”. This is an open-source developer preview and we need your help to make the CDK the best end-to-end experience for developing cloud applications on AWS. Visit the aws-cdk GitHub README to learn how to get started and then take the CDK out for a spin. Post on Gitter to start a conversation, open an issue to haggle with developers, file a pull request to contribute your wares, or star the project just to show us you care. We look forward to collaborating with you.