Skip to main content

Module: amplify-app

Terraform module to provision AWS Amplify apps, backend environments, branches, domain associations, and webhooks.

Usage

For a complete example, see examples/complete.

For automated tests of the complete example using bats and Terratest (which tests and deploys the example on AWS), see test.

data "aws_ssm_parameter" "github_pat" {
name = var.github_personal_access_token_secret_path
with_decryption = true
}

module "amplify_app" {
source = "cloudposse/amplify-app/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"

access_token = data.aws_ssm_parameter.github_pat.value

description = "Test Amplify App"
repository = "https://github.com/cloudposse/amplify-test2"
platform = "WEB"

enable_auto_branch_creation = false
enable_branch_auto_build = true
enable_branch_auto_deletion = true
enable_basic_auth = false

iam_service_role_enabled = true

iam_service_role_actions = [
"logs:CreateLogStream",
"logs:CreateLogGroup",
"logs:DescribeLogGroups",
"logs:PutLogEvents"
]

auto_branch_creation_patterns = [
"*",
"*/**"
]

auto_branch_creation_config = {
# Enable auto build for the created branches
enable_auto_build = true
}

# The build spec for React
build_spec = <<-EOT
version: 0.1
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
EOT

custom_rules = [
{
source = "/<*>"
status = "404"
target = "/index.html"
}
]

environment_variables = {
ENV = "test"
}

environments = {
main = {
branch_name = "main"
enable_auto_build = true
backend_enabled = false
enable_performance_mode = true
enable_pull_request_preview = false
framework = "React"
stage = "PRODUCTION"
}
dev = {
branch_name = "dev"
enable_auto_build = true
backend_enabled = false
enable_performance_mode = false
enable_pull_request_preview = true
framework = "React"
stage = "DEVELOPMENT"
}
}

domains = {
"test.net" = {
enable_auto_sub_domain = true
wait_for_verification = false
sub_domain = [
{
branch_name = "main"
prefix = ""
},
{
branch_name = "dev"
prefix = "dev"
}
]
}
}

context = module.label.context
}

Examples

Here is an example of using this module: