Categories
AWS CDK

Which Programming Language is the best for AWS CDK?

Controversial question? Well, maybe – however, I will try to find an objective answer for that critical question in the following blog post.

Such questions are sparking heated debates, which are downgrading from a professional dialogue to a squabble in an exponential way. Nevertheless, I will try to answer this question objectively and fairly. Let’s do it!

It depends

That will be a consultant way to answer any kind of question. You’re welcome. No, but really – let’s leave the “consulting mindset” aside. Can we objectively evaluate that?

Let’s start with a simple heuristic and observations. My first steps go to the aws-samples/aws-cdk-examples repository on Github where you can see a following distribution of languages:

Interesting distribution, isn’t it?

So it looks like Python has the best set of examples and next is Java, hoSo it looks like Python has the best set of examples, and next is Java. However, there is a trap there, as this language is well-known for its baroquesque and verbose syntax. Disappointed? Well, I said it will be a heuristic – although looking inside directories per language, Python and TypeScript have the broadest possible set of examples.

Next, a few more observations:

  • In the official documentation, we can see equal support for all programming languages that are mentioned in the AWS CDK FAQ.
  • APIs are very similar between languages, but that’s a standard if you will think about it, e.g., in the case of AWS SDK, we have the same story.

Generally, support looks pretty uniform across languages, but in the documentation, you can find this article:

Translating TypeScript AWS CDK code to other languages

TypeScript was the first language supported for developing AWS CDK applications, and for that reason, there is a substantial amount of example CDK code written in TypeScript. If you are developing in another language, it may be useful to compare how AWS CDK code is implemented in TypeScript and your language of choice, so you can, with a little effort, make use of these examples.

Official AWS CDK Documentation

Okay, so if TypeScript was the first one, let’s move it on the top of my list when it comes to the evaluation order.

Side note: I am not treating JavaScript as a separate option, because CDK heavily relies on types, so it does not a lot of make sense to treat it separately as it will be more tedious and error-prone to work with this language.

TypeScript

So here are the following observations regarding this language:

  • (+) Types are definitely a plus and tremendous help.
  • (+) There are dedicated extensions for a rest framework (Jest) with custom assertions.
    • Official guides for testing are covering this language like here.
  • (+) The most comprehensive documentation.
  • (+) One of the broadest set of official examples.
  • (+) The biggest library of the blog posts on the internet.

Python

Now it’s time for a snake. It looks similarly as TypeScript, but I have observed additionally this:

  • (+) It’s the kinda native language for DevOps Engineers, and thanks to that amount of resources on the internet are not smaller than for a TypeScript, and this still grows.
  • (-) Less than ideal support for testing tools.

C#

C# was added in the second batch, and that’s visible, because:

  • (-) It’s supported, but definitely, it is less popular in the community, so there are fewer examples available (both official and unofficial).
  • (-) Less than ideal support in testing tools.
  • (+) You can embrace functional programming via F# because it works really good.

Java

Last but not least – it’s time for our baroquesque language. The situation is pretty similar as with the C#:

  • (-) It’s supported, but definitely, it is less popular in the community, so there are fewer examples available (both official and unofficial).
  • (-) Less than ideal support in testing tools.
  • (+) You can embrace other languages – especially my favorite Kotlin.

Summary

In my opinion, the best choice is TypeScript. It just feels native for CDK, probably because it was a first language for the creators. 😉

Python is really close to this position, but it still has some small inconveniences. The rest of the languages are pretty much a daily uphill battle with documentation and a lack of examples, especially in the beginning.

For me, the choice is between Python and TypeScript, and we need to wait for more examples and better tooling around the rest. I firmly believe that eventually, it will behave as good as AWS SDK for various programming languages.

By Wojciech Gawroński

Principal Cloud Architect at Pattern Match. Infrastructure as Code, DevOps culture and AWS aficionado. Functional Programming wrangler (Erlang/Elixir).

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.