Grok Bot is an agent with a cloud computer. You ask it in chat, and it can run routines on a schedule or from a webhook. This post gives that Bot read-only access to an AWS account, with no access key. One IAM role trusts an OIDC token, and that role cannot change the account. Three uses share it: a question in chat, a report from a routine, and a written report when a CloudWatch alarm fires.
Ask a question about the account
Questions can be raised in chat. Grok Bot assumes the read-only role and can use any read API that role allows.
Get a report from a Grok Bot routine
A routine runs on a schedule, uses the same role, and posts the report in chat. The schedule belongs to the routine. It is not an EventBridge rule, and the routine does not get a second role.
A report can be current costs, or a specific metric such as API quotas.
React when an alarm is raised
A CloudWatch alarm that enters ALARM is posted by an EventBridge connection to a Grok Bot webhook. The routine investigates and replies with what fired, the evidence, a likely cause, a suggested fix, and how urgent it is. The webhook body is data, not instructions.
SFN-Alarm watches ExecutionsFailed across Step Functions state machines, from One CloudWatch alarm for many resources. Set to ALARM with no failed executions, the report called it a manual test. A later execution failed because the state machine's only state is Fail. It was started from the console, failed after 38 ms, and the alarm entered ALARM one minute later. The report named that state machine and suggested removing it or excluding it from the alarm query.
The three paths together
The original post has an interactive version of this diagram. The corner mark on each entry opens that path on its own.
Into AWS with IAM OIDC
The bot does not hold an access key. It mints an OIDC token on the agent machine, then passes that token to STS. The mint is a POST to the local socket, with audience sts.amazonaws.com, as documented in OIDC tokens for cloud agents:
curl --unix-socket "${CURSOR_AGENT_SOCKET}" \
-H 'Content-Type: application/json' \
-d '{"aud":"sts.amazonaws.com"}' \
http://cursor-agent/v1/tokens/oidc
The JWT is valid for about 5 minutes. It is only used at assume time. The bot then calls STS, and the one hour is the STS session (maxSessionDuration on the role, --duration-seconds 3600 on the call):
aws sts assume-role-with-web-identity \
--role-arn "$GROK_BOT_OPS_READ_ONLY_ROLE_ARN" \
--role-session-name grok-bot-ops \
--web-identity-token "$OIDC_TOKEN" \
--duration-seconds 3600
The issuer is https://api.cursor.com. The audience is sts.amazonaws.com. Discovery is https://api.cursor.com/.well-known/openid-configuration. GrokBotOpsReadOnlySetup imports that provider and creates GrokBotOpsReadOnlyRole in AccountSetupStack (us-east-1). Trust is sts:AssumeRoleWithWebIdentity with two StringEquals conditions: api.cursor.com:aud is sts.amazonaws.com, and api.cursor.com:sub is one exact subject. A wildcard, a question mark, or whitespace fails synthesis. The tanstack-aws deployment reads that subject from API_CURSOR_SUB in the envs secret in Secrets Manager (us-east-2), so the value is not in git.
this.oidcProvider = OidcProviderNative.fromOidcProviderArn(
this,
"Provider",
oidcProviderArn(props.config.oidcUrl),
);
this.role = new Role(this, "Role", {
roleName: "GrokBotOpsReadOnlyRole",
maxSessionDuration: Duration.hours(1),
assumedBy: new WebIdentityPrincipal(this.oidcProvider.openIdConnectProviderArn, {
StringEquals: {
[`${issuerHost}:aud`]: props.config.oidcAudience,
[`${issuerHost}:sub`]: allowedSubject,
},
}),
});
Grok Bot agents share one computer. Any agent on that computer can mint a token for the trusted subject and assume the role. The trust policy matches the subject, not an agent. There is no control today that limits the role to one agent. The role stays read-only for that reason.
What the role can read
The permissions are on GrokBotOpsReadOnlyRole. The role has the AWS managed policy ReadOnlyAccess, plus two small statements:
- Cost Explorer:
ce:Get*,ce:Describe*, andce:List*. Cost Explorer has no resource-level permissions, so those actions useResource *. - CloudFormation drift:
cloudformation:DetectStackDriftandcloudformation:DetectStackResourceDrifton stacks in this account. Starting a drift check does not change the stack.
An explicit deny, DENY_SECRET_AND_DATA_READS, blocks the reads that would return secret or data-plane values: Secrets Manager secret values, SSM parameter values, kms:Decrypt, EC2 passwords, ECR authorization tokens, S3 object bytes, DynamoDB items, the RDS Data API, the Redshift Data API, and Lambda function code and configuration. Describe and list stay allowed, including secretsmanager:DescribeSecret and secretsmanager:ListSecrets.
this.role.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName("ReadOnlyAccess"));
this.role.addToPolicy(
new PolicyStatement({
sid: "DenySecretAndDataPlaneReads",
effect: Effect.DENY,
actions: DENY_SECRET_AND_DATA_READS,
resources: ["*"],
}),
);
Log groups that use the default CloudWatch Logs encryption stay readable. A log group encrypted with a customer key needs kms:Decrypt, which this role denies. The alarm routine's first call after assuming the role is DescribeAlarms, to confirm the credentials and to read the alarm that fired.
From AWS through EventBridge
GrokBotAlarmForwarding runs in the workload region, us-east-2. CloudWatch publishes the state change on the event bus in the alarm's region, so an alarm in us-east-1 (a billing alarm, for example) is not forwarded. The rule matches every alarm in the region that enters ALARM, not a named list.
The connection sends Authorization: Bearer <token>. EventBridge connections have no native Bearer auth type, so the Bearer prefix is part of the API-key value. The API destination POSTs the event to the webhook. Both values are CloudFormation dynamic references to keys on the envs secret. Neither is read at synth time.
| Key | Use |
|---|---|
GROK_BOT_ALARM_WEBHOOK_URL |
Endpoint of the API destination. |
GROK_BOT_ALARM_WEBHOOK_TOKEN |
Bearer token on the EventBridge connection. |
const bearerToken = SecretValue.unsafePlainText(
`Bearer ${envsSecretValue(GROK_BOT_ALARM_WEBHOOK_TOKEN_KEY)}`,
);
const connection = new events.Connection(this, "Connection", {
connectionName: "GrokBotAlarmWebhook",
authorization: events.Authorization.apiKey("Authorization", bearerToken),
});
const apiDestination = new events.ApiDestination(this, "Destination", {
apiDestinationName: "GrokBotAlarmWebhook",
connection,
endpoint: webhookUrl,
httpMethod: events.HttpMethod.POST,
rateLimitPerSecond: 1,
});
this.rule = new events.Rule(this, "AlarmRule", {
ruleName: "GrokBotAlarmStateChange",
eventPattern: {
source: ["aws.cloudwatch"],
detailType: ["CloudWatch Alarm State Change"],
detail: { state: { value: ["ALARM"] } },
},
targets: [
new targets.ApiDestination(apiDestination, {
deadLetterQueue: this.deadLetterQueue,
retryAttempts: 185,
maxEventAge: Duration.hours(24),
}),
],
});
EventBridge retries for 24 hours (185 attempts), then sends the event to GrokBotAlarmForwardingDlq.
Compared with CloudWatch investigations
CloudWatch investigations is the generative AI assistant in CloudWatch. The service quotas list it as Amazon AI Operations. It scans telemetry for an incident and suggests observations, hypotheses, and possible causes. An investigation can start from the console or from an alarm. With an investigation group configured, it can also take extra telemetry, notes, cross-account data, and suggested Systems Manager Automation runbooks. Without that configuration it uses the signed-in user's permissions, and the result stays on that user's session.
| Grok Bot | CloudWatch investigations | |
|---|---|---|
| Access | One read-only role. OIDC, no access key. Secret and data-plane reads are denied. | The signed-in user's permissions, until an investigation group is configured. |
| How it starts | A chat question, a routine on a schedule, or an EventBridge webhook when an alarm enters ALARM. |
The console or an alarm. A configured group can share the investigation in the account. |
| What it changes | Nothing. It can suggest a fix. | It can suggest an Automation runbook. Running that runbook is a separate step. |
| Scope | Any read the role allows, including questions and scheduled reports. | Telemetry related to the investigation. One investigation group per account per Region, 2 concurrent AI analyses, and 150 AI-assisted investigations per month. |
| Who can use it | Every Grok Bot agent on the shared computer. The role cannot be limited to one agent. | An unconfigured investigation stays with the signed-in user. A configured one is available to permitted users in the account. |
Grok Bot is the place for a question, a scheduled report, and a chat reply when an alarm fires. CloudWatch investigations is the place for an incident review inside the AWS console, with the option to accept or discard suggestions and to run a runbook.











Top comments (0)