AWS CDK Amplify Alpha
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
-
This AWS account and region has not been bootstrapped. Caused By: Is account *********** bootstrapped Resolution: Run `cdk bootstrap aws://{YOUR_ACCOUNT_ID}/{YOUR_REGION}` locally to resolve this.cause The AWS CDK requires your environment (AWS account and region) to be bootstrapped before deploying resources, which creates a `CDKToolkit` stack with necessary resources like an S3 bucket for assets and IAM roles.fixRun `cdk bootstrap aws://<YOUR_AWS_ACCOUNT_ID>/<YOUR_AWS_REGION>` in your terminal, replacing placeholders with your actual AWS account ID and region. Ensure your IAM user/role has permissions to perform bootstrapping operations. -
You don't have permissions to perform this action. Verify that your IAM policy includes the required permissions.
cause The IAM user or role executing the CDK deployment lacks the necessary permissions to create, update, or delete the AWS resources defined in the Amplify stack.fixReview the CloudFormation stack events in the AWS console for specific `AccessDenied` errors to identify missing permissions. Grant the required IAM permissions to the deploying entity. Ensure the OAuth token used for source control (e.g., GitHub) has appropriate repository access scopes. -
Cannot find entry file at C:\Users\user1\AppData\Local\Temp\jsii-kernel-1N88ev\node_modules@aws-cdk\custom-resource-handlers\dist\aws-amplify-alpha\asset-deployment-handler\index.js
cause This error, particularly observed with `amplify_app.add_branch` when deploying from assets, indicates a potential missing internal dependency related to custom resource handlers.fixThis issue might be version-specific or require specific transitive dependencies. Ensure your `aws-cdk-lib` and `aws-cdk.aws-amplify-alpha` versions are compatible. If the issue persists, check the official AWS CDK GitHub issues for `aws-amplify-alpha` regarding asset deployment or `add_branch` for updates or workarounds. This might require updating `npm` packages within the CDK toolkit environment if it's a `jsii`-related problem.
Warnings
- breaking As an `alpha` module, the APIs are experimental and subject to non-backward compatible changes or removal in any future version, without adhering to Semantic Versioning.
- breaking A recent breaking change affects compute role creation when the `platform` property is set to `Platform.WEB_COMPUTE` or `Platform.WEB_DYNAMIC`, leading to the creation of a compute role.
- gotcha When fetching an existing Amplify app using `amplify.App.from_app_id()`, the returned object (`IApp`) provides a read-only reference. You cannot use it to modify the existing Amplify App, such as adding domains or branches directly through this imported reference.
Install
-
pip install aws-cdk.aws-amplify-alpha
Imports
- App
from aws_cdk.aws_amplify import App
from aws_cdk import aws_amplify_alpha as amplify amplify_app = amplify.App(...)
- GitHubSourceCodeProvider
from aws_cdk import aws_amplify_alpha as amplify provider = amplify.GitHubSourceCodeProvider(...)
Quickstart
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()