Image for post
Image for post
AWS CDK

This is a very short, un-paywalled survivorship guide to using the AWS CDK with TypeScript and node ESM.

TL;DR: ts-node fails when there are ES modules in the dependency graph (not specific to CDK but you need it to run cdk synth).

If you are using ESM you should already have "type": "module" in your package.json

If you’ve used the CLI to add the CDK to a TypeScript project you will get a generated file cdk.ts that looks something like this

If you run cdk synth you are likely to get the following error

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension…


Refactoring JavaScript: Collection Pipelines

Image for post
Image for post
Photo by Jonathan Fox on Unsplash

I recently started writing about refactoring JavaScript to use Collection Pipelines instead of loops. I make a pretty bold claim that this will lead to cleaner code, what I haven’t done yet is make a clear argument for why I think this leads to cleaner code.

To me, there is something truly satisfying in taking a collection of arbitrary objects, piping it through a series of individual transformations and filters and getting a new collection out the other side. Seeing a workflow broken down into discrete, often single-line steps, with no side effects is great way to write code.

Functional Building Blocks

map()


An introduction to the unknown type: a better any

Image for post
Image for post
Photo by Nicolas Lobos on Unsplash.

TypeScript code around the world is littered with the any type, and it drives me absolutely crazy. There is no (valid) reason to use it in application code, and you are opting out of the safety of a static type system.

Many developers who are new (or not so new to TypeScript) assume that when you don’t know what type you are going to get, you should type it with any. TypeScript’s official documentation also tells you that this is not the case:

“Don’t use any as a type unless you are in the process of migrating a JavaScript project…


Refactoring JavaScript: Collection Pipelines (Example)

Image for post
Image for post

This is part of a series called “Refactoring Javascript: Collection Pipelines.” You can read the introduction here.

In a previous article, I gave an introduction to the power of reduce(), however, I didn’t really highlight it’s potential with a real world example.

In this article we will solve the Canva technical challenge using a single reduce function.

Note: In the event that Canva is still using this question to screen candidates, be aware that they use HackerRank to check for plagiarism, don’t try to submit this answer.

The Challenge

The task is to write an algorithm that takes two parameters. The first…


Refactoring JavaScript: Collection Pipelines (Part 2)

Image for post
Image for post

This is part of a series called “Refactoring Javascript: Collection Pipelines.” You can read the introduction here.

In a previous article, I showed how simple collection pipelines can simplify the readability of your code with an example of IP validation.

const validateIP = (ip: string): boolean => {
const numbers = ip.split('.');
return numbers.length === 4
&& numbers
.filter((x) => Number(x).toString() === x)
.map((x) => parseInt(x, 10))
.filter((x) => x >= 0 && x <= 255)
.length === 4;
};

This code is nice because it breaks each step of the validation down into a single step. Each step pipes…


Image for post
Image for post
Refactoring Javascript: Collection Pipelines

This is the first post in a series of posts about refactoring your Javascript code to use map, filter and reduce instead of loops. I refer to this style of programming as Collection Pipelines as I was first introduced to this concept in Martin Fowler’s Refactoring.

One of the first control structures we learn as programmers is loops. …


Image for post
Image for post
Gitlab CI/CD pipelines

Serverless framework is an amazing tool and I’m very bullish on the future of serverless development. For all the amazing content out there for serverless, there isn’t a lot on how to build CI/CD pipelines for serverless projects — so here we go.

In this tutorial, we are going to use Gitlab pipelines because I’m a huge fan of Gitlab. The same template can be used to guide pipelines with Bitbucket, Azure, or any other provider. I’m going to assume next to no knowledge about setting up CI/CD so hopefully anyone can follow along. …


Image for post
Image for post

At some point in your serverless journey you’ll no doubt utilise DynamoDB. You’ll also probably want to be able to write integration tests against it. In this post we’ll go through the basics of getting an offline environment set up for testing, in a future post i’ll walk you through the couple of lines of code that needs to change if you want to utilise DynamoBBStreams (seperate post for SEO and maximum help for anyone debugging the issue).

Configuring serverless-dynamodb-local

We’ll begin by building on top of the serverless template I wrote about previously which can be found on github here. Whether…


Image for post
Image for post

Whether you use AWS across your organisation or for personal projects, it is useful to set up multiple accounts on AWS to seperate your staging/test and production environments. It is especially useful if you are building serverless applications as many of the tools you will use (e.g. Lambda) have soft limits on concurrent usage at the account level.

Apart from getting around usage limits, separating your development and production accounts allows you to experiment in a real cloud environment without negatively impacting your production environment.

The naive way of doing this involves constantly logging out and back in each time…


Image for post
Image for post
AWS IAM

If you are building a project with AWS serverless using SAM or serverless framework , you’ll need to be regularly deploying your code from your local machine and CI/CD pipelines. Both of these frameworks use AWS CloudFormation under the hood to provision and deploy resource stacks. In order for these frameworks to provision your infrastructure for you, you will need to give them permission to do so.

NOTE: This article assumes you already have the AWS CLI installed and configured. You will need to set that up first. Instructions can be found here.

Firstly log into your AWS console and…

Michael Timbs

Full-stack developer. In love with Typescript and Serverless

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store