awslabs / awslabs/agentcore-samples

[Help] <AccessDeniedException> running agentcore_runtime.launch()

Open
#874 1 comment 0 reactions 1 assignee Claimed by @EashanKaushik View on GitHub
help wanted
Dominant language
Python
Stars
3.4k
Forks
1.3k
Avg merge
1d 22h
Merged PRs (30d)
30

Description

## Summary
When I am trying to launch the agentcore_runtime within sagemaker studio "launch_result = agentcore_runtime.launch()", I get the below AccessDeniedException error message.

## Details

### IAM policy for SageMakerExecution Role:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ExistingS3Access",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"s3:PutLifecycleConfiguration",
"s3:GetLifecycleConfiguration"
],
"Resource": [
"arn:aws:s3:::SageMaker",
"arn:aws:s3:::SageMaker/*",
"arn:aws:s3:::bedrock-agentcore-codebuild-sources-*"
]
},
{
"Sid": "BedrockAgentCoreRuntime",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:CreateAgentRuntime",
"bedrock-agentcore:GetAgentRuntime",
"bedrock-agentcore:DeleteAgentRuntime",
"bedrock-agentcore:UpdateAgentRuntime"
],
"Resource": "*"
},
{
"Sid": "SageMakerIAMSetup",
"Effect": "Allow",
"Action": [
"iam:CreateRole",
"iam:PutRolePolicy",
"iam:CreatePolicy",
"iam:AttachRolePolicy",
"iam:GetRole",
"iam:GetPolicy",
"iam:PassRole"
],
"Resource": [
"arn:aws:iam::*:role/service-role/AmazonSageMaker*",
"arn:aws:iam::*:policy/service-role/AmazonSageMaker*",
"arn:aws:iam::X:role/AmazonBedrockAgent*",
"arn:aws:iam::X:role/AmazonBedrockAgentCoreSDK*"
]
},
{
"Sid": "BedrockAgentCoreCodeBuild",
"Effect": "Allow",
"Action": [
"codebuild:CreateProject",
"codebuild:StartBuild",
"codebuild:BatchGetBuilds",
"codebuild:BatchGetProjects",
"codebuild:UpdateProject"
],
"Resource": [
"arn:aws:codebuild:us-east-1:X:project/bedrock-agentcore-*",
"arn:aws:codebuild:us-east-1:X:build/bedrock-agentcore-*"
]
},
{
"Sid": "CodeBuildListAccess",
"Effect": "Allow",
"Action": [
"codebuild:ListProjects",
"codebuild:ListBuilds"
],
"Resource": "*"
},
{
"Sid": "AllowPassRoleToSageMaker",
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::*:role/service-role/AmazonSageMaker*",
"Condition": {
"StringEquals": {
"iam:PassedToService": "[sagemaker.amazonaws.com](http://sagemaker.amazonaws.com/)"
}
}
},
{
"Sid": "AllowPassRoleToBedrockAgentCore",
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": [
"arn:aws:iam::X:role/AmazonBedrockAgentCoreSDK*"
],
"Condition": {
"StringLike": {
"iam:PassedToService": [
"[bedrock-agentcore.amazonaws.com](http://bedrock-agentcore.amazonaws.com/)",
"[bedrock.amazonaws.com](http://bedrock.amazonaws.com/)"
]
}
}
}
]
}

AmazonBedrockAgentCoreSDKRuntime-us-east-1-46ebe432b7Role Trusted relationship is like:

### BedrockAgentCoreRuntimeExecutionPolicy-strands_claude

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"[bedrock.amazonaws.com](http://bedrock.amazonaws.com/)",
"[bedrock-agentcore.amazonaws.com](http://bedrock-agentcore.amazonaws.com/)"
]
},
"Action": "sts:AssumeRole"
}
]
}

