AI 日报hiw3c.com

在AWS上实现Claude平台的多环境访问

原文标题 · Implementing Multi-Environment Access for Claude Platform on AWS
AWS ML Blog aws.amazon.com RSS 全文
正文为英文,可一键机器翻译(仅首次需要等待)

You need Claude Platform on AWS (CPonAWS) inference from three environments: production workloads on AWS, developer laptops for local iteration, and external services on other cloud providers or on-premises continuous integration and continuous delivery (CI/CD) pipelines. Each environment has different authentication requirements, but all should share a single subscription with workspace-level isolation between production and development traffic. For organizations with additional environments, create a workspace per team or workload and repeat the cross-account role pattern for each.

This post walks you through the complete setup. You will deploy a dedicated AI Services account within your organization and configure cross-account SigV4 for AWS workloads. You will also generate workspace-scoped API keys for developers and wire up OIDC federation for external environments. Every step includes a CLI command, console instruction, or code snippet. If you’re evaluating which account structure is right for your organization, or which authentication path fits your workloads, see the related Architecture Patterns and Authentication Paths posts. This post picks up where those decisions end: a complete, step-by-step implementation.

The architecture

The dedicated AI Services account pattern places the CPonAWS subscription in a dedicated AI Services linked account within your organization. This account owns the subscription, workspaces, API keys, and cross-account roles. Workload accounts don’t touch the subscription directly: they assume roles into the AI Services account to make inference calls. The result is a three-account structure: a payer (management) account for billing and governance, an AI Services account that hosts the CPonAWS subscription and workspaces, and one or more workload accounts that consume inference through cross-account roles, as shown in the following diagram.

Three-account structure: a payer account, an AI Services account that hosts the CPonAWS subscription, and workload accounts that connect through cross-account roles

Figure 1: Multi-account topology for Claude Platform on AWS with a dedicated AI Services account

The preceding diagram shows the high-level account topology. The following diagram shows the specific implementation we will build, including AWS Identity and Access Management (IAM) roles, access paths, and workspace mappings:

Three access paths into the AI Services account: cross-account SigV4 from an Amazon EKS pod, a workspace-scoped API key from a developer laptop, and OIDC federation from an external workload

Figure 2: The three access patterns implemented in this guide

We will configure three access patterns:

  • AWS workload accounts through cross-account SigV4: A pod hosted on Amazon Elastic Kubernetes Service (Amazon EKS) in a workload account assumes a role in the AI Services account. It then makes SigV4-signed inference calls. No API keys stored, no secrets to rotate.
  • Developer laptops through a workspace-scoped API key: A long-lived API key locked to a development workspace. Developers use it locally with the standard Anthropic SDK.
  • External workloads through OpenID Connect (OIDC) federation and short-term keys: A workload hosted outside AWS authenticates through OIDC, obtains temporary AWS credentials. It generates a short-lived token and makes inference calls with zero persistent credentials.

Prerequisites

Before starting, verify you have:

  • An organization in AWS Organizations with:
    • A payer (management) account.
    • An AWS linked account for AI Services subscriptions (will host the CPonAWS subscription).
    • An AWS linked account for hosting workload (for example, “Prod”).
  • AWS Command Line Interface (AWS CLI) v2 installed and configured with named profiles for both accounts.
  • Python 3.12+ with the following packages: anthropic[aws], boto3, token-generator-for-aws-external-anthropic.

Step-by-step guide

This walkthrough is divided into four parts. Each part configures one layer of the architecture: the CPonAWS subscription and workspace structure, cross-account SigV4 access for AWS workloads, workspace-scoped API keys for developers, and OIDC federation for external environments. Complete them in order. Each part builds on the resources created in the previous one.

Placeholder reference

Throughout this guide, replace these placeholders with your actual values:

Placeholder Description Example
YOUR_ORG_ID AWS Organizations ID o-abc123def4
YOUR_REGION AWS Region where the workspace was created us-east-1
AI_SERVICES_ACCOUNT_ID AWS account ID of the AI Services account 123456789012
WORKLOAD_ACCOUNT_ID AWS account ID of the Workload account 987654321098
WORKSPACE_PROD_ID Anthropic production workspace ARN wrkspc_01abc...
WORKSPACE_DEV_ID Anthropic development workspace ARN wrkspc_02def...
YOUR_OIDC_ISSUER OIDC identity provider URL accounts.google.com
YOUR_WORKLOAD_IDENTITY_FILTER Subject claim filter for OIDC trust system:serviceaccount:ns:sa

