NextJsAmplifySite

The NextJsAmplifySite construct is designed to streamline the deployment of Next.js applications on AWS Amplify. It configures the necessary AWS resources, including the Amplify application, branch, and optional custom domain, to facilitate a seamless deployment and hosting experience for developers.

Features

  • AWS Amplify Configuration: Sets up an AWS Amplify application with specified GitHub repository source, build specifications, and environment variables.
  • Custom Domain Mapping: Allows for custom domain mapping with automatic subdomain creation for feature branches.
  • Auto Branch Creation and Deletion: Configures automatic branch creation and deletion based on specified patterns.
  • Custom IAM Role: Creates a custom IAM role with necessary permissions for AWS Amplify.

Properties

  • accessTokenName: The name of the AWS Secrets Manager secret containing the GitHub OAuth token.
  • repoOwner: The owner of the GitHub repository.
  • repoName: The name of the GitHub repository.
  • environmentVariables: A key-value pair of environment variables to be used in the Amplify build.
  • domainName (optional): The custom domain name for the Amplify application.

Usage

Below is an example of how to use the NextJsAmplifySite construct:

import { NextJsAmplifySite, NextJsAmplifySiteProps } from 'path-to-nextjs-amplify-site';
import { App, Stack } from 'aws-cdk-lib';

const app = new App();
const stack = new Stack(app, 'NextJsWebsiteStack');

const siteProps: NextJsAmplifySiteProps = {
  accessTokenName: 'GitHubOAuthToken',
  repoOwner: 'github-username',
  repoName: 'nextjs-repo',
  environmentVariables: {
    NEXT_PUBLIC_API_URL: 'https://api.example.com',
  },
  domainName: 'example.com',
};

new NextJsAmplifySite(stack, 'MyNextJsSite', siteProps);

In this example, a new NextJsAmplifySite construct is created with a specified GitHub repository, environment variables, and a custom domain name.

AWS Resources

  • AWS Amplify Application: Configured with the specified GitHub repository, build specifications, and environment variables.
  • AWS Amplify Branch: A branch named 'main' is created and set as the production branch.
  • Custom IAM Role: A custom IAM role is created with necessary permissions for AWS Amplify.
  • AWS Secrets Manager Secret: Utilized to securely manage the GitHub OAuth token.
  • Custom Domain (optional): Configured with automatic subdomain creation for feature branches if a domain name is provided.

Was this page helpful?