ARN: arn:aws:iam::X:role/AmazonBedrockAgentCoreSDKRuntime-us-east-1-46ebe432b7

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ECRImageAccess",
"Effect": "Allow",
"Action": [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer"
],
"Resource": [
"arn:aws:ecr:us-east-1:592781322675:repository/*"
]
},
{
"Effect": "Allow",
"Action": [
"logs:DescribeLogStreams",
"logs:CreateLogGroup"
],
"Resource": [
"arn:aws:logs:us-east-1:592781322675:log-group:/aws/bedrock-agentcore/runtimes/*"
]
},
{
"Effect": "Allow",
"Action": [
"logs:DescribeLogGroups"
],
"Resource": [
"arn:aws:logs:us-east-1:592781322675:log-group:*"
]
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:us-east-1:592781322675:log-group:/aws/bedrock-agentcore/runtimes/*:log-stream:*"
]
},
{
"Sid": "ECRTokenAccess",
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Resource": "*",
"Action": "cloudwatch:PutMetricData",
"Condition": {
"StringEquals": {
"cloudwatch:namespace": "bedrock-agentcore"
}
}
},
{
"Sid": "BedrockAgentCoreRuntime",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:InvokeAgentRuntime"
],
"Resource": [
"arn:aws:bedrock-agentcore:us-east-1:592781322675:runtime/*"
]
},
{
"Sid": "BedrockAgentCoreMemoryCreateMemory",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:CreateMemory"
],
"Resource": "*"
},
{
"Sid": "BedrockAgentCoreMemory",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:CreateEvent",
"bedrock-agentcore:GetEvent",
"bedrock-agentcore:GetMemory",
"bedrock-agentcore:GetMemoryRecord",
"bedrock-agentcore:ListActors",
"bedrock-agentcore:ListEvents",
"bedrock-agentcore:ListMemoryRecords",
"bedrock-agentcore:ListSessions",
"bedrock-agentcore:DeleteEvent",
"bedrock-agentcore:DeleteMemoryRecord",
"bedrock-agentcore:RetrieveMemoryRecords"
],
"Resource": [
"arn:aws:bedrock-agentcore:us-east-1:592781322675:memory/*"
]
},
{
"Sid": "BedrockAgentCoreIdentityGetResourceApiKey",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:GetResourceApiKey"
],
"Resource": [
"arn:aws:bedrock-agentcore:us-east-1:592781322675:token-vault/default",
"arn:aws:bedrock-agentcore:us-east-1:592781322675:token-vault/default/apikeycredentialprovider/*",
"arn:aws:bedrock-agentcore:us-east-1:592781322675:workload-identity-directory/default",
"arn:aws:bedrock-agentcore:us-east-1:592781322675:workload-identity-directory/default/workload-identity/strands_claude-*"
]
},
{
"Sid": "BedrockAgentCoreIdentityGetResourceOauth2Token",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:GetResourceOauth2Token"
],
"Resource": [
"arn:aws:bedrock-agentcore:us-east-1:592781322675:token-vault/default",
"arn:aws:bedrock-agentcore:us-east-1:592781322675:token-vault/default/oauth2credentialprovider/*",
"arn:aws:bedrock-agentcore:us-east-1:592781322675:workload-identity-directory/default",
"arn:aws:bedrock-agentcore:us-east-1:592781322675:workload-identity-directory/default/workload-identity/strands_claude-*"
]
},
{
"Sid": "BedrockAgentCoreIdentityGetWorkloadAccessToken",
"Effect": "Allow",
"Action": [
"bedrock-agentcore:GetWorkloadAccessToken",
"bedrock-agentcore:GetWorkloadAccessTokenForJWT",
"bedrock-agentcore:GetWorkloadAccessTokenForUserId"
],
"Resource": [
"arn:aws:bedrock-agentcore:us-east-1:592781322675:workload-identity-directory/default",
"arn:aws:bedrock-agentcore:us-east-1:592781322675:workload-identity-directory/default/workload-identity/strands_claude-*"
]
},
{
"Sid": "BedrockModelInvocation",
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:ApplyGuardrail"
],
"Resource": [
"arn:aws:bedrock:*::foundation-model/*",
"arn:aws:bedrock:us-east-1:592781322675:*"
]
}
]
}

### **Error Message**

🚀 CodeBuild mode: building in cloud (RECOMMENDED - DEFAULT)
• Build ARM64 containers in the cloud with CodeBuild
• No local Docker required
💡 Available deployment modes:
• runtime.launch() → CodeBuild (current)
• runtime.launch(local=True) → Local development
• runtime.launch(local_build=True) → Local build + cloud deploy (NEW)
Starting CodeBuild ARM64 deployment for agent 'strands_claude' to account X (us-east-1)
Setting up AWS resources (ECR repository, execution roles)...
Using ECR repository from config: [X.dkr.ecr.us-east-1.amazonaws.com/bedrock-agentcore-strands_claude](http://592781322675.dkr.ecr.us-east-1.amazonaws.com/bedrock-agentcore-strands_claude)
Using execution role from config: arn:aws:iam::X:role/AmazonBedrockAgentCoreSDKRuntime-us-east-1-46ebe432b7
Preparing CodeBuild project and uploading source...
Using CodeBuild role from config: arn:aws:iam::X:role/AmazonBedrockAgentCoreSDKCodeBuild-us-east-1-46ebe432b7
Using .dockerignore with 44 patterns
Uploaded source to S3: strands_claude/source.zip
Using CodeBuild project from config: bedrock-agentcore-strands_claude-builder
Starting CodeBuild build (this may take several minutes)...
Starting CodeBuild monitoring...
🔄 QUEUED started (total: 0s)
✅ QUEUED completed in 1.0s
🔄 PROVISIONING started (total: 1s)
✅ PROVISIONING completed in 8.2s
🔄 DOWNLOAD_SOURCE started (total: 9s)
✅ DOWNLOAD_SOURCE completed in 2.1s
🔄 BUILD started (total: 11s)
✅ BUILD completed in 15.5s
🔄 POST_BUILD started (total: 27s)
✅ POST_BUILD completed in 11.4s
🔄 FINALIZING started (total: 38s)
✅ FINALIZING completed in 1.0s
🔄 COMPLETED started (total: 39s)
✅ COMPLETED completed in 1.0s
🎉 CodeBuild completed successfully in 0m 40s
CodeBuild completed successfully
✅ CodeBuild project configuration saved
Deploying to Bedrock AgentCore...
---------------------------------------------------------------------------
AccessDeniedException Traceback (most recent call last)
Cell In[27], line 1
----> 1 launch_result = agentcore_runtime.launch()

File /opt/conda/lib/python3.12/site-packages/bedrock_agentcore_starter_toolkit/notebook/runtime/bedrock_agentcore.py:191, in Runtime.launch(self, local, local_build, auto_update_on_conflict, env_vars)
188 use_codebuild = not (local or local_build)
190 try:
--> 191 result = launch_bedrock_agentcore(
192 self._config_path,
193 local=local,
194 use_codebuild=use_codebuild,
195 auto_update_on_conflict=auto_update_on_conflict,
196 env_vars=env_vars,
197 )
198 except RuntimeError as e:
199 # Enhance Docker-related error messages
200 error_msg = str(e)

File /opt/conda/lib/python3.12/site-packages/bedrock_agentcore_starter_toolkit/operations/runtime/launch.py:282, in launch_bedrock_agentcore(config_path, agent_name, local, use_codebuild, env_vars, auto_update_on_conflict)
280 # Handle CodeBuild deployment (but not for local mode)
281 if use_codebuild and not local:
--> 282 return _launch_with_codebuild(
283 config_path=config_path,
284 agent_name=agent_config.name,
285 agent_config=agent_config,
286 project_config=project_config,
287 auto_update_on_conflict=auto_update_on_conflict,
288 env_vars=env_vars,
289 )
291 # Log which agent is being launched
292 mode = "locally" if local else "to cloud"

File /opt/conda/lib/python3.12/site-packages/bedrock_agentcore_starter_toolkit/operations/runtime/launch.py:506, in _launch_with_codebuild(config_path, agent_name, agent_config, project_config, auto_update_on_conflict, env_vars)
495 build_id, ecr_uri, region, account_id = _execute_codebuild_workflow(
496 config_path=config_path,
497 agent_name=agent_name,
(...)
502 env_vars=env_vars,
503 )
505 # Deploy to Bedrock AgentCore
--> 506 agent_id, agent_arn = _deploy_to_bedrock_agentcore(
507 agent_config,
508 project_config,
509 config_path,
510 agent_name,
511 ecr_uri,
512 region,
513 account_id,
514 env_vars=env_vars,
515 auto_update_on_conflict=auto_update_on_conflict,
516 )
518 log.info("Deployment completed successfully - Agent: %s", agent_arn)
520 return LaunchResult(
521 mode="codebuild",
522 tag=f"bedrock_agentcore-{agent_name}:latest",
(...)
526 agent_id=agent_id,
527 )

File /opt/conda/lib/python3.12/site-packages/bedrock_agentcore_starter_toolkit/operations/runtime/launch.py:200, in _deploy_to_bedrock_agentcore(agent_config, project_config, config_path, agent_name, ecr_uri, region, account_id, env_vars, auto_update_on_conflict)
194 if is_role_validation_error:
195 log.error(
196 "Role validation failed after %d attempts. The execution role may not be ready. Role: %s",
197 max_retries + 1,
198 agent_config.aws.execution_role,
199 )
--> 200 raise e
202 # Calculate delay with exponential backoff
203 delay = min(base_delay * (2**attempt), max_delay)

File /opt/conda/lib/python3.12/site-packages/bedrock_agentcore_starter_toolkit/operations/runtime/launch.py:167, in _deploy_to_bedrock_agentcore(agent_config, project_config, config_path, agent_name, ecr_uri, region, account_id, env_vars, auto_update_on_conflict)
165 for attempt in range(max_retries + 1):
166 try:
--> 167 agent_info = bedrock_agentcore_client.create_or_update_agent(
168 agent_id=agent_config.bedrock_agentcore.agent_id,
169 agent_name=agent_name,
170 image_uri=f"{ecr_uri}:latest",
171 execution_role_arn=agent_config.aws.execution_role,
172 network_config=network_config,
173 authorizer_config=agent_config.get_authorizer_configuration(),
174 request_header_config=agent_config.request_header_configuration,
175 protocol_config=protocol_config,
176 env_vars=env_vars,
177 auto_update_on_conflict=auto_update_on_conflict,
178 )
179 break # Success! Exit retry loop
181 except ClientError as e:

File /opt/conda/lib/python3.12/site-packages/bedrock_agentcore_starter_toolkit/services/runtime.py:326, in BedrockAgentCoreClient.create_or_update_agent(self, agent_id, agent_name, image_uri, execution_role_arn, network_config, authorizer_config, request_header_config, protocol_config, env_vars, auto_update_on_conflict)
315 if agent_id:
316 return self.update_agent(
317 agent_id,
318 image_uri,
(...)
324 env_vars,
325 )
--> 326 return self.create_agent(
327 agent_name,
328 image_uri,
329 execution_role_arn,
330 network_config,
331 authorizer_config,
332 request_header_config,
333 protocol_config,
334 env_vars,
335 auto_update_on_conflict,
336 )

File /opt/conda/lib/python3.12/site-packages/bedrock_agentcore_starter_toolkit/services/runtime.py:155, in BedrockAgentCoreClient.create_agent(self, agent_name, image_uri, execution_role_arn, network_config, authorizer_config, request_header_config, protocol_config, env_vars, auto_update_on_conflict)
152 if env_vars is not None:
153 params["environmentVariables"] = env_vars
--> 155 resp = self.client.create_agent_runtime(**params)
156 agent_id = resp["agentRuntimeId"]
157 agent_arn = resp["agentRuntimeArn"]

File /opt/conda/lib/python3.12/site-packages/botocore/client.py:602, in ClientCreator._create_api_method.._api_call(self, *args, **kwargs)
598 raise TypeError(
599 f"{py_operation_name}() only accepts keyword arguments."
600 )
601 # The "self" in this scope is referring to the BaseClient.
--> 602 return self._make_api_call(operation_name, kwargs)

File /opt/conda/lib/python3.12/site-packages/botocore/context.py:123, in with_current_context..decorator..wrapper(*args, **kwargs)
121 if hook:
122 hook()
--> 123 return func(*args, **kwargs)

File /opt/conda/lib/python3.12/site-packages/botocore/client.py:1078, in BaseClient._make_api_call(self, operation_name, api_params)
1074 error_code = request_context.get(
1075 'error_code_override'
1076 ) or error_info.get("Code")
1077 error_class = self.exceptions.from_code(error_code)
-> 1078 raise error_class(parsed_response, operation_name)
1079 else:
1080 return parsed_response

AccessDeniedException: An error occurred (AccessDeniedException) when calling the CreateAgentRuntime operation:

## Expected Behavior
Launching agent to AgentCore Runtime

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.