AWS Cloud Development Kit (CDK) is an infrastructure as code (IaC) tool that allows users to define resource stacks using popular programming languages and then deploy those stacks using AWS CloudFormation. CDK is a command line interface (cli) tool that can be downloaded to a user’s development machine or CI/CD systems. The cdk cli tool provides functionality to create new projects, check differences between the deployed stack and the local configuration, synthesize the cdk code into CloudFormation script, and deploy directly from the machine running the tool. CDK is a purpose-built tool built on top of AWS cloudformation to provide enhanced functionality than native CloudFormation. Using fully featured programming languages allows users to create complex logic and conditions that can sometimes be required when creating resource stacks. At runtime, CDK can look up and resolve dynamic values that should not or could not be statically defined.
Basic Concepts
- Constructs
- Constructs are the building block of CDK.
- Constructs can range from single resources provided by AWS to complicated custom collections of resources created to work together.
- The constructs created by AWS are defined in the AWS Construct Library.
- There are 3 levels of constructs
- L1
- Low-level construct with a 1-to-1 mapping to the corresponding CloudFormation resource
- L1 resource names start with Cfn
- L2
- Higher-level construct that allows for resource creation with enhanced functionality
- Assists with resource creation by providing defaults and boilerplates
- L3
- High-level construct that allows for common tasks that require multiple resources to be easily completed
- For more information about constructs, check out the docs https://docs.aws.amazon.com/cdk/v2/guide/constructs.html
- Stacks
- Deployable collection of resources
- CDK stacks get synthesized into CloudFormation stacks using the cdk synth command
- Stacks can be nested using the NestedStack construct
- For more information about stacks, check out the docs https://docs.aws.amazon.com/cdk/v2/guide/stacks.html
- App
- Container for one or many stacks
- Stacks inside of the same app can reference resources in one another
- Stacks can be deployed individually within an app. This is helpful when defining multiple environments
- For more information about the app, check out the docs https://docs.aws.amazon.com/cdk/v2/guide/apps.html
- Environments
- Environments specify the AWS account and region that a stack should be associated to
- Environments are not required for stacks; however, if it’s not explicitly provided, then a stack is considered environment-agnostic
- For more information about environments, check out the docs https://docs.aws.amazon.com/cdk/v2/guide/environments.html
- Bootstrapping
- Bootstrapping is the process of configuring an account and region to use CDK
- Bootstrapping must be run the first time that that CDK is used in an account and environment; however, subsequent cdk runs do not need to bootstrap
- Bootstrapping is account and region-specific, so it must be run in all regions in a particular account you wish to use CDK with
- CDK creates a CloudFormation script in the specific region to deploy the CDKToolkit
- For more information about bootstrapping, check out the docs https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html
Commands
There are many commands available using the cdk cli tool. To use the cdk tool you must first install it on your machine. Additionally, you will need an AWS account, the aws cli and a profile already set up on the local machine. For information about the aws cli please see the aws cli documentation https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html. For information about how to install the cdk cli tool and additional information about the following commands, see the cdk documentation https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html.
-
list - Lists the stacks in the App
cdk list --profile <profileName>
-
synth - Synthesizes cdk code into CloudFormation scripts in the cdk.out folder
cdk synth <stackName> --profile <profileName>
-
bootstrap - Bootstraps an account and region by using cloudformation to deploy the CDKToolkit
cdk bootstrap --profile <profileName>
-
deploy - Synthesizes and deploys cdk stacks to AWS
cdk deploy <stackName> --profile <profileName>
-
destroy - Destroys the specified cdk stack
cdk destroy <stackName> --profile <profileName>
-
diff - Checks the state of the current configuration against the configuration hosted in the account
cdk diff <stackName> --profile <profileName>
-
init - Initializes a new cdk app
cdk init --language <languageName> --profile <profileName>
CDK is a powerful tool with a lot more features than have been covered in this post. I highly recommend you read through the docs and work through some examples to get hands-on with CDK. The CDK workshop provides some great examples to get you hands-on with CDK (https://cdkworkshop.com/).
CDK is a great option for DevOps engineers who would need more functionality out of their IaC tooling and developers who would feel more comfortable keeping their IaC stacks closer to their code. IaC is extremely important for running applications in the cloud, and AWS CDK is a great option to have in your tech stack.
Have you ever wanted to share your knowledge or passion with the world? We all have things we are interested in, good, and want to share with the world. We tell our friends, families, and coworkers about these passions, but sometimes we want to reach a bigger audience. A blog is a great way to do that. Blogs can be about anything; it could be about work projects or skills, cooking, or your last knitting project. The point is that you have something to share with the world, and a blog can help you to reach that larger audience.
Like anything new, starting a blog can be tough. It’s hard to know how to get started. At a high level, there are a couple of things to consider when starting a blog, how you want to host it and where you want to host it. Let’s first start with how you want to host it. There are many options for creating a blog. Typically, they fall into the category of an off-the-shelf application such as WordPress, a static-generated site, or a custom site.
How to Host
Applications such as WordPress can be great options for hosting a blog or other types of sites. WordPress is one of if not the most popular website platforms on the market today. It’s easy to use, has many third-party plugins, and has a strong support community. While WordPress is a strong option, it also comes with some trade-offs. WordPress uses PHP and server-side code to host your website, which means it must be run on a server. Since the site needs to run on a server, there is typically a cost to host the site. Often the cost to host a WordPress site is minimal for smaller sites, but the costs can quickly add up after adding redundancy to the site and extra plugins. The site running on a server also means that it needs to have security patching and maintenance performed on it to ensure the safety of your site. If the WordPress blog is hosted on a platform that manages your site for you, it will typically contribute to your overall cost. Finally, solutions such as WordPress typically offer many features that are overkill for a simple blog. Most blogs don’t need advanced features and, therefore, can make using these tools more complicated for users.
Static site generators are a great option for hosting a simple blog. They are frameworks created using popular programming languages such as Ruby, Javascript, and Go. These frameworks allow users to create content by writing posts in markdown and then generate all of the code required to create the blog. Since there is no server-side code, these sites can be hosted on platforms such as AWS for a very low cost, if not free. Many of these frameworks also have templates that can be used for the site layout and aesthetics. An additional benefit of static sites is the reduced overhead. Since servers are not required to run the sites, you don’t have to worry about patching and maintenance on servers. One of my personal favorite static site generators is Jeykll. It’s an easy-to-use framework written in Ruby. It has many great, free templates available for users, and it has a large community that can help address any issues or questions.
A custom site could also be an option for individuals with the skill and desire to create their site. WordPress and static site generators do not require development skills from users. Users can choose from tons of different templates. The benefit of creating a custom site is that it allows you to create the site exactly the way you want it. It’s a good option if you have the required skills, but for someone like myself who does not come from a front-end development background, the learning curve is more than I’d want to take on for a simple blog.
Where to Host
Now that you understand how to host your blog better, it’s important to understand where to host it. There are a lot of companies on the market today that host websites. WordPress.com, Squarespace, and Wix are well-known options for off-the-shelf applications. They offer a variety of different options and pricing to choose from. If you would like to use an off-the-shelf solution such as WordPress and don’t want to have to manage the underlying resources yourself, then you should consider one of these providers.
If you would rather host your site yourself, or a static or custom site, then other platforms should be considered. For static sites, platforms such as Netlify can be good options. Netlify and other similar platforms offer entry-level starter tiers for free for users to get their blogs published globally. These platforms require very little to no knowledge of the underlying infrastructure required to host your site, and you can get your site up and running quickly.
Platforms like Netlify can be great for getting started but are very limited in what they offer. To expand your options, you should consider using a cloud platform such as AWS. AWS is a great option for hosting any of the discussed types of blogs. You can host off-the-shelf solutions along with static and custom sites. Using AWS gives you access to a wide array of services for not just your blog but any other applications you may want to use in the future. AWS always only charges for the resources you use, so hosting a static blog globally can be done for a very low cost, if not free.
There is a wide array of options to choose from when hosting a blog. There is not a one size fits all option either. You need to pick the right application and hosting provider to meet your individual needs. Personally, I chose to go with Jeykll and AWS but if WordPress with a managed provider works better for you, then do that. What’s most important at the end of the day is that you are sharing your knowledge and passion with the world.