Deploying AWS Amplify with Terraform: Infrastructure as Code for Full-Stack Hosting

AWS Amplify is a managed service for typical fullstack applications, allowing developers to connect their Git repository and manage automatic deployments of their app frontends, backend APIs, authentication, storage, serverless functions, etc. It is AWS’ answer to Netlify, Vercel, Cloudflare kickstarter app deploys, and so abstracts away the underlying infrastructure and how it connects together for a simpler GUI and code-driven configuration.

For teams that already operate VPCs, databases and other AWS resources through Terraform, keeping Amplify in the console creates a gap in infrastructure as code. Managing Amplify resources entirely through Terraform makes the setup reproducible and version-controlled, and brings frontend hosting into the same workflow as the rest of AWS resources. AWS Amplify is great for developers who want a managed hosting experience, but enterprise teams often need their infrastructure defined in Terraform alongside everything else. Instead of clicking through the Amplify console or using the Amplify CLI separately from your other infrastructure, you can manage Amplify resources entirely through Terraform.

What AWS Amplify Provides

AWS Amplify can help you build and deploy full-stack applications with ease, while Terraform allows you to define your infrastructure configurations in code using a declarative configuration language. Amplify is an AWS service offering that allows you to easily deploy full-stack applications or static sites really easily. It allows you to either connect to a repository or to do manual deploys where you can either point it at an S3 bucket or upload a zip file containing your site.

The service provides a unified model to manage backend and frontend development workflows, and it helps to seamlessly integrate with other AWS services. Another neat feature is it performs an automatic ui check for your deployed application against a few common devices so you can check that it is rendering correctly on different screen sizes. There are many other great features such as monitoring and automatic branch creation.

Since AWS Amplify serves basic accelerated app deployments its Terraform support is in less demand which likely explains some long-standing bugs which have been circumvented and documented in practice.

Why Terraform for Amplify

If your organization already uses Terraform for VPCs, databases, and other AWS resources, managing Amplify separately creates a gap in your infrastructure-as-code strategy.

Using Terraform for Amplify gives you:

  • A single source of truth for all infrastructure
  • Consistent state management across resources
  • Drift detection and automated reconciliation
  • The ability to create identical environments with terraform workspace
  • Integration with your existing CI/CD pipelines

Terraform enables you to automate the provision and management of your AWS Amplify resources. Once you have defined your changes in the declarative configuration language, Terraform will apply the changes automatically, reducing any manual or human intervention. Managing Amplify through Terraform brings your frontend hosting into the same infrastructure-as-code workflow as the rest of your AWS resources. You get reproducible environments, drift detection, and the ability to spin up identical staging environments with a single terraform apply. For teams that already live in Terraform, this eliminates the last piece of manual console configuration.

This guide covers provisioning Amplify apps, branches, domain associations, webhooks, and related backend resources using Terraform. By the end, your entire Amplify setup will be reproducible and version-controlled.

Prerequisites

You need:

  • Terraform 1.0 or later installed
  • AWS credentials configured
  • A Git repository with your frontend application
  • A GitHub personal access token for repository connection

It is assumed that you already have an understanding of using Terraform and AWS. If you are new to Terraform, Amplify and AWS, there are many valuable resources to get you up to speed.

Start the AWS command-line interface CLI running on your workstation so that you can authenticate with AWS.

For a React workflow, create a React.js app using the command for your stack. For the purposes of this article we will assume that we already have a React application that we want to deploy. The content or code of the application is not important as we will be focusing on setting up the infrastructure not developing the application.

From the AWS console, set up an IAM user with the policy AdministratorAccess-Amplify to manage our Terraform infrastructure.

Provider and State Configuration

A typical Terraform configuration starts with provider and backend definition.

```hcl
terraform {
requiredversion = ">= 1.0"
required
providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}

backend "s3" {
bucket = "my-terraform-state"
key = "amplify/terraform.tfstate"
region = "us-east-1"
}
```

