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.
A GenAI release pipeline
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.01The following diagram shows the pipeline stages that would have caught a harmful prompt change before release.

Test layers
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.
| Stage | Checks | Tools |
|---|---|---|
| Build | Unit tests, dependency and secret scans, IaC checks | CodeBuild, CodeArtifact, ECR scanning |
| Evaluate | Golden-set regression, LLM-judge quality, red-team safety | CodeBuild, Bedrock evaluations |
| Staging | Integration and performance tests | CloudFormation or CDK, CodeBuild |
| Approve | Manual approval for high-risk changes | CodePipeline approval action |
| Production | Canary with alarms and automatic rollback | CodeDeploy, aliases, AppConfig |
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.
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.