Resource: awsAmplifyApp
Provides an Amplify App resource, a fullstack serverless app hosted on the AWS Amplify Console.
\~> Note: When you create/update an Amplify App from Terraform, you may end up with the error "BadRequestException: You should at least provide one valid token" because of authentication issues. See the section "Repository with Tokens" below.
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";
new aws.amplifyApp.AmplifyApp(this, "example", {
buildSpec:
"version: 0.1\nfrontend:\n phases:\n preBuild:\n commands:\n - yarn install\n build:\n commands:\n - yarn run build\n artifacts:\n baseDirectory: build\n files:\n - '**/*'\n cache:\n paths:\n - node_modules/**/*\n",
customRule: [
{
source: "/<*>",
status: "404",
target: "/index.html",
},
],
environmentVariables: {
ENV: "test",
},
name: "example",
repository: "https://github.com/example/app",
});
Repository with Tokens
If you create a new Amplify App with the repository argument, you also need to set oauthToken or accessToken for authentication. For GitHub, get a personal access token and set accessToken as follows:
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.amplifyApp.AmplifyApp(this, "example", {
accessToken: "...",
name: "example",
repository: "https://github.com/example/app",
});
You can omit accessToken if you import an existing Amplify App created by the Amplify Console (using OAuth for authentication).
Auto Branch Creation
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.amplifyApp.AmplifyApp(this, "example", {
autoBranchCreationConfig: {
enableAutoBuild: true,
},
autoBranchCreationPatterns: ["*", "*/**"],
enableAutoBranchCreation: true,
name: "example",
});
Basic Authorization
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.amplifyApp.AmplifyApp(this, "example", {
basicAuthCredentials: '${base64encode("username1:password1")}',
enableBasicAuth: true,
name: "example",
});
Rewrites and Redirects
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.amplifyApp.AmplifyApp(this, "example", {
customRule: [
{
source: "/api/<*>",
status: "200",
target: "https://api.example.com/api/<*>",
},
{
source:
"</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>",
status: "200",
target: "/index.html",
},
],
name: "example",
});
Custom Image
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
new aws.amplifyApp.AmplifyApp(this, "example", {
environmentVariables: {
_CUSTOM_IMAGE: "node:16",
},
name: "example",
});
Argument Reference
The following arguments are supported:
name- (Required) Name for an Amplify app.accessToken- (Optional) Personal access token for a third-party source control system for an Amplify app. The personal access token is used to create a webhook and a read-only deploy key. The token is not stored.autoBranchCreationConfig- (Optional) Automated branch creation configuration for an Amplify app. AnautoBranchCreationConfigblock is documented below.autoBranchCreationPatterns- (Optional) Automated branch creation glob patterns for an Amplify app.basicAuthCredentials- (Optional) Credentials for basic authorization for an Amplify app.buildSpec- (Optional) The build specification (build spec) for an Amplify app.customRule- (Optional) Custom rewrite and redirect rules for an Amplify app. AcustomRuleblock is documented below.description- (Optional) Description for an Amplify app.enableAutoBranchCreation- (Optional) Enables automated branch creation for an Amplify app.enableBasicAuth- (Optional) Enables basic authorization for an Amplify app. This will apply to all branches that are part of this app.enableBranchAutoBuild- (Optional) Enables auto-building of branches for the Amplify App.enableBranchAutoDeletion- (Optional) Automatically disconnects a branch in the Amplify Console when you delete a branch from your Git repository.environmentVariables- (Optional) Environment variables map for an Amplify app.iamServiceRoleArn- (Optional) AWS Identity and Access Management (IAM) service role for an Amplify app.oauthToken- (Optional) OAuth token for a third-party source control system for an Amplify app. The OAuth token is used to create a webhook and a read-only deploy key. The OAuth token is not stored.platform- (Optional) Platform or framework for an Amplify app. Valid values:web,WEB_COMPUTE. Default value:web.repository- (Optional) Repository for an Amplify app.tags- (Optional) Key-value mapping of resource tags. If configured with a providerdefaultTagsconfiguration block present, tags with matching keys will overwrite those defined at the provider-level.
An autoBranchCreationConfig block supports the following arguments:
basicAuthCredentials- (Optional) Basic authorization credentials for the autocreated branch.buildSpec- (Optional) Build specification (build spec) for the autocreated branch.enableAutoBuild- (Optional) Enables auto building for the autocreated branch.enableBasicAuth- (Optional) Enables basic authorization for the autocreated branch.enablePerformanceMode- (Optional) Enables performance mode for the branch.enablePullRequestPreview- (Optional) Enables pull request previews for the autocreated branch.environmentVariables- (Optional) Environment variables for the autocreated branch.framework- (Optional) Framework for the autocreated branch.pullRequestEnvironmentName- (Optional) Amplify environment name for the pull request.stage- (Optional) Describes the current stage for the autocreated branch. Valid values:production,beta,development,experimental,PULL_REQUEST.
A customRule block supports the following arguments:
condition- (Optional) Condition for a URL rewrite or redirect rule, such as a country code.source- (Required) Source pattern for a URL rewrite or redirect rule.status- (Optional) Status code for a URL rewrite or redirect rule. Valid values:200,301,302,404,404200.target- (Required) Target pattern for a URL rewrite or redirect rule.
Attributes Reference
In addition to all arguments above, the following attributes are exported:
arn- ARN of the Amplify app.defaultDomain- Default domain for the Amplify app.id- Unique ID of the Amplify app.productionBranch- Describes the information about a production branch for an Amplify app. AproductionBranchblock is documented below.tagsAll- Map of tags assigned to the resource, including those inherited from the providerdefaultTagsconfiguration block.
A productionBranch block supports the following attributes:
branchName- Branch name for the production branch.lastDeployTime- Last deploy time of the production branch.status- Status of the production branch.thumbnailUrl- Thumbnail URL for the production branch.
Import
Amplify App can be imported using Amplify App ID (appId), e.g.,
App ID can be obtained from App ARN (e.g., arn:aws:amplify:usEast1:12345678:apps/d2Ypk4K47Z8U6).