AWS CDK Amplify Alpha

2.250.0a0 · active · verified Thu Apr 16

The `aws-cdk-aws-amplify-alpha` library provides experimental higher-level constructs (L2 and L3) for provisioning AWS Amplify applications using the AWS Cloud Development Kit (CDK). As an alpha module, its APIs are under active development and are subject to non-backward compatible changes or removal in future versions, not adhering to strict Semantic Versioning. It enables a Git-based workflow for deploying and hosting full-stack serverless web applications. The current version is `2.250.0a0`, typically mirroring the `aws-cdk-lib` release cadence with an alpha qualifier.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create an AWS Amplify App using the `aws-cdk-aws-amplify-alpha` library. It sets up a GitHub-connected application with a basic build specification. Ensure you have your GitHub OAuth token stored in AWS Secrets Manager and your `GITHUB_OWNER` and `GITHUB_REPO` environment variables set. You will also need to have `aws-cdk-lib` and `aws-cdk.aws-codebuild` installed.

import os
from aws_cdk import (
    App, Stack, SecretValue
)
from aws_cdk import aws_amplify_alpha as amplify
from aws_cdk import aws_codebuild as codebuild

class AmplifyStack(Stack):
    def __init__(self, scope: App, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        github_token = SecretValue.secrets_manager("my-github-token") # Store your GitHub token in AWS Secrets Manager
        github_owner = os.environ.get('GITHUB_OWNER', 'your-github-username')
        github_repo = os.environ.get('GITHUB_REPO', 'your-amplify-repo')

        amplify_app = amplify.App(
            self, "MyApp",
            source_code_provider=amplify.GitHubSourceCodeProvider(
                owner=github_owner,
                repository=github_repo,
                oauth_token=github_token
            ),
            build_spec=codebuild.BuildSpec.from_object_to_yaml({
                "version": "1.0",
                "frontend": {
                    "phases": {
                        "preBuild": {
                            "commands": ["yarn"]
                        },
                        "build": {
                            "commands": ["yarn build"]
                        }
                    },
                    "artifacts": {
                        "baseDirectory": "public",
                        "files": ["**/*"]
                    }
                }
            })
        )

        amplify_app.add_branch("main")

app = App()
AmplifyStack(app, "AmplifyQuickstartStack",
             env={'account': os.environ.get('CDK_DEFAULT_ACCOUNT'), 'region': os.environ.get('CDK_DEFAULT_REGION')})
app.synth()

view raw JSON →