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

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
Learn more about how to leverage the default features of npm workspaces to help you manage your monorepo project while also checking out some of the new npm cli features.
TypeScript and React: Secrets of a Happy Marriage
React Advanced Conference 2022React Advanced Conference 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
TypeScript and React are inseparable. What's the secret to their successful union? Quite a lot of surprisingly strange code. Learn why useRef always feels weird, how to wrangle generics in custom hooks, and how union types can transform your components.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
We don't think of React as shipping its own types. But React's types are a core part of the framework - overseen by the React team, and co-ordinated with React's major releases.In this live coding talk, we'll look at all the types you've been missing out on. How do you get the props type from a component? How do you know what ref a component takes? Should you use React.FC? And what's the deal with JSX.Element?You'll walk away with a bunch of exciting ideas to take to your React applications, and hopefully a new appreciation for the wonders of React and TypeScript working together.
Automating All the Code & Testing Things with GitHub Actions
React Advanced Conference 2021React Advanced Conference 2021
19 min
Automating All the Code & Testing Things with GitHub Actions
Top Content
Code tasks like linting and testing are critical pieces of a developer’s workflow that help keep us sane like preventing syntax or style issues and hardening our core business logic. We’ll talk about how we can use GitHub Actions to automate these tasks and help keep our projects running smoothly.
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
Demand for DevOps has increased in recent years as more organizations adopt cloud native technologies. Complexity has also increased and a "zero to hero" mentality leaves many people chasing perfection and FOMO. This session focusses instead on why maybe we shouldn't adopt a technology practice and how sometimes teams can achieve the same results prioritizing people over ops automation & controls. Let's look at amounts of and fine-tuning everything as code, pull requests, DevSecOps, Monitoring and more to prioritize developer well-being over optimization perfection. It can be a valid decision to deploy less and sleep better. And finally we'll examine how manual practice and discipline can be the key to superb products and experiences.
Stop Writing Your Routes
Vue.js London 2023Vue.js London 2023
30 min
Stop Writing Your Routes
The more you keep working on an application, the more complicated its routing becomes, and the easier it is to make a mistake. ""Was the route named users or was it user?"", ""Did it have an id param or was it userId?"". If only TypeScript could tell you what are the possible names and params. If only you didn't have to write a single route anymore and let a plugin do it for you. In this talk we will go through what it took to bring automatically typed routes for Vue Router.

Workshops on related topic

React, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 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.
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced Conference 2022React Advanced Conference 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.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
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.
Practice TypeScript Techniques Building React Server Components App
TypeScript Congress 2023TypeScript Congress 2023
131 min
Practice TypeScript Techniques Building React Server Components App
Workshop
Maurice de Beijer
Maurice de Beijer
In this hands-on workshop, Maurice will personally guide you through a series of exercises designed to empower you with a deep understanding of React Server Components and the power of TypeScript. Discover how to optimize your applications, improve performance, and unlock new possibilities.
 
During the workshop, you will:
- Maximize code maintainability and scalability with advanced TypeScript practices
- Unleash the performance benefits of React Server Components, surpassing traditional approaches
- Turbocharge your TypeScript with the power of Mapped Types
- Make your TypeScript types more secure with Opaque Types
- Explore the power of Template Literal Types when using Mapped Types
 
Maurice will virtually be by your side, offering comprehensive guidance and answering your questions as you navigate each exercise. By the end of the workshop, you'll have mastered React Server Components, armed with a newfound arsenal of TypeScript knowledge to supercharge your React applications.
 
Don't miss this opportunity to elevate your React expertise to new heights. Join our workshop and unlock the potential of React Server Components with TypeScript. Your apps will thank you.
Deploying React Native Apps in the Cloud
React Summit 2023React Summit 2023
88 min
Deploying React Native Apps in the Cloud
WorkshopFree
Cecelia Martinez
Cecelia Martinez
Deploying React Native apps manually on a local machine can be complex. The differences between Android and iOS require developers to use specific tools and processes for each platform, including hardware requirements for iOS. Manual deployments also make it difficult to manage signing credentials, environment configurations, track releases, and to collaborate as a team.
Appflow is the cloud mobile DevOps platform built by Ionic. Using a service like Appflow to build React Native apps not only provides access to powerful computing resources, it can simplify the deployment process by providing a centralized environment for managing and distributing your app to multiple platforms. This can save time and resources, enable collaboration, as well as improve the overall reliability and scalability of an app.
In this workshop, you’ll deploy a React Native application for delivery to Android and iOS test devices using Appflow. You’ll also learn the steps for publishing to Google Play and Apple App Stores. No previous experience with deploying native applications is required, and you’ll come away with a deeper understanding of the mobile deployment process and best practices for how to use a cloud mobile DevOps platform to ship quickly at scale.