Lesson 4 of 4 Secure Access, GenAI Gateways and CI/CD

Delivering Generative AI Components Through CI/CD Pipelines

This lesson describes pipelines that move prompts, model configurations, guardrails, knowledge base settings, agent definitions and evaluation datasets through automated quality and safety tests with rollback.

Learning outcomes

After completing this lesson, you will be able to:

  • Version every deployable artefact.
  • Test generative AI components in layers.
  • Deploy with gradual traffic shifting and roll back on failure.

What goes through the pipeline

Every deployable artefact is versioned in source control: application and tool code, infrastructure as code (AWS CDK or CloudFormation) for knowledge bases, agents, guardrails and gateways, prompt templates, routing configuration and evaluation datasets. AWS CodePipeline starts on a commit and runs stages; AWS CodeBuild runs build and test commands in managed containers; AWS CodeArtifact hosts approved packages; Amazon ECR stores container images with image scanning; AWS CloudFormation or CDK deploys infrastructure; AWS CodeDeploy shifts Lambda and ECS traffic gradually.

Put in order

A GenAI release pipeline

Exam skills 2.3.5

Put the stages of a CodePipeline release for a GenAI application in order.

Log in to try this activity Interactive activities are free with an account.

Automated testing for GenAI

Tests run in layers. Unit tests check tool functions and parsing with mocked model responses. Prompt regression tests run golden datasets against the candidate prompt or model and compare scores with the production baseline, using deterministic checks and LLM judges, or Bedrock evaluation jobs started from CodeBuild. Safety tests run adversarial prompts (jailbreaks, prompt injection, PII extraction) and verify that guardrails block them. Integration tests call the deployed staging stack end to end, and performance tests check latency and token usage against budgets.

Security scans run alongside: dependency vulnerability scanning, secret detection, container image scanning in ECR, and infrastructure as code policy checks (for example that knowledge bases use KMS encryption and that roles are not overly broad).

# buildspec.yml (evaluation stage)
version: 0.2
phases:
  install:
    commands:
      - pip install -r tests/requirements.txt
  build:
    commands:
      - pytest tests/unit
      - python tests/run_golden_set.py --prompt-arn "$CANDIDATE_PROMPT_ARN" --out results.json
      - python tests/compare_to_baseline.py results.json --min-faithfulness 0.90 --max-regression 0.02
      - python tests/run_red_team.py --guardrail "$GUARDRAIL_ID" --max-attack-success 0.01

The following diagram shows the pipeline stages that would have caught a harmful prompt change before release.

A pipeline that would have caught the prompt change. A red-team safety stage probes for internal information and a golden-set regression stage compares against the baseline, both in CodeBuild, before a canary release with alarms on guardrail interventions. The agent alias can be moved back to the previous version immediately.
Prompt and agent versions are immutable, so the previous version is always available.
Match the pairs

Test layers

Exam skills 2.3.5 · 5.1.4

Match each test layer in a GenAI pipeline with what it checks.

Log in to try this activity Interactive activities are free with an account.

Deployment strategies and rollback

Deployments go to staging first, then to production with gradual traffic shifting: CodeDeploy canary or linear deployments for Lambda functions and ECS services with CloudWatch alarms that trigger automatic rollback; alias updates for Bedrock agents, flows and prompt versions; AppConfig deployment strategies for routing and model configuration. Manual approval actions gate production for high-risk changes. Because previous versions of prompts, agents and flows are immutable, rolling back is a matter of pointing aliases or configuration back. The following table summarises the stages.

StageChecksTools
BuildUnit tests, dependency and secret scans, IaC checksCodeBuild, CodeArtifact, ECR scanning
EvaluateGolden-set regression, LLM-judge quality, red-team safetyCodeBuild, Bedrock evaluations
StagingIntegration and performance testsCloudFormation or CDK, CodeBuild
ApproveManual approval for high-risk changesCodePipeline approval action
ProductionCanary with alarms and automatic rollbackCodeDeploy, aliases, AppConfig
Worked example

A prompt change that slipped through

A prompt edit deployed directly to production made a support agent reveal internal escalation procedures to customers. The company wants such changes caught automatically and reverted quickly.

The pipeline should include a red-team safety stage with prompts that probe for internal information and a golden-set regression stage, both in CodeBuild, before a canary release with alarms on guardrail interventions; the agent alias can be moved back to the previous version immediately.

Check yourself

Which generative AI components should be versioned like code?

Show answer

Prompts, guardrails, agent definitions, configuration and evaluation data.

Exam Tips

Remember for the exam

  • Version prompts, guardrails, agents, configuration and evaluation data like code.
  • Pipeline stages: unit tests, scans, golden-set regression, red-team safety, staging tests.
  • Canary deployments with alarms give automatic rollback.
  • Roll back prompts, agents and flows by moving aliases to previous versions.