Part 1: Set up the AI Services account

Follow the Introducing Claude Platform on AWS guide to subscribe your AI Services account to CPonAWS. After you’re subscribed, create two workspaces to isolate production and development traffic:

  1. Access the AWS Management Console on the AI Services account, and navigate to Claude Platform on AWS.
  2. Navigate to Access, and sign in as Admin.
  3. In the Claude Console, choose the drop-down menu in the top left corner and choose Create Workspace. Enter the name production, and choose Create.
Claude Console dashboard with the workspace menu open in the top left corner and the Create Workspace option

Figure 3: Claude Console dashboard showing how to create a workspace

  1. Note the workspace ARN (for example, wrkspc_PROD).
  2. Repeat to create a second workspace named development (for example, wrkspc_DEV).

Tip: Record both workspace ARNs now. You will reference them in IAM policies and code throughout this guide. Workspaces are created in a specific AWS Region, and your API calls must target the matching Regional endpoint (for example, aws-external-anthropic.us-east-1.api.aws). Note that the workspace Region determines the API endpoint, not where inference runs. Inference geography is controlled separately through the workspace’s Security settings in the Claude Console. Current options are “US” and “Global routing”. For short-term keys, this is enforced at both generation and use: the token only works against the same Regional endpoint where it was generated. Long-lived API keys are not Region-locked. For supported Regions and available models, see Supported Regions and models in the Claude Platform on AWS User Guide.

Part 2: Cross-account SigV4 for AWS workloads

This section configures an EKS pod (or another workload) in the Workload account to make inference calls through SigV4 signing. The workload assumes a role in the AI Services account that grants access only to the production workspace.

2.1 Create the cross-account role (AI Services account)

First, create the trust policy file in the AI Services account. This allows a specific role in the Workload account to assume the cross-account role.

  1. Access the AWS Management Console in the AI Services account, and open AWS CloudShell.
  2. Save this file as trust-policy.json.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::WORKLOAD_ACCOUNT_ID:role/EKS-Pod-Role"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringEquals": {
                    "aws:PrincipalOrgID": "YOUR_ORG_ID"
                }
            }
        }
    ]
}
  1. Create the role by running the following command.
# From the AI Services account profile
aws iam create-role \
    --role-name CrossAccount-ClaudePlatform-Prod \
    --assume-role-policy-document file://trust-policy.json \
    --description "Allows workload account to invoke CPonAWS production workspace" \
    --profile ai-services

2.2 Attach the permission policy (AI Services account)

  1. Save this file as permission-policy.json.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "CPonAWSInference",
            "Effect": "Allow",
            "Action": [
                "aws-external-anthropic:CreateInference",
                "aws-external-anthropic:CountTokens",
                "aws-external-anthropic:GetModel",
                "aws-external-anthropic:ListModels"
            ],
            "Resource": "arn:aws:aws-external-anthropic:YOUR_REGION:AI_SERVICES_ACCOUNT_ID:workspace/WORKSPACE_PROD_ID"
        },
        {
            "Sid": "CPonAWSResourceless",
            "Effect": "Allow",
            "Action": "aws-external-anthropic:GetAccountStatus",
            "Resource": "*"
        },
        {
            "Sid": "STSWebIdentity",
            "Effect": "Allow",
            "Action": ["sts:GetWebIdentityToken", "sts:TagGetWebIdentityToken"],
            "Resource": "*"
        }
    ]
}
  1. Attach the policy to the role:
aws iam put-role-policy \
    --role-name CrossAccount-ClaudePlatform-Prod \
    --policy-name CPonAWS-Inference-Prod \
    --policy-document file://permission-policy.json \
    --profile ai-services

Note: CreateInference is scoped to the WORKSPACE_PROD_ID workspace ARN. This role cannot access the development workspace or additional workspace in the account.

2.3 Grant AssumeRole (Workload account)

The EKS pod role in the Workload account needs permission to assume the cross-account role. First, create the policy.

  1. Access the AWS Management Console in the Workload account, and open AWS CloudShell.
  2. Save this file as allow-assume-cponaws.json.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Resource": "arn:aws:iam::AI_SERVICES_ACCOUNT_ID:role/CrossAccount-ClaudePlatform-Prod"
        }
    ]
}
  1. Create and attach the policy.
