Skip to content

Resource: awsAmplifyBranch

Provides an Amplify Branch resource.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsAmplifyAppExample = new aws.amplifyApp.AmplifyApp(this, "example", {
  name: "app",
});
new aws.amplifyBranch.AmplifyBranch(this, "master", {
  appId: awsAmplifyAppExample.id,
  branchName: "master",
  environmentVariables: {
    REACT_APP_API_SERVER: "https://api.example.com",
  },
  framework: "React",
  stage: "PRODUCTION",
});

Basic Authentication

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsAmplifyAppExample = new aws.amplifyApp.AmplifyApp(this, "example", {
  name: "app",
});
new aws.amplifyBranch.AmplifyBranch(this, "master", {
  appId: awsAmplifyAppExample.id,
  basicAuthCredentials: '${base64encode("username:password")}',
  branchName: "master",
  enableBasicAuth: true,
});

Notifications

Amplify Console uses EventBridge (formerly known as CloudWatch Events) and SNS for email notifications. To implement the same functionality, you need to set enableNotification in a awsAmplifyBranch resource, as well as creating an EventBridge Rule, an SNS topic, and SNS subscriptions.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsAmplifyAppExample = new aws.amplifyApp.AmplifyApp(this, "example", {
  name: "app",
});
const awsAmplifyBranchMaster = new aws.amplifyBranch.AmplifyBranch(
  this,
  "master",
  {
    appId: awsAmplifyAppExample.id,
    branchName: "master",
    enableNotification: true,
  }
);
const awsCloudwatchEventRuleAmplifyAppMaster =
  new aws.cloudwatchEventRule.CloudwatchEventRule(this, "amplify_app_master", {
    description: `AWS Amplify build notifications for :  App: \${aws_amplify_app.app.id} Branch: \${${awsAmplifyBranchMaster.branchName}}`,
    eventPattern:
      '${jsonencode({\n    "detail" = {\n      "appId" = [\n        aws_amplify_app.example.id\n      ]\n      "branchName" = [\n        aws_amplify_branch.master.branch_name\n      ],\n      "jobStatus" = [\n        "SUCCEED",\n        "FAILED",\n        "STARTED"\n      ]\n    }\n    "detail-type" = [\n      "Amplify Deployment Status Change"\n    ]\n    "source" = [\n      "aws.amplify"\n    ]\n  })}',
    name: `amplify-\${aws_amplify_app.app.id}-\${${awsAmplifyBranchMaster.branchName}}-branch-notification`,
  });
const awsSnsTopicAmplifyAppMaster = new aws.snsTopic.SnsTopic(
  this,
  "amplify_app_master_3",
  {
    name: `amplify-\${aws_amplify_app.app.id}_\${${awsAmplifyBranchMaster.branchName}}`,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsSnsTopicAmplifyAppMaster.overrideLogicalId("amplify_app_master");
const dataAwsIamPolicyDocumentAmplifyAppMaster =
  new aws.dataAwsIamPolicyDocument.DataAwsIamPolicyDocument(
    this,
    "amplify_app_master_4",
    {
      statement: [
        {
          actions: ["SNS:Publish"],
          effect: "Allow",
          principals: [
            {
              identifiers: ["events.amazonaws.com"],
              type: "Service",
            },
          ],
          resources: [awsSnsTopicAmplifyAppMaster.arn],
          sid: `Allow_Publish_Events \${${awsAmplifyBranchMaster.arn}}`,
        },
      ],
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
dataAwsIamPolicyDocumentAmplifyAppMaster.overrideLogicalId(
  "amplify_app_master"
);
const awsCloudwatchEventTargetAmplifyAppMaster =
  new aws.cloudwatchEventTarget.CloudwatchEventTarget(
    this,
    "amplify_app_master_5",
    {
      arn: awsSnsTopicAmplifyAppMaster.arn,
      inputTransformer: {
        inputPaths: {
          appId: "$.detail.appId",
          branch: "$.detail.branchName",
          jobId: "$.detail.jobId",
          region: "$.region",
          status: "$.detail.jobStatus",
        },
        inputTemplate:
          '"Build notification from the AWS Amplify Console for app: https://<branch>.<appId>.amplifyapp.com/. Your build status is <status>. Go to https://console.aws.amazon.com/amplify/home?region=<region>#<appId>/<branch>/<jobId> to view details on your build. "',
      },
      rule: awsCloudwatchEventRuleAmplifyAppMaster.name,
      targetId: awsAmplifyBranchMaster.branchName,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsCloudwatchEventTargetAmplifyAppMaster.overrideLogicalId(
  "amplify_app_master"
);
const awsSnsTopicPolicyAmplifyAppMaster = new aws.snsTopicPolicy.SnsTopicPolicy(
  this,
  "amplify_app_master_6",
  {
    arn: awsSnsTopicAmplifyAppMaster.arn,
    policy: dataAwsIamPolicyDocumentAmplifyAppMaster.json,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsSnsTopicPolicyAmplifyAppMaster.overrideLogicalId("amplify_app_master");

Argument Reference

The following arguments are supported:

  • appId - (Required) Unique ID for an Amplify app.
  • branchName - (Required) Name for the branch.
  • backendEnvironmentArn - (Optional) ARN for a backend environment that is part of an Amplify app.
  • basicAuthCredentials - (Optional) Basic authorization credentials for the branch.
  • description - (Optional) Description for the branch.
  • displayName - (Optional) Display name for a branch. This is used as the default domain prefix.
  • enableAutoBuild - (Optional) Enables auto building for the branch.
  • enableBasicAuth - (Optional) Enables basic authorization for the branch.
  • enableNotification - (Optional) Enables notifications for the branch.
  • enablePerformanceMode - (Optional) Enables performance mode for the branch.
  • enablePullRequestPreview - (Optional) Enables pull request previews for this branch.
  • environmentVariables - (Optional) Environment variables for the branch.
  • framework - (Optional) Framework for the branch.
  • pullRequestEnvironmentName - (Optional) Amplify environment name for the pull request.
  • stage - (Optional) Describes the current stage for the branch. Valid values: production, beta, development, experimental, PULL_REQUEST.
  • tags - (Optional) Key-value mapping of resource tags. If configured with a provider defaultTags configuration block present, tags with matching keys will overwrite those defined at the provider-level.
  • ttl - (Optional) Content Time To Live (TTL) for the website in seconds.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • arn - ARN for the branch.
  • associatedResources - A list of custom resources that are linked to this branch.
  • customDomains - Custom domains for the branch.
  • destinationBranch - Destination branch if the branch is a pull request branch.
  • sourceBranch - Source branch if the branch is a pull request branch.
  • tagsAll - Map of tags assigned to the resource, including those inherited from the provider defaultTags configuration block.

Import

Amplify branch can be imported using appId and branchName, e.g.,

$ terraform import aws_amplify_branch.master d2ypk4k47z8u6/master