Skip to content

Using AWS DevOps Agent with AWS CodePipeline and AWS CodeCommit

6 minute read
Content level: Intermediate
0

Some assume AWS DevOps Agent cannot monitor deployments and correlate code changes when the pipeline is AWS CodePipeline and the repository is AWS CodeCommit, since its documented supported CI/CD providers are GitHub and GitLab. It can. This article shows how the agent reads CodePipeline and correlates a CodeCommit change during an incident investigation

Introduction

When an incident lands, the first question is usually the same: what changed? A large share of production issues trace back to a recent deployment, so the fastest path to a root cause is to line the alarm up with the pipeline run that shipped just before it, and then with the code change that run carried.

Because the documented supported CI/CD providers for AWS DevOps Agent are GitHub and GitLab [1], it is easy to assume the agent cannot monitor deployments or correlate code changes when your pipeline is AWS CodePipeline and your repository is AWS CodeCommit. It can. During an investigation the agent reads CodePipeline and correlates a CodeCommit code change with the incident it is looking at.

The reason is that CodePipeline and CodeCommit are native AWS services. The agent reaches them directly through their AWS APIs, authorized by the IAM permissions on the DevOps Agent service role. An API call with the right permissions is all it takes. No pipeline registration, no repository connection wizard, no custom integration server.

The access model

When you associate an AWS account with an Agent Space and choose to auto-create a new DevOps Agent role, that role is created with the AIDevOpsAgentAccessPolicy managed policy attached. That policy defines the agent's read surface during an investigation, and it includes both CodePipeline and CodeCommit read actions [2]. Because both are native AWS services, the agent invokes their APIs directly under that role. If the pipeline and repository live in an associated account, the agent can read them.

Seeing it in the topology

Before an incident happens, the agent builds a topology of the associated account. In our test environment it looked like this:

topology

The deployment chain is visible end to end: the CodeCommit Source Repository, an EventBridge Source Repo Event Rule that fires on a push, the CI/CD Pipeline, the Build Project, and the Web Service behind its Load Balancer. Those are the neighbors the agent already knows when it investigates the web service, which is why it can walk from a failing service back to the commit that fed it. The bottom row is the trigger path: a 5XX Alarm, an Alarm EventBridge Rule, and an Alarm Trigger Lambda. The alarm side starts the investigation; the deployment side gives it the change history to reason about.

Reading AWS CodePipeline

The policy grants three CodePipeline actions [2], which is enough for the questions that matter during an incident:

ActionWhat it gives the agent
codepipeline:List*Pipelines and their recent executions
codepipeline:GetPipelineStateStage and action states, plus the source revision behind the latest execution
codepipeline:GetPipelineThe pipeline definition: stages, actions, configuration

So when a service is failing, the agent can pull up the pipeline that deploys it, see which stage failed, and identify the execution that shipped the change.

Surfacing AWS CodeCommit code changes

Once the agent knows which execution is implicated, the next question is what code it carried. If the source is CodeCommit in an associated account, the read access is already there.

When you set up the Agent Space and auto-create a new DevOps Agent role, it comes with a full read-only CodeCommit set built in [2]:

"codecommit:BatchDescribe*",
"codecommit:BatchGet*",
"codecommit:Describe*",
"codecommit:EvaluatePullRequestApprovalRules",
"codecommit:GetApprovalRuleTemplate",
"codecommit:GetBranch",
"codecommit:GetComment",
"codecommit:GetCommentReactions",
"codecommit:GetCommentsForComparedCommit",
"codecommit:GetCommentsForPullRequest",
"codecommit:GetCommit",
"codecommit:GetCommitHistory",
"codecommit:GetCommitsFromMergeBase",
"codecommit:GetDifferences",
"codecommit:GetMergeCommit",
"codecommit:GetMergeConflicts",
"codecommit:GetMergeOptions",
"codecommit:GetObjectIdentifier",
"codecommit:GetPullRequest",
"codecommit:GetPullRequestApprovalStates",
"codecommit:GetPullRequestOverrideState",
"codecommit:GetReferences",
"codecommit:GetRepository",
"codecommit:GetRepositoryTriggers",
"codecommit:GetTree",
"codecommit:GetUploadArchiveStatus",
"codecommit:List*"

The change-correlation actions are all there: GetCommit, GetCommitHistory, GetDifferences, GetPullRequest, GetBranch, GetRepository, BatchGet*, List*. With those, the agent can look up a commit, walk recent history, list which files changed between two commits, and read pull request metadata. In our testing, once an execution was tied to a source revision, the agent pulled that commit, diffed it against its parent to find the changed files, and reasoned about the change against the symptoms in metrics and logs. That is what turns "the service started failing" into "the service started failing right after this change."

The prerequisite for reading file content

The default set lets the agent see which files changed, but not read their raw content. Two more actions are the prerequisite, and neither is in the auto-created block:

  • codecommit:GetBlob: raw blob content for a changed file by blob ID
  • codecommit:GetFile: full file content and metadata at a specific commit

Add them to the DevOps Agent service role for the agent to open the changed files.

In our testing, with these actions granted the agent read the before and after of the changed file and quoted the one-line change that caused the outage. That is the two-tier story: metadata correlation points at the commit; the two file-content actions let the agent open it and read the exact line.

Example root cause surfacing CodeCommit

devops-agent-rca

Summary

The short version: a GitHub or GitLab pipeline is not a requirement for DevOps Agent to monitor deployments and correlate code changes. It does the same job on an AWS-native CodePipeline and CodeCommit stack, and it does not need either one registered as an integration. It reads them through the DevOps Agent service role, which lets it find the pipeline that deploys a failing service, identify the execution and its source revision, and line the corresponding CodeCommit commit up against the incident.

One thing to plan around: reading raw file content, not just the list of changed files, needs codecommit:GetBlob and codecommit:GetFile added to the role. The metadata read access that gets you to the commit is already there; those two actions are what let the agent open the file and read the exact change.

References

  1. Connecting to CI/CD pipelines, AWS DevOps Agent User Guide: https://docs.aws.amazon.com/devopsagent/latest/userguide/configuring-integrations-and-knowledge-connecting-to-cicd-pipelines-index.html
  2. AIDevOpsAgentAccessPolicy, AWS Managed Policy Reference (version 10): https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AIDevOpsAgentAccessPolicy.html