Infrastructure as Code for React Application on AWS Written in TypeScript

Rate this content
Bookmark

We consider what IaC (Infrastructure as Code) is and why we should invest our time/money into it. It’s going to be a workshop-style talk and as the result, the end of it you will have complete infrastructure as code for React application on AWS written in TypeScript

This talk has been presented at React Advanced 2021, check out the latest edition of this React Conference.

FAQ

The presenter is Denys Artyukhovic, a team lead at The Zone.

The main topic of the talk is infrastructure as code, specifically focusing on using Terraform and TypeScript to manage infrastructure.

The Zone is based in London and aims to change how fans engage with sports, offering a truly immersive experience with real-time augmented data for video streams.

The Zone is available in more than 200 countries.

The Zone is supported on smart TVs, tablets, laptops, Xbox, PS5, and other game consoles.

Infrastructure as code is important to avoid the stress and errors associated with manual infrastructure changes, and to ensure scalability and consistency.

The two programming paradigms discussed are imperative, which involves explicit instructions, and declarative, which focuses on describing the desired outcome.

Terraform is an open-source software developed by HashiCorp that supports thousands of different providers and allows infrastructure management with code.

At the end of the talk, Denys provides code samples, a GitHub repository link, and mentions that the talk will be recorded for future reference.

TypeScript is considered a game changer because it allows developers to use a familiar programming language for infrastructure, eliminating the need to learn a new language.

Denis Artyuhovich
Denis Artyuhovich
30 min
22 Oct, 2021

Comments

Sign in or register to post your comment.
Video Summary and Transcription
This Talk covers infrastructure as code using Terraform and CDK. The speaker demonstrates how to build infrastructure for a React application, including an S3 bucket and connecting to a real domain. They also discuss configuring cache behavior, CloudFront, and remote backends. TypeScript is highlighted as a powerful language for infrastructure as code, and the importance of automation and well-documented code for global-scale infrastructures is emphasized.

1. Introduction to Infrastructure as Code

Short description:

We're going to cover infrastructure as code. My team at The Zone is changing how fans engage with sports. We have a wide range of infrastructure. To avoid manual errors and ensure scalability, we need to use infrastructure as code. There are two programming paradigms: imperative and declarative. Terraform, an open source software, supports thousands of providers and allows us to manage infrastructure with code, including TypeScript.

Cool. Yeah, as I said, now we're going to cover infrastructure as code. But before let myself and give you a bit of background why we need it. So what's going on?

Cool. My name is Denys Artyukhovic. I'm team lead at The Zone. Originally, I'm from Belarus, now based in London. And at The Zone, we're changing every aspect how fans are engaging with sports, starting from the content distribution to a truly immersive experience when in real time you can see augmented data for the video streams. We are available on more than 200 countries, and various types of devices, including smart TVs, tablets, laptops, and of course like Xbox, PS5, and other game consoles. And I think you can imagine how many types of various infrastructure we have. And my team actually built features which are cross-target. They are available on web and on TVs.

So the answer now, probably obvious, but let's consider like normal flow of developing their applications. So we're starting with the one feature, or let's say service, then new, bright, shiny idea comes to the stage and we have one more feature, and then boom, hundreds of them. And in our case, we can expect changes in our infrastructure even multiple times per day, and I think you can imagine how stressing it could be if everything will be manual, because you need to replicate some manual changes, and what if some of the developers forget to update the documentation? Or what if UI itself has changed on our Cloud provider, like AWS, and we click on the wrong tick box and Facebook is not available for a few hours? So it can be really stress, right? So to avoid this situation and to fix this problem and never been such a problem, again, we need to take advantage of the infrastructure as code.

