
AWS Ops Agent's code change risk analysis is now GA, so I tried it out on a PR that breaks IAM and alarms #AWSreInvent
This page has been translated by machine translation. View original
Hello, I'm Shunta Toda from the Retail App Co-Creation Department.
At re:Invent 2026, Code Change Risk Analysis for AWS Ops Agent (formerly AWS DevOps Agent) became GA.
It looks at code changes before deployment and checks whether they "break the metrics the alarms are watching" and whether they "stop working under the production IAM policies."
This time, I prepared a code change that deliberately breaks an alarm and IAM permissions, set the feature up from the Management Console, and tried it out.
What is Code Change Risk Analysis?
It learns the code dependencies and application structure from the connected repositories and AWS environment, and checks whether a code change will cause problems in production.
It checks the following three points.
- Whether the code change breaks metrics or alarms
- Whether the changed code stops working under the production IAM policies or resource policies
- Whether the data flow stops in the production environment
When you connect a GitHub or GitLab repository, analysis runs automatically when a PR is created or a commit is pushed (private repositories only).
You can also request an analysis from chat.
This feature was offered in preview under the name "release readiness review," and it was replaced by Code Change Risk Analysis at GA.
The app to try
For testing, I prepared a small CDK app consisting only of a Lambda function that retrieves orders, a DynamoDB table, and a CloudWatch alarm, and deployed it to the Tokyo region.
The Lambda emits a custom metric called OrderErrors on errors, and the alarm monitors that metric.
The Lambda role is given only read permission on the table.
// Orders are only looked up, so read permission only
table.grantReadData(getOrder);
// Alarm that monitors the custom metric emitted by the Lambda
new cloudwatch.Alarm(this, 'OrderErrorsAlarm', {
alarmName: 'order-api-order-errors',
metric: new cloudwatch.Metric({
namespace: 'OrderApi',
metricName: 'OrderErrors',
statistic: 'Sum',
period: Duration.minutes(5),
}),
threshold: 5,
treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
evaluationPeriods: 1,
});
The repository is a private GitHub repository.
Automatic PR analysis targets only private repositories.
Creating an Agent Space
First, open AWS Ops Agent in the Management Console and create an Agent Space.
An Agent Space is a unit that groups the AWS accounts and repositories the agent looks at.
I entered a name and set the agent's response language to Japanese.

For the scope, I chose "Individual accounts," and let the console automatically create the IAM role for the agent.

On the confirmation screen, click "Create Agent Space."

It was created.
After a while, the relationships between the resources in the account are mapped automatically.

Connecting a GitHub repository
In the Agent Space's "Capabilities" tab, click "Add" under "Pipeline."

Select GitHub and click "Register."

I left the connection type as "App registration" and the access permission as the recommended "Read and write."
Write permission is required to add comments to PRs.

When you click "Submit," you are taken to GitHub, where you install the GitHub App. The GitHub App's name is still the old name, AWS DevOps Agent.
For the target, I chose "Only select repositories" and selected just the test repository.

Back in the console, select the repository to connect.

The next screen has "Automatic trigger for change review" and "Automated verification tests."
Both are turned on by default.

In "Advanced settings," you can specify the environment in which verification tests run, and narrow down the branches and events targeted by automatic analysis.
I didn't configure anything this time.

Finally, check "I confirm I want Ops agents to review my pull requests on these repositories." and submit.

The repository was added to the pipeline.

Preparing a change that breaks the alarm and IAM
I changed only the Lambda code as follows. I did not change the CDK side.
- When an order is retrieved, write the last viewed time to the same table (the role only has read permission)
- Change the metric name emitted on errors from
OrderErrorstoOrderLookupFailed(the metric the alarm watches is no longer emitted)
-import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb';
+import { DynamoDBClient, GetItemCommand, UpdateItemCommand } from '@aws-sdk/client-dynamodb';
...
Key: { orderId: { S: event.orderId } },
}));
+
+ // Record the last viewed time if the order is found
+ if (res.Item) {
+ await ddb.send(new UpdateItemCommand({
+ TableName: process.env.TABLE_NAME,
+ Key: { orderId: { S: event.orderId } },
+ UpdateExpression: 'SET lastViewedAt = :now',
+ ExpressionAttributeValues: { ':now': { S: new Date().toISOString() } },
+ }));
+ }
+
return res.Item ?? null;
} catch (e) {
- putMetric('OrderErrors', 1);
+ putMetric('OrderLookupFailed', 1);
throw e;
}
Both look fine when you only look at the code, but they are changes that break once checked against the production IAM policies and alarm settings.
I pushed a branch with this change and created a PR.
Automatic analysis of the PR
When you create a PR, analysis starts automatically.
While the analysis is running, the status aws-devops-agent/code-change-risk-analysis is attached to the PR.

