CodePipeline

Simfra's CodePipeline orchestrates multi-stage pipelines with real cross-service integration. Source stages pull from CodeCommit, build stages trigger CodeBuild projects, and deploy stages create CodeDeploy deployments. A background worker advances pipeline execution by polling each action's status.

Prerequisites

  • SIMFRA_DOCKER=true

Create a Pipeline

Save this as pipeline.json:

{
  "pipeline": {
    "name": "my-pipeline",
    "roleArn": "arn:aws:iam::000000000000:role/codepipeline-role",
    "pipelineType": "V2",
    "executionMode": "QUEUED",
    "stages": [
      {
        "name": "Source",
        "actions": [
          {
            "name": "CodeCommitSource",
            "actionTypeId": {
              "category": "Source",
              "owner": "AWS",
              "provider": "CodeCommit",
              "version": "1"
            },
            "outputArtifacts": [
              { "name": "SourceOutput" }
            ],
            "configuration": {
              "RepositoryName": "my-app",
              "BranchName": "main"
            },
            "runOrder": 1
          }
        ]
      },
      {
        "name": "Build",
        "actions": [
          {
            "name": "CodeBuild",
            "actionTypeId": {
              "category": "Build",
              "owner": "AWS",
              "provider": "CodeBuild",
              "version": "1"
            },
            "inputArtifacts": [
              { "name": "SourceOutput" }
            ],
            "outputArtifacts": [
              { "name": "BuildOutput" }
            ],
            "configuration": {
              "ProjectName": "my-build"
            },
            "runOrder": 1
          }
        ]
      },
      {
        "name": "Deploy",
        "actions": [
          {
            "name": "CodeDeploy",
            "actionTypeId": {
              "category": "Deploy",
              "owner": "AWS",
              "provider": "CodeDeploy",
              "version": "1"
            },
            "inputArtifacts": [
              { "name": "BuildOutput" }
            ],
            "configuration": {
              "ApplicationName": "my-app",
              "DeploymentGroupName": "prod"
            },
            "runOrder": 1
          }
        ]
      }
    ],
    "artifactStore": {
      "type": "S3",
      "location": "my-pipeline-artifacts"
    }
  }
}

Create the pipeline:

aws --endpoint-url http://localhost:4599 codepipeline create-pipeline \
  --cli-input-json file://pipeline.json

Creating a pipeline automatically triggers its first execution.

Start an Execution

aws --endpoint-url http://localhost:4599 codepipeline start-pipeline-execution \
  --name my-pipeline

Check Pipeline State

aws --endpoint-url http://localhost:4599 codepipeline get-pipeline-state \
  --name my-pipeline

How Execution Works

A background worker advances pipeline executions:

  1. Stage entry: The worker checks the transition gate (enabled/disabled), then starts all actions in the stage.
  2. Action groups: Actions within a stage are grouped by runOrder. All actions in a group must complete before the next group starts.
  3. Cross-service actions: For CodeBuild and CodeDeploy actions, the worker calls the target service's internal API to start builds/deployments, then polls their status.
  4. Stage completion: When all action groups succeed, the stage is marked as Succeeded and the next stage begins.
  5. Failure: If any action fails, remaining actions in later run-order groups are abandoned, the stage fails, and the execution fails.

Action Provider Behavior

Provider Category Behavior
CodeCommit Source Auto-succeeds (source resolved at pipeline start)
S3 Source Auto-succeeds
CodeBuild Build/Test Starts a real build via InternalStartBuild, polls InternalGetBuildStatus
CodeDeploy Deploy Creates a real deployment via InternalCreateDeployment, polls InternalGetDeploymentStatus
S3 Deploy Auto-succeeds
Manual Approval Blocks until PutApprovalResult is called
Custom/ThirdParty Any Uses the job system (PollForJobs / PutJobSuccessResult)

Execution Modes

V2 pipelines support three execution modes:

  • SUPERSEDED (default for V1): New executions supersede in-progress ones.
  • QUEUED: Executions queue and run in order.
  • PARALLEL: Multiple executions run simultaneously.
{
  "pipeline": {
    "pipelineType": "V2",
    "executionMode": "PARALLEL",
    ...
  }
}

Manual Approval

Add an approval action to pause the pipeline until a human approves:

{
  "name": "Approval",
  "actions": [
    {
      "name": "ManualApproval",
      "actionTypeId": {
        "category": "Approval",
        "owner": "AWS",
        "provider": "Manual",
        "version": "1"
      },
      "configuration": {
        "CustomData": "Please review the deployment"
      },
      "runOrder": 1
    }
  ]
}

Approve or reject:

# Approve
aws --endpoint-url http://localhost:4599 codepipeline put-approval-result \
  --pipeline-name my-pipeline \
  --stage-name Approval \
  --action-name ManualApproval \
  --result summary="Looks good",status=Approved \
  --token <approval-token>

# Reject
aws --endpoint-url http://localhost:4599 codepipeline put-approval-result \
  --pipeline-name my-pipeline \
  --stage-name Approval \
  --action-name ManualApproval \
  --result summary="Issues found",status=Rejected \
  --token <approval-token>

Stage Transitions

Disable a transition to prevent a stage from executing:

aws --endpoint-url http://localhost:4599 codepipeline disable-stage-transition \
  --pipeline-name my-pipeline \
  --stage-name Deploy \
  --transition-type Inbound \
  --reason "Deployment freeze"

Re-enable:

aws --endpoint-url http://localhost:4599 codepipeline enable-stage-transition \
  --pipeline-name my-pipeline \
  --stage-name Deploy \
  --transition-type Inbound

Stop an Execution

# Graceful stop (let current actions finish)
aws --endpoint-url http://localhost:4599 codepipeline stop-pipeline-execution \
  --pipeline-name my-pipeline \
  --pipeline-execution-id <execution-id> \
  --reason "Manual stop"

# Abandon (stop immediately)
aws --endpoint-url http://localhost:4599 codepipeline stop-pipeline-execution \
  --pipeline-name my-pipeline \
  --pipeline-execution-id <execution-id> \
  --abandon \
  --reason "Emergency stop"

EventBridge Events

CodePipeline emits events on every state change:

  • CodePipeline Pipeline Execution State Change - pipeline started, succeeded, failed, stopped
  • CodePipeline Stage Execution State Change - stage started, succeeded, failed
  • CodePipeline Action Execution State Change - action started, succeeded, failed

Use these to trigger downstream automation via EventBridge rules.

Next Steps

  • CodeCommit - host Git repositories for pipeline source stages
  • CodeBuild - build projects for pipeline build stages
  • CodeDeploy - deployment actions for pipeline deploy stages