But before we're gonna start talking about the infrastructure itself, let's consider these two programming paradigms as they are quite relevant when we talk about coding for the infrastructure. On the one hand, we have the imperative, which stands for explicit instructions for literally everything. We usually refer to some bus scripts, and actually, explicit instruction is the biggest advantage of such approach. But at the same time it's the biggest concern, because you need to maintain everything yourself, and it's not really scalable over time. On the other hand, we have the declarative approach, which stands to describe outcome and handle the provider to do the rest of the job, which is way easier and better to scale. So, yeah, again, with the imperative one, you're kind of smart and you're always blaming system that it doesn't work as you expect it, because you wrote so many lines of code. When with the declarative one, you just don't care until smart providers are handling everything for you. And the good news that Terraform actually, it's an open source. Who worked with Terraform before? Let me ask this question first. Yeah. Okay. A few people. Awesome. So, Terraform is an open source software which is originally developed by HashiCorp, and it supports about the thousands of different providers, and it allow us manage our infrastructure with code, and what's more important for today that it also support TypeScript. Or better to say that CDK, which stands for Cloud Development Kit, supports the TypeScript.

2. Building Infrastructure with Terraform and CDK

Short description:

To implement infrastructure, you previously needed to learn a new language. Terraform's language is not complex, and I believe it's a game changer. In the next 30 minutes, we'll build production-ready infrastructure for a React application, step by step. We'll start by creating folders and installing CDK. Then, we'll use React Create app to create a basic TypeScript React application. Next, we'll initialize the project with CDK-TF, specifying a TypeScript template and a local back end. If you encounter TypeScript errors, add the skip-loop check flag to the Terraform ts-config.

And I truly believe that it's a real game changer because previously, to implement infrastructure, you likely need to learn a new language. With the Terraform HashiCorp language, which is not bad, it's not complex, probably slightly more complex than JSON or YAML files, but you know, we are developers. I really like the power of programming languages and I'm coding for many years, and that's what I would like to create my infrastructure with, and yeah, that's why I think it's a real game changer.

So in the next 30 minutes, what we're gonna do, I mean, probably a bit less, we're gonna build the React, we're gonna build the production-ready infrastructure for our React application, to be honest, for even any JS application you choose. And yeah, we're gonna do it step by step, it's gonna kind of workshop-style talk, you can follow up with the laptops but don't worry if you need to take your time, after the talk right at the end I will share with you all the code samples and there will be a GitHub repo link, so you can follow up later on and I'm pretty sure that this talk will be recorded.

Okay, so we can start. So let me just do this because it's a bit weird. Cool. Can you see my screen? And just a second, I will make it scalable so I can control it. Okay, so I'm really sorry. I just messed things up. But all good now. Cool. Yeah, the first step, what we're going to do, we're going to use React Create. I hope everyone. Yeah. So we're going to use React Create app just to create the basic TypeScript React application and we're going to run this command for this and after this we're going to have this nice and shiny application ready. But so far nothing is related to the infrastructure itself.

