Reader small image

You're reading from  AWS CDK in Practice

Product typeBook
Published inJun 2023
PublisherPackt
ISBN-139781801812399
Edition1st Edition
Right arrow
Authors (2):
Mark Avdi
Mark Avdi
author image
Mark Avdi

Mark Avdi is an Engineer, Solutions Architect and currently the CTO of Westpoint Software Solutions. He has gained his invaluable experience through decades of coding programs, designing software, and managing complex cloud infrastructures in multiple industries with different sets of challenges using a variety of solutions. Mark is a technologist; he keeps up with the trends and believes in the power of technology as an ultimate tool to help businesses prosper and tackle problems our world currently faces.
Read more about Mark Avdi

Leo Lam
Leo Lam
author image
Leo Lam

Leo Lam is an AWS Certified Solutions Architect and the COO of Westpoint Software Solutions. While having detailed knowledge of the vast array of services AWS currently provides, he maintains the close relationship between AWS & Westpoint as partners. Leo comes from a sporting background and uses his experience to effectively integrate the dynamics of sporting philosophy into day-to-day software development to build teams and workflows that constantly deliver.
Read more about Leo Lam

View More author details
Right arrow

Understanding the inner workings of AWS CDK

We hope that was fun. In the previous section, we mentioned AWS CloudFormation and how CDK outputs a CloudFormation template and then manages its life cycle.

According to AWS, CloudFormation is an IaC service (again, I’d argue with the code bit) that you can use to model, provision, and manage AWS services. In short, it’s a YAML or JSON file with an AWS service definition of its properties and relationships.

Learning CloudFormation is outside the scope of this book, but it’s useful for you to understand and read about it, to better debug your CDK applications. Let’s take a brief look at a CloudFormation excerpt sample YAML configuration.

Here is how you set up a basic EC2 instance and open up the 22 port for SSH access. Reading YAML is straightforward, and if you look closely, you will be able to read the various components our CloudFormation configuration defines:

Parameters:
  KeyName:
    Description: The EC2 Key Pair to allow SSH access to the instance
    Type: 'AWS::EC2::KeyPair::KeyName'
Resources:
  Ec2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      SecurityGroups:
        - !Ref InstanceSecurityGroup
        - MyExistingSecurityGroup
      KeyName: !Ref KeyName
      ImageId: ami-7a11e213
  InstanceSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: Enable SSH access via port 22
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0

Well, CDK uses the same underlying mechanism. Working with AWS CloudFormation directly can be very daunting and complicated, even for relatively simple stacks. To prove this point, go to this chapter’s CDK app root and run the following command:

$ cdk synth

You guessed it right—this gigantic abomination of a YAML output is the result of about 20 lines of CDK TypeScript code. CDK essentially compiles your code into a CloudFormation stack and manages the rest of the complexity of adding and removing various bits, linking resources together, and a ton of other things for you.

The amount of time that developers save is undeniably massive. The amount of confusion, mistakes, and painful trials and errors of CloudFormation or any other configuration-defined IaC tool that CDK eliminates makes CDK and the new set of similar tools such as Pulumi clear winners of the IaC race. Businesses that onboard CDK into their development practices will be able to deliver a lot more in a shorter amount of time.

Developers with CDK skills will be highly sought after. Welcome aboard—this is the future of software development on the cloud!

Previous PageNext Page
You have been reading a chapter from
AWS CDK in Practice
Published in: Jun 2023Publisher: PacktISBN-13: 9781801812399
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Mark Avdi

Mark Avdi is an Engineer, Solutions Architect and currently the CTO of Westpoint Software Solutions. He has gained his invaluable experience through decades of coding programs, designing software, and managing complex cloud infrastructures in multiple industries with different sets of challenges using a variety of solutions. Mark is a technologist; he keeps up with the trends and believes in the power of technology as an ultimate tool to help businesses prosper and tackle problems our world currently faces.
Read more about Mark Avdi

author image
Leo Lam

Leo Lam is an AWS Certified Solutions Architect and the COO of Westpoint Software Solutions. While having detailed knowledge of the vast array of services AWS currently provides, he maintains the close relationship between AWS & Westpoint as partners. Leo comes from a sporting background and uses his experience to effectively integrate the dynamics of sporting philosophy into day-to-day software development to build teams and workflows that constantly deliver.
Read more about Leo Lam