Skip to content

Commit 1f6a2f2

Browse files
committed
feat(payments): grant runtime role payment data-plane perms + system prompt update
The deployed agent runtime role was missing every Get/List/Create payment instrument+session action and ProcessPayment. The L3 stack only granted sts:AssumeRole on the ProcessPaymentRole, which carries only ProcessPayment — and the SDK plugin's auto-pay path calls GetPaymentInstrument on the runtime's own credentials before any role assumption. Without this grant the plugin fails with AccessDeniedException on the very first 402 it tries to settle. Add the seven required actions to the runtime role's inline policy in the vended CDK stack template (src/assets/cdk/lib/cdk-stack.ts). Scoped to the manager ARN. Also update PAYMENT_SYSTEM_PROMPT in the Strands payments capability to mention the http_request tool, which the AgentCorePaymentsPlugin now provides automatically (see SDK PR aws/bedrock-agentcore-sdk-python#493). The other prompt lines for get_payment_session / get_payment_instrument_balance / list_payment_instruments are unchanged — those tools were already provided by the plugin. Snapshot updated to reflect the cdk-stack.ts addition.
1 parent c31e6d7 commit 1f6a2f2

3 files changed

Lines changed: 54 additions & 2 deletions

File tree

src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,32 @@ export class AgentCoreStack extends Stack {
409409
})
410410
);
411411
412+
// Grant payment data-plane actions directly to the runtime role.
413+
//
414+
// NOTE: This deviates from the canonical role model in the AgentCore Payments
415+
// beta guide, which assigns Get/List/Create instrument+session actions to a
416+
// separate ManagementRole and limits the agent's role to ProcessPayment only.
417+
// The current SDK plugin (AgentCorePaymentsPlugin.generate_payment_header)
418+
// calls GetPaymentInstrument internally during the 402 auto-pay path, so the
419+
// runtime role needs read access. CreatePaymentSession is included so
420+
// \`agentcore invoke --auto-session\` works without a separate ManagementRole
421+
// call. Tighten this if the SDK is updated to accept pre-fetched instrument
422+
// details and split create-session into a backend-only flow.
423+
env.runtime.role.addToPrincipalPolicy(
424+
new iam.PolicyStatement({
425+
actions: [
426+
'bedrock-agentcore:GetPaymentInstrument',
427+
'bedrock-agentcore:ListPaymentInstruments',
428+
'bedrock-agentcore:GetPaymentInstrumentBalance',
429+
'bedrock-agentcore:GetPaymentSession',
430+
'bedrock-agentcore:ListPaymentSessions',
431+
'bedrock-agentcore:CreatePaymentSession',
432+
'bedrock-agentcore:ProcessPayment',
433+
],
434+
resources: [manager.paymentManagerArn, \`\${manager.paymentManagerArn}/*\`],
435+
})
436+
);
437+
412438
if (payment.autoPayment !== undefined) {
413439
env.runtime.addEnvironmentVariable(\`\${prefix}_AUTO_PAYMENT\`, String(payment.autoPayment));
414440
}
@@ -5399,7 +5425,7 @@ logger = logging.getLogger(__name__)
53995425
54005426
PAYMENT_SYSTEM_PROMPT = """
54015427
You have payment capabilities via the x402 protocol:
5402-
- Payments are processed automatically when you access paid endpoints (HTTP 402 responses)
5428+
- Use http_request to call HTTP endpoints. 402 Payment Required responses are settled automatically by the plugin and the call is retried.
54035429
- Use get_payment_session to check your remaining budget before expensive operations
54045430
- Use get_payment_instrument_balance to check wallet USDC balance
54055431
- Use list_payment_instruments to see available payment instruments

src/assets/cdk/lib/cdk-stack.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,32 @@ export class AgentCoreStack extends Stack {
134134
})
135135
);
136136

137+
// Grant payment data-plane actions directly to the runtime role.
138+
//
139+
// NOTE: This deviates from the canonical role model in the AgentCore Payments
140+
// beta guide, which assigns Get/List/Create instrument+session actions to a
141+
// separate ManagementRole and limits the agent's role to ProcessPayment only.
142+
// The current SDK plugin (AgentCorePaymentsPlugin.generate_payment_header)
143+
// calls GetPaymentInstrument internally during the 402 auto-pay path, so the
144+
// runtime role needs read access. CreatePaymentSession is included so
145+
// `agentcore invoke --auto-session` works without a separate ManagementRole
146+
// call. Tighten this if the SDK is updated to accept pre-fetched instrument
147+
// details and split create-session into a backend-only flow.
148+
env.runtime.role.addToPrincipalPolicy(
149+
new iam.PolicyStatement({
150+
actions: [
151+
'bedrock-agentcore:GetPaymentInstrument',
152+
'bedrock-agentcore:ListPaymentInstruments',
153+
'bedrock-agentcore:GetPaymentInstrumentBalance',
154+
'bedrock-agentcore:GetPaymentSession',
155+
'bedrock-agentcore:ListPaymentSessions',
156+
'bedrock-agentcore:CreatePaymentSession',
157+
'bedrock-agentcore:ProcessPayment',
158+
],
159+
resources: [manager.paymentManagerArn, `${manager.paymentManagerArn}/*`],
160+
})
161+
);
162+
137163
if (payment.autoPayment !== undefined) {
138164
env.runtime.addEnvironmentVariable(`${prefix}_AUTO_PAYMENT`, String(payment.autoPayment));
139165
}

src/assets/python/http/strands/capabilities/payments/payments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
PAYMENT_SYSTEM_PROMPT = """
2828
You have payment capabilities via the x402 protocol:
29-
- Payments are processed automatically when you access paid endpoints (HTTP 402 responses)
29+
- Use http_request to call HTTP endpoints. 402 Payment Required responses are settled automatically by the plugin and the call is retried.
3030
- Use get_payment_session to check your remaining budget before expensive operations
3131
- Use get_payment_instrument_balance to check wallet USDC balance
3232
- Use list_payment_instruments to see available payment instruments

0 commit comments

Comments
 (0)