Lesson 4 of 5 Kiro and AI-Assisted Development

Using AI Tools for Reviews, Approvals and Validation in CI/CD Pipelines

This lesson explains how to run the Kiro CLI in headless mode in a pipeline and how AI steps support deployment approvals, environment provisioning and post-deployment validation without replacing deterministic gates.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how headless mode authenticates and how tool permissions are granted.
  • Explain why AI should inform, not make, production release decisions.
  • Describe how AI-drafted infrastructure is reviewed and deployed safely.
  • Identify the controls that govern AI steps in a pipeline.

Kiro CLI in headless mode

A pipeline has no person to sign in or approve each step, so the Kiro CLI provides a headless mode. The command kiro-cli chat --no-interactive takes a prompt as an argument or on standard input, runs it to completion and exits. Authentication uses an API key in the KIRO_API_KEY environment variable, available on paid subscriptions and, for managed subscriptions, only when an administrator allows it.

Because no one is present to approve tool calls, permissions are granted up front. --trust-tools approves only the listed tools, such as read_file and grep_search, which suits a reviewer that must not change the repository; --trust-all-tools approves everything and should be used only in an isolated environment. The following CodeBuild buildspec.yml reviews a change and keeps the output as a build artifact. CodeBuild reads the key from Secrets Manager, so it never appears in the repository or the logs.

version: 0.2
env:
  secrets-manager:
    KIRO_API_KEY: ci/kiro-api-key
phases:
  install:
    commands:
      - curl -fsSL https://cli.kiro.dev/install | bash
  build:
    commands:
      - >
        kiro-cli chat --v3 --no-interactive --trust-tools=read_file,grep_search
        "Review the changes in this commit for security issues and missing error handling.
        List each finding with file, line and severity." | tee review.md
artifacts:
  files:
    - review.md

Automated deployment approvals

An approval gate decides whether a release may proceed. AI can make that decision easier, but it should not make it alone, because a model's judgement is not deterministic and can be manipulated by the content it reviews. A sound design separates the two roles.

  • Deterministic gates decide automatically: unit and integration tests pass, coverage is above the threshold, scanners report no critical findings, and alarms are quiet after the canary.
  • AI assistance informs the decision: a Kiro review or a Lambda invoke action that calls Amazon Bedrock summarises what changed, its risk and the test results.
  • A CodePipeline manual approval action before production shows that summary through its comments and link, and an authorised person approves or rejects.

For low-risk environments such as development, the pipeline can promote automatically when every deterministic gate passes, so the AI summary is only advisory.

Sort into groups

Who decides?

Exam skills 3.3.9

Separate the roles of deterministic gates, AI assistance and people.

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

Environment provisioning and post-deployment validation

Environment provisioning creates the resources a test or feature environment needs. An AI agent can draft the AWS CDK, CloudFormation or AWS SAM code from a spec, following steering rules such as "encrypt every table with the team's KMS key and tag every resource with the cost centre". The draft goes through the normal process: commit, review, cfn-lint and a change set, then deployment by the pipeline's role. The agent never deploys with broad personal credentials.

Post-deployment validation checks that the new version works in its real environment. AI tools can generate smoke tests and CloudWatch Synthetics canary scripts from the API definition. The pipeline runs them after deployment, or a CodeDeploy AfterAllowTraffic hook runs them during a canary, and CloudWatch alarms on errors and latency trigger an automatic rollback. If an alarm fires, CloudWatch investigations can correlate it with the deployment and suggest a cause.

Governing AI steps

An AI step in a pipeline is a privileged automation, so it is governed like one. The following controls apply.

  • Least-privilege roles and tool permissions: a reviewer reads; it does not push, merge or deploy.
  • Secrets such as KIRO_API_KEY stored in Secrets Manager and injected at run time.
  • A time limit on every job, so a stuck agent cannot hold the pipeline.
  • Prompts and outputs logged for audit, with sensitive data masked.
  • A human approval before production for any change that an agent proposed.
Scenario questions

Govern the AI step

Exam skills 3.3.9

Practise controls for AI steps in a pipeline.

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

An AI-assisted release pipeline

A team wants an automated security review of each change, a readable risk summary for the release manager, and confidence that production is healthy after release.

The pipeline's build stage runs unit tests, the scanners and headless Kiro with read-only tools, storing review.md as an artifact. A critical finding fails the build through a small script that parses the review.

Before production, a Lambda invoke action sends the diff summary, test results and review to Amazon Bedrock and attaches the generated risk summary to a manual approval action. After approval, CodeDeploy shifts traffic with a canary configuration, a CloudWatch Synthetics canary runs in the AfterAllowTraffic hook, and an alarm on the 5xx rate rolls the release back automatically if errors rise.

Check yourself

Why should a headless Kiro reviewer run with --trust-tools rather than --trust-all-tools?

Show answer

--trust-tools approves only the listed tools, so a read-only reviewer cannot change files or run commands even if the content it reviews tries to instruct it to.

Exam Tips

Remember for the exam

  • Run Kiro in a pipeline without a person: kiro-cli chat --no-interactive with KIRO_API_KEY.
  • Allow a pipeline agent only to read code: --trust-tools with read-only tools.
  • Store the API key in Secrets Manager and inject it with the buildspec secrets-manager section.
  • AI summarises; deterministic gates and a manual approval action decide production releases.
  • Validate after deployment with canaries and alarms that trigger automatic rollback.