cd /news/ai-agents/grok-bot-for-read-only-aws-operation… · home › topics › ai-agents › article
[ARTICLE · art-177927] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Grok Bot for read-only AWS operations

A developer built a setup giving xAI's Grok Bot read-only access to an AWS account without long-lived access keys, using a single IAM role that trusts short-lived OIDC tokens minted on the agent machine and exchanged via STS AssumeRoleWithWebIdentity. The same role serves chat questions, scheduled cost and quota reports, and CloudWatch alarm investigations routed through an EventBridge webhook, with the role's trust policy pinned to an exact subject and audience. In a test, an alarm on Step Functions ExecutionsFailed correctly identified a state machine whose only state is Fail and suggested removing or excluding it from the alarm query.

recommendation

Give cloud agents keyless read-only access by trusting an OIDC provider with exact aud and sub conditions, and treat webhook bodies as data, not instructions.

more in playbook: Securing agents and AI tools
by read6 min views1 publishedNov 29, 2026

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.

Questions can be raised in chat. Grok Bot assumes the read-only role and can use any read API that role allows.

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.

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 original post has an interactive version of this diagram. The corner mark on each entry opens that path on its own.

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.

The permissions are on GrokBotOpsReadOnlyRole. The role has the AWS managed policy ReadOnlyAccess, plus two small statements:

ce:Get*, ce:Describe*, and ce:List*. Cost Explorer has no resource-level permissions, so those actions use Resource *. cloudformation:DetectStackDrift and cloudformation:DetectStackResourceDrift on 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.

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.

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.

── more in #ai-agents 4 stories · sorted by recency
── more on @grok bot 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/grok-bot-for-read-on…] indexed:0 read:6min 2026-11-29 · —