Skip to content

Agent: Error: An error occurred (accessDeniedException) when calling the InvokeAgent operation: Access denied when calling Bedrock.

0

I'm getting an error: Agent: Error: An error occurred (accessDeniedException) when calling the InvokeAgent operation: Access denied when calling Bedrock. Check your request permissions and retry the request.

My IAM Role has permissions for AmazonBedrockFullAccess and other Customer Managed policies. The Resource array of the policies includes both the Agent and Foundation Model ARNs with the same region as the created agent. I have also added both ARNs to the aws:SourceArn array in the IAM Role's Trust relationships.

I am able to create an agent programmatically, however, I get the error above when trying to invoke the agent with boto3.client(service_name='bedrock-agent-runtime', region_name='us-west-2'). What am i doing wrong, and how can I fix the problem?

For some context, I am able to call the bedrock-runtime.invoke_model API successfully with my IAM User.

A support agent assumed the issue is due to my account having a $0 spend but is yet to confirm that assumption with the technical agents.

  1. Can anyone confirm that assumption?
  2. Do you have other ideas that can fix the error?

Thank you.

asked 2 years ago2.6K views

3 Answers
0

Based on the information provided, there are a few potential reasons for the AccessDeniedException error you're encountering when trying to invoke the Bedrock agent:

  1. IAM Permissions: While you have the AmazonBedrockFullAccess policy attached, there might be a specific permission missing for the InvokeAgent operation. Ensure that your IAM role has the "bedrock:InvokeAgent" permission explicitly allowed.

  2. Resource-based Policy: The Bedrock agent might require a resource-based policy statement on the associated Lambda function. You may need to add a permission that allows the Bedrock service to invoke the Lambda function.

  3. Service Control Policies (SCPs): If your AWS account is part of an organization, there might be SCPs in place that restrict certain Bedrock actions.

  4. Region Mismatch: Confirm that the region specified in your boto3 client matches the region where your Bedrock agent is deployed.

  5. Account Spend Limit: The support agent's assumption about the $0 spend limit could be a factor, but it's not typically a common cause for AccessDenied errors. However, if your account has restrictions due to billing or usage limits, it might affect certain API calls.

To address these potential issues:

  1. Review your IAM role permissions and ensure "bedrock:InvokeAgent" is explicitly allowed.

  2. Add a resource-based policy to your Lambda function allowing Bedrock to invoke it. You can do this by:

    • Going to the Lambda function's Configuration tab
    • Selecting Permissions
    • Adding a new permission under Resource-based Policy Statements
    • Setting the Principal to "bedrock.amazonaws.com"
    • Specifying your Bedrock Agent's ARN as the Source ARN
    • Allowing the "lambda:InvokeFunction" action
  3. Double-check that your boto3 client is using the correct region.

  4. If possible, try invoking the agent using the AWS Management Console to see if the issue persists outside of programmatic access.

  5. Contact AWS Support to confirm if there are any account-level restrictions affecting your Bedrock usage.

If these steps don't resolve the issue, you may need to work with AWS Support to investigate further, as there could be account-specific factors at play.
Sources
Error when Bedrock agent invoke lambda | AWS re:Post
Resolve InvokeModel API error in Amazon Bedrock | AWS re:Post
I can create Bedrock Agent using console, but can't using CLI. | AWS re:Post

answered 2 years ago

EXPERT

reviewed 2 years ago

0

Hello.

Could you please share all the IAM policies you have set for the IAM role?
It is possible that "InvokeAgent" is explicitly denied or that the policy settings are incorrect and it is not working.
Additionally, if you configure CloudTrail to record data events, you may be able to view details in CloudTrail.
https://docs.aws.amazon.com/bedrock/latest/userguide/logging-using-cloudtrail.html#service-name-data-events-cloudtrail

EXPERT

answered 2 years ago

0

Has this issue been solved yet? I ran into a similar problem, updating the version of the aliases solved the problem for me. My issue was I didnt have the correct policy statements attached to the role at first, but adding them in CDK wasnt enough to fix the production version of the agent. Making changes in CDK only propegates to the draft version of the agent, not the production alias, we have to update that manually at this point in time, or replace it during deployment with a new alias with a different ID.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.