Permission denied with aws bedrock but working with aws cli

Status Fixed / completed
Maintainer reply ✓ Yes — 8enmann
Activity 8 comments · opened Feb 25, 2025 · closed Feb 26, 2025
💡 Likely answer: A maintainer (8enmann, collaborator) responded on this thread — see the highlighted reply below.

Hi!

I can access claude 3.7 with

aws bedrock-runtime invoke-model --model-id us.anthropic.claude-3-7-sonnet-20250219-v1:0 --body '{"anthropic_version":"bedrock-2023-05-31","max_tokens":100,"messages":[{"role":"user","content":"Hello, are you working?"}]}' --cli-binary-format raw-in-base64-out --region us-east-1 --profile PROFILE output.json

I get a response and everything seems to be working. But with claude code I get

API Error: 403 You don't have access to the model with the specified model ID.

No matter how I start claude code.

For example
AWS_REGION=us-east-1 AWS_PROFILE=PROFILE CLAUDE_CODE_USE_BEDROCK=1 ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0' DISABLE_PROMPT_CACHING=1 claude

View original on GitHub ↗

8 Comments

matheus-mprado · 1 year ago

Hi,

i get the same error:

!Image

jeremycyr-MK · 1 year ago

Do you have access granted to that model in the Bedrock console on AWS?

<img width="1040" alt="Image" src="https://github.com/user-attachments/assets/d4c46bd9-7080-4b44-b8de-3d4c5358263d" />

There is an approval flow for model use within Bedrock

oscarthorn · 1 year ago

Yes, in all us regions. As I mentioned I can use to model through aws bedrock-runtime invoke-model --model-id us.anthropic.claude-3-7-sonnet-20250219-v1:0 ... with no issues.

8enmann collaborator · 1 year ago

Two suggestions

  1. Try AWS_PROFILE= and use the envvar-based creds for the account/role with permission
  2. Try removing us. from the prefix of the model name

If neither of those work, I have a PR incoming that might fix it for ya.

oscarthorn · 1 year ago

@8enmann Thanks for the suggestion. Unsetting the profile variable and using creds directly solves the problem!

Quentin-M · 1 year ago

You cannot use profiles, Claude Code does not support that.

See https://github.com/anthropics/claude-code/issues/6#issuecomment-2680841040 for the initial report and work-around.

matheus-mprado · 1 year ago

I set the following environment variables and they worked

export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0'
export DISABLE_PROMPT_CACHING=1
export AWS_ACCESS_KEY_ID=YOUR ACCESS KEY
export AWS_SECRET_ACCESS_KEY=YOUR SECRET ACCESS KEY
export AWS_REGION=YOUR REGION MODEL INFERENCE ACCESS ANTHROPIC

even with the aws configure done, you need to do these environment configurations for it to work.

PS. If you use Windows, you can use Claude's code with git bash without using WSL, but you need to set up the environment variables again every time, creating a sh script that automates this helps.

#!/bin/bash

# exporting environments
export CLAUDE_CODE_USE_BEDROCK=1
export ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0'
export DISABLE_PROMPT_CACHING=1
export AWS_ACCESS_KEY_ID=YOUR ACCESS KEY
export AWS_SECRET_ACCESS_KEY=YOUR SECRET ACCESS KEY
export AWS_REGION=YOUR REGION MODEL INFERENCE ACCESS ANTHROPIC

echo "environments set!"
github-actions[bot] · 1 year ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.