Now we're going to start with creating some folders for our infrastructure. And as a prerequirement we need to install CDK. You can install it on the root level of your machine globally or you can install it per project. It's your call. But basically as soon as we have CDK-TF we can create a project folder and start bootstrapping our infrastructure. For this I'm going to use a command which is CDK-TF init. I'm going to pass the template as a TypeScript, similarly what we've done for the React application and I'm going to specify local back end. If you know what local back end means in terms of Terraforms, it's cool. If not, no worries. We're going to cover it a bit later during the talk. After the initialization, you may see such errors related to the TypeScript and the reason for that because I'm pretty sure Terraform is going to address them shortly but so far you need to add skip-loop check because it doesn't really expect that there will be one more TypeScript project in the same project. As soon as we add skip-loop check flag to ts-config of the Terraform, everything will be okay.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
Watch video: React's Most Useful Types
Today's Talk focuses on React's best types and JSX. It covers the types of JSX and React components, including React.fc and React.reactnode. The discussion also explores JSX intrinsic elements and react.component props, highlighting their differences and use cases. The Talk concludes with insights on using React.componentType and passing components, as well as utilizing the react.element ref type for external libraries like React-Select.
TypeScript and React: Secrets of a Happy Marriage
React Advanced 2022React Advanced 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
React and TypeScript have a strong relationship, with TypeScript offering benefits like better type checking and contract enforcement. Failing early and failing hard is important in software development to catch errors and debug effectively. TypeScript provides early detection of errors and ensures data accuracy in components and hooks. It offers superior type safety but can become complex as the codebase grows. Using union types in props can resolve errors and address dependencies. Dynamic communication and type contracts can be achieved through generics. Understanding React's built-in types and hooks like useState and useRef is crucial for leveraging their functionality.
Automating All the Code & Testing Things with GitHub Actions
React Advanced 2021React Advanced 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Top Content
We will learn how to automate code and testing with GitHub Actions, including linting, formatting, testing, and deployments. Automating deployments with scripts and Git hooks can help avoid mistakes. Popular CI-CD frameworks like Jenkins offer powerful orchestration but can be challenging to work with. GitHub Actions are flexible and approachable, allowing for environment setup, testing, deployment, and custom actions. A custom AppleTools Eyes GitHub action simplifies visual testing. Other examples include automating content reminders for sharing old content and tutorials.
Making Magic: Building a TypeScript-First Framework
TypeScript Congress 2023TypeScript Congress 2023
31 min
Making Magic: Building a TypeScript-First Framework
Top Content
Daniel Rowe discusses building a TypeScript-first framework at TypeScript Congress and shares his involvement in various projects. Nuxt is a progressive framework built on Vue.js, aiming to reduce friction and distraction for developers. It leverages TypeScript for inference and aims to be the source of truth for projects. Nuxt provides type safety and extensibility through integration with TypeScript. Migrating to TypeScript offers long-term maintenance benefits and can uncover hidden bugs. Nuxt focuses on improving existing tools and finds inspiration in frameworks like TRPC.
Fine-tuning DevOps for People over Perfection
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Fine-tuning DevOps for People over Perfection
Top Content
DevOps is a journey that varies for each company, and remote work makes transformation challenging. Pull requests can be frustrating and slow, but success stories like Mateo Colia's company show the benefits of deploying every day. Challenges with tools and vulnerabilities require careful consideration and prioritization. Investing in documentation and people is important for efficient workflows and team growth. Trust is more important than excessive control when deploying to production.

Workshops on related topic

React, TypeScript, and TDD
React Advanced 2021React Advanced 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Featured Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced 2022React Advanced 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Building Your Own Custom Type System
React Summit 2024React Summit 2024
38 min
Building Your Own Custom Type System
Featured Workshop
Kunal Dubey
Kunal Dubey
I'll introduce the audience to a concept where they can have end-to-end type systems that helps ensure typesafety across the teams Such a system not only improves communication between teams but also helps teams collaborate effectively and ship way faster than they used to before. By having a custom type system, teams can also identify the errors and modify the API contracts on their IDE, which contributes to a better Developer Experience. The workshop would primarily leverage TS to showcase the concept and use tools like OpenAPI to generate the typesystem on the client side. 
Frictionless Development With Unified Type System
JSNation 2024JSNation 2024
113 min
Frictionless Development With Unified Type System
Featured Workshop
Ejiro Asiuwhu
Ejiro Asiuwhu
Imagine developing where frontend and backend sing in harmony, types dance in perfect sync, and errors become a distant memory. That's the magic of TypeScript Nirvana!
Join me on a journey to unveil the secrets of unified type definitions, the key to unlocking frictionless development. We'll dive into:
- Shared language, shared love: Define types once, share them everywhere. Consistency becomes your BFF, errors your worst nightmare (one you'll rarely see).- Effortless coding: Ditch the manual grind of type checking. TypeScript's got your back, freeing you to focus on building awesomeness.- Maintainability magic: With crystal-clear types guiding your code, maintaining it becomes a walk in the park. More time innovating, less time debugging.- Security fortress: TypeScript's type system shields your app from common vulnerabilities, making it a fortress against security threats.