Skip to content

Can't build Gen 2 backend for amplify app

0

I can deploy my amplify app but it creates no backend. No amplify_outputs.json file is created. I get this error in the build log

ERROR] [CDKAssetPublishError] CDK failed to publish assets ∟ Caused by: [ToolkitError] Failed to publish asset data/amplifyData

1 Answer
0

This issue appears to be related to AWS CDK bootstrapping, which is required for Amplify Gen 2 backend deployments.

Based on the error you're seeing, here are some steps to resolve the issue:

  1. Bootstrap your AWS account and region: The error suggests that CDK can't publish assets because your AWS account and region haven't been properly bootstrapped. Run the following command in your terminal:
cdk bootstrap aws://{YOUR_ACCOUNT_ID}/{YOUR_REGION}

Replace the placeholders with your actual AWS account ID and region.

  1. Verify bootstrap status: After running the bootstrap command, check your CloudFormation console in the correct region to confirm a stack named CDKToolkit exists, which indicates successful bootstrapping.

  2. Ensure proper deployment sequence: For Amplify Gen 2, you need to run npx ampx pipeline-deploy during the build phase. Check your amplify.yml file to ensure it includes this command with the correct parameters:

pnpm exec ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
  1. Generate outputs file: The amplify_outputs.json file should be generated during build time using the command mentioned above. This file should be git-ignored as it's environment-specific and will be generated during deployment.

  2. Check region consistency: Ensure the region you bootstrapped matches the region your application is trying to deploy to. You might need to set environment variables like AWS_DEFAULT_REGION to ensure consistency.

If the issue persists, you might need to check your IAM permissions to ensure the deployment role has sufficient permissions to access bootstrap resources.
Sources
ran cdk bootstrap aws://956394424627/us-east-2 successfully but deploy says BootstrapNotDetectedError: This AWS account and region has not been bootstrapped. | AWS re:Post
Is amplify_outputs.json safe in client code + should we gitignore it | AWS re:Post
Encountering an issue while setting up my Amplify Data backend | AWS re:Post
Aws amplify generation 2 backend code not deploy | AWS re:Post

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.