Amplify Toolbox
    Preparing search index...

    Function definePipeline

    • Define a CI/CD pipeline for Amplify applications.

      Creates a self-mutating CodePipeline V2 that deploys through the configured stages. Each branch gets its own independent pipeline.

      The pipeline uses a two-phase deployment per stage:

      1. Backend deploy — CloudFormation stacks (Cognito, AppSync, DynamoDB, etc.) deployed via CDK Pipelines' native stage mechanism.
      2. Hosting deploy — A post-deploy CodeBuild step that mirrors ampx deploy: generates amplify_outputs.json from the deployed backend, builds the frontend (so amplify_outputs.json is baked into Lambda bundles for SSR), then deploys hosting via cdk deploy.

      This two-phase approach ensures amplify_outputs.json is available during the frontend build — the same ordering that ampx deploy provides locally.

      Use getStageConfig() inside hosting.ts/backend.ts to read per-stage configuration during synthesis.

      Parameters

      • props: DefinePipelineProps

        Pipeline configuration including source, synth, and branch/stage definitions.

      Returns void

      import { definePipeline } from '@aws-amplify/hosting/pipeline';

      definePipeline({
      source: {
      repo: 'my-org/my-app',
      connectionArn: 'arn:aws:codeconnections:us-east-1:123456789:connection/aaaaaaaa-1111-2222-3333-bbbbbbbbbbbb',
      },
      branches: [
      {
      branch: 'main',
      stages: [
      { name: 'beta' },
      { name: 'prod', requireApproval: true },
      ],
      },
      ],
      });
      // amplify/hosting.ts
      import { defineHosting, getStageConfig } from '@aws-amplify/hosting';

      const stage = getStageConfig<{ domain: string }>();
      defineHosting({
      framework: 'spa',
      domain: stage?.config?.domain,
      });