Orchestrating AWS Amplify Deployments with Terraform: Simplifying Scalable Development

Orchestrating AWS Amplify Deployments with Terraform: Simplifying Scalable Development

OverView :-

AWS Amplify is a powerful tool that can help you build and deploy full-stack applications with ease. #Terraform is an infrastructure as code tool that allows you to manage your cloud infrastructure in a declarative manner. In this tutorial, we will show you how to deploy AWS Amplify using #Terraform.

Step 1: Install #Terraform and the AWS CLI

The first step is to install #Terraform and the AWS CLI on your machine. You can download #Terraform from the official website, and the AWS CLI can be installed using pip. Once you have installed these tools, you can move on to the next step.

Step 2: Create a folder named amplify in your home directory. With in the amplify folder create a file named main.tf. The file should include the following code:

resource "aws_amplify_app" "amplify_app" {
  name       = var.app_name
  repository = var.repository
  oauth_token = var.token  
}
resource "aws_amplify_branch" "amplify_branch" {
  app_id      = aws_amplify_app.amplify_app.id
  branch_name = var.branch_name
}
resource "aws_amplify_domain_association" "domain_association" {
  app_id      = aws_amplify_app.amplify_app.id
  domain_name = var.domain_name
  wait_for_verification = false

  sub_domain {
    branch_name = aws_amplify_branch.amplify_branch.branch_name
    prefix      = var.branch_name
  }

}

This code defines an Amplify app, branch, and domain. You will need to define the values for the variables in a separate file called variables.tf.

Step 3: Define Variables

In the variables.tf file, you will define the values for the variables used in the main.tf file. The file should include the following code:

variable "token" {
  type        = string
  description = "github token to connect github repo"
  default     = "Your Gitub Token"
}

variable "repository" {
  type        = string
  description = "github repo url"
  default     = "YOUR SOURCE-CODE REPO URL"
}

variable "app_name" {
  type        = string
  description = "AWS Amplify App Name"
  default     = "my-amplify"
}

variable "branch_name" {
  type        = string
  description = "AWS Amplify App Repo Branch Name"
  default     = "master"
}


variable "domain_name" {
  type        = string
  default     = "awsamplifyapp.com"
  description = "AWS Amplify Domain Name"
}

Step 4: Define Outputs

In the main.tf file, you will define the outputs required for your #Terraform configuration. The file should include the following code:

output "amplify_app_id" {
  value = aws_amplify_app.amplify_app.id
}

output "amplify_app_url" {
  value = aws_amplify_domain_association.domain_association.domain_name
}

These outputs will provide you with the necessary information to access and use your Amplify app.

Step 5: Apply Your #Terraform Configuration

Now that you have defined your #Terraform configuration file, variables, and outputs, you can apply your configuration using the following commands:

terraform init
terraform plan
terraform apply

The terraform init command will initialize our #Terraform environment.
The terraform plan command will show us the plan of the changes to be made.
The terraform apply command applies the #Terraform configuration and creates amplify.

Step 6: Verify Your Amplify Resources

After #Terraform has successfully applied your configuration, you can verify that your Amplify resources have been created by visiting the AWS Management Console

  • Once the deployment is completed u can check the app is available or not by clicking on the https**url .**

Terraform-Source-code linkgithub.com/MahiraTechnology/Mahira-medium.git

Conclusion:-

In this tutorial, we have shown you how to deploy AWS Amplify using Terraform. #Terraform allows you to manage your infrastructure as code, which means that you can version control your infrastructure and easily reproduce it across multiple environments. By following the steps outlined in this tutorial, you can easily deploy your Amplify app using #Terraform and have full control over your cloud infrastructure.