AWS Amplify CLI Hosting Plugin
This package is a core plugin for the AWS Amplify Command Line Interface (CLI), specifically designed to manage the hosting services for Amplify projects. It empowers developers to seamlessly add, update, push, and remove web hosting capabilities, primarily leveraging services like AWS Amplify Console (for full-stack deployments) or Amazon S3/CloudFront (for static site hosting). While the overall Amplify CLI is in its `v14.x` major version, this specific plugin (`amplify-category-hosting`) is at version `3.4.10`, indicating a stable and less frequently updated internal component. The Amplify CLI generally follows a frequent release cadence, often weekly or bi-weekly, for bug fixes and minor improvements across its various categories. Its key differentiator is deeply integrating hosting with other Amplify backend categories (Auth, API, Storage) and providing a streamlined CI/CD pipeline for frontend web applications, simplifying the deployment process for developers.
Common errors
-
The Amplify Console displays the “build” step of one of your environments as failed and shows other environments as successfully deployed.
cause Inconsistent deployments across environments, often in multi-account or CI/CD pipelines, where one environment fails to update.fixUsing the Amplify CLI, deploy the application specifically in the failing account/environment. Get the App ID from a working environment (e.g., 'dev') and then run `amplify pull --appId <APP_ID> --envName <FAILING_ENV_NAME>` followed by `amplify publish` or `amplify push` in the context of the failing environment. -
Push failures from unmanaged changes to cloud resources - Drift
cause Amplify-managed cloud resources (e.g., DynamoDB tables, Cognito Roles, IAM policies) were modified outside of the Amplify CLI or Amplify Studio, leading to a mismatch between the CloudFormation stack and the actual AWS resources.fixAvoid manual changes to Amplify-generated resources. If drift occurs, `amplify status` might indicate discrepancies. In some cases, `amplify push --force` may help synchronize, but for complex drift, manual intervention to revert changes in the AWS Console to match the CloudFormation template or even recreating the resource might be necessary as a last resort. -
Deployment failed due to build error: The request entity is too large.
cause Your build artifact, particularly for Server-Side Rendered (SSR) applications using AWS Lambda, exceeds the maximum allowed deployment package size (e.g., 50MB for Lambda).fixReduce the size of your deployment artifact. This often involves ensuring that development dependencies are not bundled into the production build, using external modules provided by the Lambda runtime where possible, or excluding large unnecessary files from the deployment package. -
Deployment failed due to build error: 'out of memory' or 'Build timed out'
cause The build process exhausted the memory allocated to the Amplify build container or exceeded the maximum build duration. This is common for large React/Next.js applications.fixIn the Amplify Console, navigate to 'App settings' -> 'Build settings'. Increase the 'Build compute type' from 'Standard' to 'Large' to provide more memory. Also, increase the 'Build timeout' setting to 60 or 120 minutes.
Warnings
- breaking The Amplify CLI introduced a major version `14.0.0` which updated the default Node.js runtime to Node.js 18 and removed support for .NET Core 3.1. Ensure your local environment and Amplify Console build settings match this requirement to avoid build failures.
- gotcha Modifying Amplify-managed cloud resources (e.g., S3 buckets, CloudFront distributions, IAM roles) directly through the AWS Console can cause 'drift' and lead to `amplify push` failures or unexpected behavior during subsequent deployments.
- gotcha When migrating between Amplify CLI major versions or working in multi-account/multi-environment setups, ensure consistent `amplifyconfiguration.json` (or `aws-exports.js`) files across all environments and that build environments have correct credentials. Discrepancies can lead to deployment failures in CI/CD pipelines.
- gotcha Build failures in Amplify Hosting are common and can stem from various issues, including Node.js version mismatches, insufficient memory for large applications, exceeding artifact size limits (especially for SSR apps), or build timeouts.
Install
-
npm install amplify-category-hosting -
yarn add amplify-category-hosting -
pnpm add amplify-category-hosting
Imports
- amplify hosting add
import { addHosting } from 'amplify-category-hosting'amplify hosting add
- amplify hosting push
import { pushHostingChanges } from 'amplify-category-hosting'amplify hosting push
- amplify hosting remove
import { removeHosting } from 'amplify-category-hosting'amplify hosting remove
Quickstart
npx amplify-cli init --amplify-config '{"projectName":"myamplifyapp","envName":"dev","defaultEditor":"code","frontend":"javascript","framework":"react","srcDir":"src","distDir":"build","buildCommand":"npm run-script build","startCommand":"npm run-script start"}' --force
cd myamplifyapp
# Add hosting for a Single Page App (SPA) or PWA
amplify hosting add
# Choose 'Hosting with Amplify Console (Managed hosting and CI/CD)'
# Choose 'Manual deployment'
# Or integrate with a Git repository for continuous deployment.
# After adding hosting and building your frontend, deploy it:
npm run build
amplify publish
# To remove hosting later:
amplify hosting remove