provider "aws" {
region = var.aws_region
}
```

The backend S3 configuration is used for state management. The module documentation notes minimum supported Terraform version is 1.3.0 with aws >= 5.20.

Module version requirements from the JetBrains terraform-aws-amplify module are:

Name Version
terraform >= 1.3
aws >= 5.20

Provider requirements:

Name Version
aws >= 5.20

Creating the Amplify App Resource

The awsamplifyapp resource creates the Amplify application.

```hcl
resource "awsamplifyapp" "main" {
name = var.appname
repository = var.repository
url
accesstoken = var.githubaccess_token

buildspec = <<-EOT
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '/*'
cache:
paths:
- node
modules//*
EOT
}
```

Build specification can be supplied inline. For React progressive web applications, the build phase typically runs npm ci and npm run build, with artifacts pointing to the output directory.

The guide recommends setting waitforverification = false initially and verify separately.

Prerequisites summary:

Item Requirement
Terraform 1.0 or later, module requires >=1.3.0
AWS Provider ~> 5.0
AWS Credentials Configured
Git Repository Frontend application
GitHub Token Personal access token for repository access

Monorepo Structure and Workflow

To deploy with AWS Amplify via Terraform within a monorepo structure:

. ├── frontend │ ├── package.json │ └── ... └── infra ├── main.tf └── ...

We will be making use of AWS Amplify’s managed deployments where we connect a CodeCommit repository to Amplify so that when we push changes to our repository, our application will automatically deploy the changes. We will also be using Terraform to set up our AWS infrastructure.

The terraform-aws-amplify module simplifies the deployment process of a web site by automatically deploying it from an existing S3 bucket to a new AWS Amplify service that it sets up for you.

The module repository contains:

  • examples: this folder contains ready to use examples that show how to use this Module
  • tests: this folder contains a list of automated tests for this Module and examples
  • lib: this folder contains a list of local utilities, mostly Makefiles, to support the contributor's maintenance effort of this Module
  • modules: this folder contains a list of local Terraform modules that the Root Module uses
  • .github: this folder contains a list of GitHub workflows to support contributions during change requests and releases of this Module

Resources exposed by the module include:

Name Type
awsamplifyapp.site resource
awsamplifybranch.site resource

Input variable example:

Name Description Type Default Required
awss3bucket_store The AWS S3 details where the ZIP bundle that needs to be deployed is stored object n/a yes
deployment_name The name of the

Benefits and Operational Patterns

The service provides a unified model to manage backend and frontend development workflows, and it helps to seamlessly integrate with other AWS services.

Benefits of managing Amplify through Terraform include a single source of truth for all infrastructure, consistent state management across resources, drift detection and automated reconciliation, the ability to create identical environments with terraform workspace, and integration with existing CI/CD pipelines.

For teams that already live in Terraform, this eliminates the last piece of manual console configuration. Managing Amplify through Terraform brings your frontend hosting into the same infrastructure-as-code workflow as the rest of your AWS resources. You get reproducible environments, drift detection, and the ability to spin up identical staging environments with a single terraform apply.

I would like to deploy my AWS Amplify React project using Terraform so that I can automate my workflow and eliminate any manual intervention during deployment. Terraform enables you to automate the provision and management of your AWS Amplify resources. Once you have defined your changes in the declarative configuration language, Terraform will apply the changes automatically, reducing any manual or human intervention.

Conclusion

Deploying AWS Amplify with Terraform moves Amplify hosting from console clicks into declarative, version-controlled infrastructure. Terraform for Amplify gives you a single source of truth, consistent state management, drift detection and automated reconciliation, identical environments via terraform workspace, and integration with existing CI/CD pipelines.

The practical setup starts with an AWS provider configuration and S3 state backend, an IAM user with AdministratorAccess-Amplify policy, and an awsamplifyapp resource defining name, repository, access token and build_spec. Monorepo layouts separate frontend code from infra definitions, and modules such as terraform-aws-amplify provide reusable scaffolding for deploying from S3 to Amplify.

For teams already operating AWS with Terraform, bringing Amplify under Terraform closes the last manual gap. The entire Amplify setup becomes reproducible and version-controlled, with automated deployments triggered from Git changes and infrastructure changes applied via terraform apply.

Sources

  1. Deploying AWS Amplify with Terraform
  2. Deploy React on AWS Amplify Using Terraform
  3. Deploy Amplify Backend Resources With Terraform
  4. How To Setup Aws Amplify Infrastructure With Terraform
  5. terraform-aws-amplify

Related Posts