Insufficient IAM permissions
An inline comment marked ⛔ Blocking was added to the changed line (the line that calls UpdateItem).
The Lambda role only has grantReadData, so every time an existing order is retrieved it would result in an AccessDeniedException, the comment points out.
It even includes a fix that changes it to grantReadWriteData in CDK, and a suggestion to separate the write into its own try/catch.

The alarm stops reacting
A comment was also added as an "additional finding in a related file" about the alarm in lib/order-api-stack.ts, which was not changed in the PR.
The Lambda now emits OrderLookupFailed, but the alarm is still watching OrderErrors, so the alarm would no longer fire, the comment points out.
The severity is CRITICAL, and it explained the two problems as connected: "even if a failure occurs due to insufficient IAM permissions, this alarm cannot detect it."

The comment also included the results of the verification tests: even when OrderLookupFailed was emitted 10 times on the error path, 0 data points reached the metric the alarm watches, and the alarm stayed OK.
Status and test report
The analysis finished in about 6 minutes, and the status failed with "change blocked - action required."
The status fails only when the recommended action is BLOCK.
In this repository the status is not set as required, so the PR can still be merged, but if you make it required in branch protection, you can stop the merge.

From the "View test report" comment, you can check the details of the test results in the web app described below.
Trying analysis from chat
Open the web app from "Launch via IAM" at the top right of the Agent Space screen, and you can request an analysis from "Start risk analysis in chat" on the "Changes" page.

When I asked for a production risk analysis in chat, it confirmed the target repository and branch, and then started the analysis.

The analysis finished in about 6 minutes.
Report
The recommended action is "Block," and one critical issue was found.

There were four findings.

Insufficient IAM permissions (CRITICAL)
The Lambda role only has DynamoDB read permission but calls UpdateItem, so retrieving any existing order would fail, the finding points out.
It even showed the grantReadData line in CDK, and proposed changing it to grantReadWriteData and separating the write into its own try/catch.

The alarm stops reacting (LOW)
The alarm monitors OrderErrors, but the code only emits OrderLookupFailed, so the alarm would no longer fire, the finding points out.
It was rated LOW because this alarm has no actions attached, and failures can still be seen in Lambda's standard Errors metric, so the impact is small.
In the automatic PR analysis, the same finding was rated CRITICAL.

In addition, two more LOW findings were raised: "each read adds one write" and "if an order is deleted between the Get and the Update, an incomplete item is created."
The recommendations summarize the fixes.

Tests
The "Tests" tab shows the results of the automated verification tests.
Three tests were created this time, and all of them failed (reproduced the problem).

When you open a test, the test code, commands, and output are kept.
In the IAM test, it extracted the role's policy from the template generated by cdk synth and confirmed that dynamodb:UpdateItem was not included.

Making the output Japanese
Even though I had set the Agent Space's response language to Japanese, the report and PR comments were in English.
In the web app, I opened "Code change risk analysis" from "Agents" and added the following sentence to "Agent instructions (AGENTS.md)" in the agent's definition.
レポート、検出結果、PR のコメントはすべて日本語で書いてください。

When I pushed a commit to the PR and re-ran the analysis, both the inline comments and the report were in Japanese.

Impressions after using it
It checks against production settings
It read the "permissions of the production IAM role" and "the metric the alarm watches," which can't be known from the code diff alone, from the deployed environment and the repository's CDK, and pointed out the problems.
It is specific about why something is a problem
Each finding included the relevant file and line, the steps it checked, and how to fix it, so the content could be fixed as is.
You can make it Japanese with an instruction
Being able to match the review comments to the team's language is helpful.
Summary
I set up Code Change Risk Analysis for AWS Ops Agent from the Management Console and tried it out.
It found both the insufficient IAM permissions and the change to the alarm's metric name before deployment.
It checks for "mismatches with production settings," which are easy to miss in code review, so putting it in front of review should give peace of mind.
It can be used at no additional charge until 2027/02/02, so please give it a try!
References