aws iam create-policy \
    --policy-name AllowAssumeCPonAWSRole \
    --policy-document file://allow-assume-cponaws.json \
    --profile workload-prod

aws iam attach-role-policy \
    --role-name EKS-Pod-Role \
    --policy-arn arn:aws:iam::WORKLOAD_ACCOUNT_ID:policy/AllowAssumeCPonAWSRole \
    --profile workload-prod

2.4 Test (from the Workload account)

  1. Run the following Python script from a machine (or pod) with the EKS-Pod-Role credentials.
import boto3, os
from anthropic import AnthropicAWS

# Assume the cross-account role in the AI Services account
sts = boto3.client("sts")
assumed = sts.assume_role(
    RoleArn="arn:aws:iam::AI_SERVICES_ACCOUNT_ID:role/CrossAccount-ClaudePlatform-Prod",
    RoleSessionName="prod-workload"
)
creds = assumed["Credentials"]
os.environ["AWS_ACCESS_KEY_ID"] = creds["AccessKeyId"]
os.environ["AWS_SECRET_ACCESS_KEY"] = creds["SecretAccessKey"]
os.environ["AWS_SESSION_TOKEN"] = creds["SessionToken"]

# Make an inference call
client = AnthropicAWS(aws_region="YOUR_REGION", workspace_id="WORKSPACE_PROD_ID")
resp = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=128,
    messages=[{"role": "user", "content": "Hello from the workload account!"}]
)
print(resp.content[0].text)

Part 3: Workspace-scoped API key for developer access

Developers can use API keys to call Claude from their laptops without configuring cross-account role chains. In the following section, you will generate a key, scope it to the development workspace, and verify isolation.

3.1 Generate an API key (AI Services account)

  1. Sign in to the AI Services account on the AWS Management Console.
  2. Navigate to Claude Platform on AWS, then API keys.
  3. Choose Generate long-term key, select an API key expiration, and choose Generate.
  4. Copy the key value immediately (store it securely: you won’t see it again).
Claude Console API Keys page showing the long-term key generation dialog with expiration options

Figure 4: Generating a long-term API key from the Claude Console (API Keys page) with configurable expiration

3.2 Scope the key to the development workspace (AI Services account)

By default, the generated key’s backing IAM user (AeaApiKey-*) has the AnthropicLimitedAccess managed policy attached. This policy grants access to every workspace. To enforce workspace isolation:

  1. On the AWS Management Console (AI Services account), navigate to IAM, then Users.
  2. Search for users starting with AeaApiKey-.
  3. Find the most recently created user (the creation timestamp should match when you generated the key).
  4. Select the user, and then choose the Permissions tab.
  5. Select the AnthropicLimitedAccess policy, and choose Remove to detach the managed policy.
  6. Choose Add permissions, then Create inline policy.
  7. Switch to the JSON tab and paste the following.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "InferenceDevWorkspaceOnly",
            "Effect": "Allow",
            "Action": [
                "aws-external-anthropic:CreateInference",
                "aws-external-anthropic:CountTokens"
            ],
            "Resource": "arn:aws:aws-external-anthropic:YOUR_REGION:AI_SERVICES_ACCOUNT_ID:workspace/wrkspc_DEV"
        },
        {
            "Sid": "BearerTokenAndStatus",
            "Effect": "Allow",
            "Action": [
                "aws-external-anthropic:CallWithBearerToken",
                "aws-external-anthropic:GetAccountStatus"
            ],
            "Resource": "*"
        },
        {
            "Sid": "STSWebIdentity",
            "Effect": "Allow",
            "Action": ["sts:GetWebIdentityToken", "sts:TagGetWebIdentityToken"],
            "Resource": "*"
        }
    ]
}
  1. Name the policy CPonAWS-DevWorkspace-Only and choose Create policy.

3.3 Distribute the key to the development team (Workload account or developer environment)

The admin distributes the scoped API key to the development team. Store it in the team’s preferred secret management solution. For AWS based teams, store it in AWS Secrets Manager within the workload or developer AWS account:

aws secretsmanager create-secret \
    --name cponaws/dev-api-key \
    --secret-string "YOUR_API_KEY_VALUE" \
    --region YOUR_REGION \
    --profile workload-prod

Note: The API key is self-authenticating. It works regardless of which AWS ac