Get started with Amazon Bedrock Managed Agents (with OpenAI) on AgentCore Runtime
Note
Amazon Bedrock Managed Agents (with OpenAI) is in preview. Features and APIs may change before general availability.
Amazon Bedrock Managed Agents runs the OpenAI Codex harness on Amazon. The harness runs the loop between the model and the tools, keeps the session, and compacts context as the conversation grows. When the agent must run a command or work with files, Bedrock Managed Agents sends the work to an environment. You decide where that environment runs.
You can run the Codex exec-server on your own computer for local development. For other workloads, Bedrock Managed Agents invokes an AgentCore Runtime in your account. The Runtime gives each session its own microVM. The session runs under an execution role that you control, and the Runtime can connect to your VPC so that the agent can reach private resources. The model calls stay in Bedrock Managed Agents, so the container runs only the commands that the agent sends.
In this tutorial, you do these tasks:
-
Create and deploy the Runtime with the AgentCore CLI.
-
Start a session with the OpenAI SDK. The agent uses a sample skill in your Runtime.
-
(Optional) Add your own skills.
Steps 1 to 4 take about 15 minutes.
The Amazon resources that you create in this tutorial might result in charges to your Amazon account. These resources include the Runtime, the Amazon CodeBuild image builds, and the Bedrock Managed Agents model calls. For more information, see AgentCore pricing
Prerequisites
-
Node.js 20.12 or later. The AgentCore CLI is distributed as an npm package. Check with
node --version. -
uv. The sample client uses uv
to run with Python 3.12 or later and to install its Python dependencies. -
An Amazon account with credentials configured. To create an account, see Getting started with an Amazon account. To configure credentials, see Configuring the Amazon CLI.
-
IAM permissions. Your identity needs permissions to make AgentCore API calls and to assume the CDK bootstrap roles used during deployment. See Use the AgentCore CLI. The sample client also needs IAM permissions. See The session role.
-
Model access. Your account needs access to the Bedrock Managed Agents model
openai.gpt-5.6-luna.
The CLI builds the container image with Amazon CodeBuild in your account, so you do not need Docker.
Step 1: Create the project
To create the project
-
Install the AgentCore CLI.
npm install -g @aws/agentcore agentcore --version -
Set your credentials and Region.
export AWS_PROFILE=your-profileexport AWS_REGION=us-east-1 -
Create the project from the
environment-python-bmatemplate.agentcore create --nameMyManagedAgent--template environment-python-bma cdMyManagedAgentNote
You can also run
agentcore createwith no flags. Choose code-based, and then choose theenvironment-python-bmatemplate.The project has the Runtime configuration in
agentcore/agentcore.jsonand the container source inapp/agent/. The Runtime is namedagent. The container runscodex exec-server, which connects out to Bedrock Managed Agents and runs the commands of the agent.The template configures the Runtime with these defaults:
-
A 30 minute idle timeout and an 8 hour maximum lifetime. See Configure lifecycle settings.
-
An execution role with the permissions in
policies/bma-acr-policy.json.
-
MyManagedAgent/ ├── agentcore/ │ ├── agentcore.json │ ├── aws-targets.json │ └── cdk/ └── app/agent/ ├── Dockerfile ├── lifecycle/server.py ├── otel/collector.yaml ├── plugins/acr-report/ ├── policies/ │ ├── bma-acr-policy.json │ ├── bma-session-trust.json │ └── bma-session-policy.json ├── pyproject.toml ├── client.py └── README.md
Key files:
-
lifecycle/server.py- The lifecycle server. Bedrock Managed Agents calls it to startcodex exec-serverin your Runtime session. Do not change this file. -
Dockerfile- Installs Codex, the CloudWatch agent, and Python, and copieslifecycle/,otel/, andplugins/to/opt/bma. -
otel/collector.yaml- Sends the spans and logs of the exec-server to X-Ray and CloudWatch Logs. -
plugins/acr-report/- A sample plugin with one skill. The skill savesacr-report.txtin the workspace. -
policies/bma-acr-policy.json- The policy of the Runtime execution role. Allowsbedrock-mantle:RegisterEnvironmentandbedrock-mantle:ConnectEnvironment. To limit it to one project, changeResourcetoarn:aws:bedrock-mantle:.region:account-id:project/project-id -
pyproject.toml- The Python dependencies. Thedevgroup is forclient.pyonly. -
policies/bma-session-trust.jsonandpolicies/bma-session-policy.json- The trust policy and the permissions of the session role. See The session role. -
client.py- A sample client that starts a session. You run it in Step 3.
The Runtime execution role registers and connects the environment. The session role is different: Bedrock Managed Agents assumes it to call the model and invoke or stop your Runtime. The CLI template does not automatically create or select this session role.
To provision the session role with the generated CDK application
-
Edit
agentcore/cdk/lib/cdk-stack.ts. -
Replace the constructor’s existing assignment to
this.applicationwith the following code:const applicationProps = { ...props.application, spec: { ...props.application.spec, runtimes: (props.application.spec.runtimes ?? []).map(runtime => runtime.name === 'agent' ? { ...runtime, bedrockManagedAgents: true } : runtime ), }, }; this.application = new AgentCoreApplication(this, 'Application', applicationProps);
This sets the L3 construct’s activation marker after the project has been loaded. Do not add bedrockManagedAgents to agentcore.json; it is not a supported CLI Runtime field. If you renamed the Runtime, replace agent in the snippet with its logical name.
The L3 session role trusts bedrock-mantle.amazonaws.com, with source-account and source-ARN conditions for sessions and projects in the deployment account and Region. It grants bedrock-mantle:CreateInference, and bedrock-agentcore:InvokeAgentRuntime and bedrock-agentcore:StopRuntimeSession for the marked Runtime and its endpoints. It also grants bedrock-agentcore:InvokeGateway for Gateways throughout that account and Region, not just this project’s Gateways. Review those grants for your workload.
Alternatively, create or obtain a session role with the trust and permissions in the Bedrock Managed Agents security guide. In either case, the role must be in the calling account, and your client identity must be authorized to pass that specific role to Bedrock Managed Agents.
(Optional) To use an existing execution role
If you set executionRoleArn on the runtime in agentcore/agentcore.json, the CLI uses your existing role. It cannot attach policies/bma-acr-policy.json to that role.
-
Grant the role
bedrock-mantle:RegisterEnvironmentandbedrock-mantle:ConnectEnvironmentbefore you deploy.
(Optional) To deploy the Runtime in a VPC
By default, the Runtime runs without VPC access. Deploy the Runtime in a VPC when the agent needs to reach private resources in your VPC, or when you plan to share skills from an Amazon S3 bucket, which requires VPC network mode.
-
Add the following fields to the
agentRuntime entry inagentcore/agentcore.json:{ "networkMode": "VPC", "networkConfig": { "vpcId": "vpc-0123456789abcdef0", "subnets":"], "securityGroups":"] } }Replace the IDs with the IDs of your VPC, subnets, and security groups. A container build in VPC mode needs
vpcId.
The subnets must have a route to the Bedrock Managed Agents endpoint, because the exec-server connects out to it. The image build runs in the same subnets and downloads Codex and Python, so the subnets also need a route to the internet. See Configure AgentCore for VPC.
Step 2: Deploy
agentcore dev does not support the environment-python-bma template. In a project with other supported Runtimes, it skips this Runtime unless you select it explicitly, in which case it reports that local development is unsupported. Deploy the environment and use client.py as shown in Run a session. This limitation does not prevent running the Codex exec-server independently on your own computer.
To deploy the Runtime
-
Deploy the Runtime and check its status.
agentcore deploy agentcore status --jsonThe CLI builds the image with Amazon CodeBuild in your account, and deploys the Runtime and its execution role. Bedrock Managed Agents invokes the Runtime for you.
-
Save the
arnof theagentRuntime from the output ofagentcore status --json.{ "resourceType": "runtime", "name": "agent", "deploymentState": "deployed", "arn": "arn:aws:bedrock-agentcore:us-east-1:111122223333:runtime/MyManagedAgent_agent-a1b2c3d4e5" } -
Read the session-role ARN. The CDK session-role setup above also produces a CloudFormation output described as
IAM role ARN for Bedrock Managed Agents sessions. Read it from the deployed stack’s Outputs tab, or use the stack name shown during deployment.aws cloudformation describe-stacks \ --stack-namestack-name\ --query "Stacks[0].Outputs[?Description=='IAM role ARN for Bedrock Managed Agents sessions'].OutputValue" \ --output text -
Save this ARN for
SESSION_ROLE_ARNin the client. It is not the Runtime execution-role ARN, andagentcore statusdoes not report this session-role output. Authorize your client identity foriam:PassRoleon this ARN, withiam:PassedToServiceset tobedrock-mantle.amazonaws.com, in addition to the session/event permissions in the Bedrock Managed Agents security guide.
Step 3: Run a session
Bedrock Managed Agents uses a session role to call the model and to invoke your Runtime. The session role is not the Runtime execution role. When you run client.py, it creates the session role in your account. agentcore deploy does not create the session role, and agentcore remove does not delete it. See The session role.
The session role is not the Runtime execution role. agentcore deploy creates the execution role with policies/bma-acr-policy.json. The client gives the session role to Bedrock Managed Agents in the role_arn field when it creates a session.
When you start a new session and do not give --role-arn, the client does these steps:
-
If the role
BmaSessionRole-does not exist, the client creates it.region -
The client compares the trust policy and the inline policy
BmaSessionof the role withpolicies/bma-session-trust.jsonandpolicies/bma-session-policy.json. If a policy is not the same, the client writes the file to the role. The files are limited to the account and the Region of the Runtime. -
If the client changed the role, it waits 15 seconds. IAM needs this time before Bedrock Managed Agents can use the change.
To change the role, change the files. The client does not remove other policies that someone adds to the role. It does not check the role when you give --session-id, and it does not change a role that you give with --role-arn.
For production, give the client a role for one Runtime and one gateway with --role-arn. To make the role, use the two files in policies/. Put in your partition, Region, and account ID. Then change the
in runtime/ and gateway/* to your Runtime ID and gateway ID. Do not change the files in the project, because all the projects in the Region share BmaSessionRole-.region
The identity you use to run the client needs the Bedrock Managed Agents client permissions, bedrock-mantle:CallWithBearerToken, and iam:PassRole on the session role. To let the client create and repair the role, also give these permissions on arn:aws:iam::: account-id:role/BmaSessionRole-*iam:GetRole, iam:CreateRole, iam:UpdateAssumeRolePolicy, iam:GetRolePolicy, and iam:PutRolePolicy. If you give --role-arn, the client does not need these five permissions.
For the trust policy, the permissions of the session role, and the client permissions, see Security and IAM roles in the Amazon Bedrock User Guide.
The client uses the client.beta.agents resources of the openai package. Bedrock Managed Agents runs the agent loop.
When the client creates the session, it sets these values in environment:
-
type-aws_bedrock_agentcore, which tells Bedrock Managed Agents to use an AgentCore Runtime. -
runtime_arn- Your Runtime. The session runs in the Region of the Runtime. -
workspace_directory- The directory where the agent runs its commands. The client uses/home/app/workspace. The lifecycle server creates the directory. -
runtime_qualifier- The endpoint of the Runtime. The client usesDEFAULT. -
capability_directories- The directories where Bedrock Managed Agents finds skills. The client uses/opt/bma/plugins.
The client also sets role_arn in extra_body to the session role. The openai package does not have a parameter for this field.
The provide_token helper uses your Amazon credentials to get a short-lived Amazon Bedrock bearer token for each request.
If you add a gateway to the project, give its ARN from the output of agentcore deploy with --gateway. Use the flag only for a new session. The client adds the gateway as an mcp tool with the ARN in connector_id. Bedrock Managed Agents calls the gateway with the session role. The gateway must support MCP version 2025-03-26. If it does not, the agent gets no gateway tools, and Bedrock Managed Agents does not show an error.
"""Send an input to a Bedrock Managed Agents session that uses this project's ACR.""" import argparse import json import time from pathlib import Path from typing import Any import boto3 from aws_bedrock_token_generator import provide_token from botocore.exceptions import ClientError from openai import NotFoundError, OpenAI BMA_MODEL_ID = "openai.gpt-5.6-luna" SESSION_ROLE_ARN = "arn:aws:iam::111122223333:role/your-bma-session-role" WORKSPACE_DIRECTORY = "/home/app/workspace" CAPABILITY_DIRECTORIES = ["/opt/bma/plugins"] TURN_END = ("completed", "failed", "cancelled") TOOL_CALLS = ("mcp_call", "function_call", "web_search_call") POLICIES = Path(__file__).parent / "policies" SESSION_ROLE = "BmaSessionRole-{region}" SESSION_POLICY = "BmaSession" def show(data: dict[str, Any]) -> None: """Prints the session ID, the commands, the tool calls, and the answer.""" kind = data["type"].removeprefix("agent.session.") item = data.get("item") or {} if kind == "created": print(f"Session {data['session']['id']}") elif kind == "turn.output_text.delta": print(data["delta"], end="", flush=True) elif kind == "turn.item.done" and item.get("type") == "command_execution": print(f"\n$ {item['command']}\n{item.get('output') or ''}".rstrip()) elif kind == "turn.item.done" and item.get("type") in TOOL_CALLS: print(f"\nTool {item.get('name') or item['type']} {item.get('status')}") elif kind == "error" or kind.split(".")[-1] in TURN_END: source = data.get("turn") or data.get("environment") or data.get("session") print(f"\n{kind} {(source or data).get('error') or ''}".rstrip()) def load_policy(name: str, partition: str, region: str, account: str) -> str: """Reads a policy file and puts in the partition, the Region, and the account.""" text = (POLICIES / name).read_text() for key, value in (("Partition", partition), ("Region", region), ("AccountId", account)): text = text.replace("${AWS::" + key + "}", value) return text def session_role(runtime_arn: str) -> str: """Creates or repairs the session role, and returns its ARN. If the trust policy or the policy of the role is not the same as the file in `policies/`, the client writes the file to the role. """ _, partition, _, region, account = runtime_arn.split(":")[:5] name = SESSION_ROLE.format(region=region) trust = load_policy("bma-session-trust.json", partition, region, account) policy = load_policy("bma-session-policy.json", partition, region, account) iam = boto3.client("iam") changed = False try: role = iam.get_role(RoleName=name)["Role"] except iam.exceptions.NoSuchEntityException: role = iam.create_role(RoleName=name, AssumeRolePolicyDocument=trust)["Role"] print(f"Created the session role {name}") changed = True else: if role["AssumeRolePolicyDocument"] != json.loads(trust): iam.update_assume_role_policy(RoleName=name, PolicyDocument=trust) print(f"Updated the trust policy of {name}") changed = True try: current = iam.get_role_policy(RoleName=name, PolicyName=SESSION_POLICY)["PolicyDocument"] except iam.exceptions.NoSuchEntityException: current = None if current != json.loads(policy): iam.put_role_policy(RoleName=name, PolicyName=SESSION_POLICY, PolicyDocument=policy) if not changed: print(f"Updated the policy of {name}") changed = True if changed: # IAM needs some seconds before Bedrock Managed Agents can use a new or changed role. time.sleep(15) return role["Arn"] def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--runtime", required=True, help="The ACR ARN.") parser.add_argument( "--session-id", help="The BMA session ID. If it does not exist, the client creates a session.", ) parser.add_argument( "--input", default="Use the acr-report skill to save an ACR report in the workspace.", ) parser.add_argument( "--gateway", help="The Gateway ARN from the output of `agentcore deploy`.", ) parser.add_argument( "--role-arn", help="The session role that BMA assumes. If you do not give it, the client creates a role.", ) parser.add_argument("--delete", action="store_true", help="Delete the session.") parser.add_argument("--raw", action="store_true", help="Print events as JSON.") args = parser.parse_args() # BMA must run in the Region of the ACR. region = args.runtime.split(":")[3] with OpenAI( api_key=lambda: provide_token(region=region), base_url=f"https://bedrock-mantle.{region}.api.aws/openai/v1", ) as client: sessions = client.beta.agents.sessions session_id = args.session_id if session_id: try: session = sessions.retrieve(session_id).model_dump(warnings=False) except NotFoundError: print(f"Session {session_id} does not exist.") session_id = None else: if session["environment"].get("runtime_arn") != args.runtime: raise ValueError(f"Session {session_id} uses another ACR.") if not session_id and not args.role_arn: try: args.role_arn = session_role(args.runtime) except ClientError as error: parser.error( f"The client cannot create or check the session role: {error}. " "Get the IAM permissions in README.md, or give --role-arn." ) print(f"Session role {args.role_arn}") if session_id: # BMA opens the stream only with stream=true, and the SDK does not send it. events = sessions.events.stream(session_id, extra_query={"stream": "true"}) message = { "role": "user", "content": [{"type": "input_text", "text": args.input}], } sessions.events.create( session_id, events=[{"type": "agent.session.input.message", "input": [message]}], ) else: agent: dict[str, Any] = { "model": BMA_MODEL_ID, "instructions": "Use the available tools to complete the task.", } if args.gateway: # Bedrock Managed Agents calls Gateway with the session role from the service side. agent["tools"] = [ {"type": "mcp", "server_label": "team_tools", "connector_id": args.gateway} ] args.input += " Then list the tools that the Gateway gives you." events = sessions.create( agent=agent, environment={ "type": "aws_bedrock_agentcore", "runtime_arn": args.runtime, "runtime_qualifier": "DEFAULT", "workspace_directory": WORKSPACE_DIRECTORY, "capability_directories": CAPABILITY_DIRECTORIES, }, input=args.input, stream=True, # The SDK has no role_arn parameter. BMA assumes this role to call the ACR. extra_body={"role_arn": args.role_arn}, ) with events: for event in events: data = event.model_dump(mode="json", warnings=False) session_id = session_id or (data.get("session") or {}).get("id") if args.raw: print(json.dumps(data), flush=True) else: show(data) if data["type"].removeprefix("agent.session.turn.") in TURN_END: break if args.delete: sessions.delete(session_id) print(f"\nDeleted session {session_id}") if __name__ == "__main__": main()
To run a session
-
Run the client from the Runtime directory with the following command. Replace
runtime-arnwith the ARN of your Runtime.cd app/agent uv run client.py --runtimeruntime-arnuv runinstalls the dependencies and thedevgroup frompyproject.tomlin.venv. The client creates a session and prints the session ID, each command with its output, and the agent’s answer. By default, the agent uses theacr-reportskill to saveacr-report.txtin the workspace.
Step 4: Continue the session
To send another input to the same session, add the session ID. The turn uses the same workspace. To keep the workspace after an idle stop, add session storage as in Keep files after an idle stop.
To continue a session
-
Send another input to the same session by adding the session ID. In the following command, replace
runtime-arnwith the ARN of your Runtime andsession-idwith the ID of your session.uv run client.py --runtimeruntime-arn--session-idsession-id\ --input "Run cat acr-report.txt and show the output."If the session does not exist, the client creates a new session and prints its ID. Add
--deleteto delete the session after the turn, or--rawto print each event as JSON.
(Optional) To keep files after an idle stop
Files in the home directory are removed when the Runtime session stops after the idle timeout. On a microVM Runtime, put the home directory of the exec-server on session storage. Then the workspace, the connection state, and CODEX_HOME stay after an idle stop.
A workspace directory on session storage works only on a Runtime that has session storage. For more information about session storage, see File system configurations for AgentCore Runtime.
-
Add the following fields to the
agentRuntime entry inagentcore/agentcore.json. TheBMA_HOME_DIRvariable moves the home directory of the exec-server to the session storage mounted at/mnt/home.{ "filesystemConfigurations": [ { "sessionStorage": { "mountPath": "/mnt/home" } } ], "envVars": [ { "name": "BMA_HOME_DIR", "value": "/mnt/home" } ] } -
In
client.py, setWORKSPACE_DIRECTORY = "/mnt/home/workspace". -
Deploy, and run the client.
Step 5: (Optional) Add skills
To add a skill to the image, you add a plugin under plugins/ and deploy. A plugin has a .codex-plugin/plugin.json file and a skills/ directory. The skills/ directory has one subdirectory for each skill, with a SKILL.md file in it. The image copies it to /opt/bma/plugins, which the client already gives to Bedrock Managed Agents.
To add a skill
-
Copy
plugins/acr-report/, and rename the plugin directory andskills/acr-report/to the name of your plugin and your skill. -
In
plugin.json, setname,version,description, and"skills": "./skills/". EachSKILL.mdstarts with front matter that hasnameanddescription. -
Deploy.
-
Start a new session with
--input "Use the.skill-nameskill to …"
(Optional) To share skills from an Amazon S3 bucket
You can mount an S3 Files access point in the Runtime. Then the skills change when the bucket changes, and the image stays the same. For the S3 Files file system, the access point, and the security group rules, see File system configurations for AgentCore Runtime.
-
Configure the Runtime with the network options in Deploy the Runtime in a VPC.
-
In the bucket, put each plugin in its own directory under the root directory of the access point. Use the same layout as
plugins/acr-report/:andplugin/.codex-plugin/plugin.json.plugin/skills/skill/SKILL.md -
Add the mount to the entry for the Runtime in
agentcore/agentcore.json.{ "filesystemConfigurations": [ { "s3FilesAccessPoint": { "accessPointArn": "arn:aws:s3files:us-east-1:111122223333:file-system/fs-0123456789abcdef0/access-point/fsap-0123456789abcdef0", "mountPath": "/mnt/skills" } } ] } -
Set
CAPABILITY_DIRECTORIESinclient.pyto["/opt/bma/plugins", "/mnt/skills"], and deploy.
Step 6: View logs and traces
agentcore deploy turns on CloudWatch Transaction Search in your account. The traces show after about 10 minutes. To see the traces in the console, open the CloudWatch console and choose GenAI Observability. Each call from Bedrock Managed Agents to the lifecycle server has one bma.invocation span. For more information, see View observability data for your Amazon Bedrock AgentCore agents.
Transaction Search settings apply to the entire account
Transaction Search and its span indexing apply to the entire account in the Region, and additional charges might apply. To keep your current settings, add "disableTransactionSearch": true to ~/.agentcore/config.json before you deploy.
To view logs and traces
-
Search the Runtime logs from the last 15 minutes, and list the recent traces.
agentcore logs runtime --since 15m agentcore traces runtime list --since 30m
Step 7: Update and redeploy
To update and redeploy
-
Change the lifecycle settings in
agentcore/agentcore.json. For example, this setting stops an idle session after 10 minutes. The values are in seconds.{ "lifecycleConfiguration": { "idleRuntimeSessionTimeout": 600, "maxLifetime": 28800 } } -
Set environment variables for the lifecycle server in the
envVarslist of the Runtime entry. For example, this variable turns off the traces and the exec-server logs.{ "envVars": [ { "name": "DISABLE_ADOT_OBSERVABILITY", "value": "true" } ] }The lifecycle server supports the following environment variables.
Variable Default Description DISABLE_ADOT_OBSERVABILITYNot set
Set to
trueto turn off the traces and the exec-server logs. The lifecycle server still writes its own logs to the log group of the Runtime.BMA_HOME_DIR/home/appHOMEof the exec-server.BMA_STATE_DIR.bmainBMA_HOME_DIRThe directory of
state.json, which keeps the connection state of the session.BMA_CODEX_HOME.codexinBMA_HOME_DIRCODEX_HOMEof the exec-server.BMA_CODEX_BINARY/opt/bma/bin/codexThe Codex binary.
BMA_MAX_TURN_LEASE300The longest turn lease, in seconds. The lifecycle server changes a longer request to this value.
-
To pin the Codex release, set
CODEX_RELEASEto aversionin theDockerfile, next toCODEX_NON_INTERACTIVE=1. Otherwise, each image build installs the latest Codex release. The lifecycle server needs Codex 0.154.0 or later. -
Deploy again.
agentcore deployThe changes apply to new sessions.
Step 8: Clean up
Important
These steps permanently delete resources and revert account-level settings such as Transaction Search. Make sure you no longer need them before you continue.
To delete the project resources
-
To delete a session, add
--deleteto the last run of the client for that session. -
Remove the resources of the project.
agentcore remove all --yes -
Deploy to delete the Runtime, its execution role, and the stack.
agentcore deploy --yes
The deploy does not delete these resources:
-
The CloudWatch Logs log groups of the Runtime, of the CodeBuild project that builds the image, and of the Lambda function that starts the build.
-
The Amazon KMS key of the Amazon ECR repository. The key stays in the Pending deletion state for 30 days, and then Amazon KMS deletes it.
-
The
CDKToolkitstack, if the first deploy bootstrapped the account and Region. Other Amazon CDK apps can use this stack. Delete it only if no other app uses it. -
The Transaction Search settings from Step 6.
-
The session role that
client.pycreated in Step 3.
To delete the session role
-
Delete the session role’s inline policy and the role.
aws iam delete-role-policy --role-name BmaSessionRole-region--policy-name BmaSession aws iam delete-role --role-name BmaSessionRole-region
To find and delete the log groups
-
Find the Runtime log groups. Replace
project-namewith the name of your project andagent-namewith the name of your agent. In Step 1, both areMyManagedAgent.aws logs describe-log-groups --log-group-name-prefix /aws/bedrock-agentcore/runtimes/project-name_agent-name- --query 'logGroups[].logGroupName' -
Find the CodeBuild log groups. Replace
project-namewith the same project name as in the previous step, andtarget-namewith the name of the deploy target inagentcore/aws-targets.json; the default isdefault. In the CodeBuild name, each underscore (_) in the project name and the target name becomes a hyphen (-).aws logs describe-log-groups --log-group-name-prefix /aws/codebuild/AgentCore-project-name-target-name- --query 'logGroups[].logGroupName' -
Find the Lambda log groups. This command lists the Lambda log groups of all AgentCore CLI projects in the Region, so identify only the ones for your project.
aws logs describe-log-groups --log-group-name-prefix /aws/lambda/AgentCore- --query 'logGroups[].logGroupName'Note
The name is shortened, as in the following example, where
suffixis a generated string./aws/lambda/AgentCore-MyManagedAgent--ApplicationAgentMyManage-suffix -
Delete each log group that you found for your project. Replace
log-group-namewith the name of the log group.aws logs delete-log-group --log-group-namelog-group-name
(Optional) To check for other resources
-
If you added other resources to the project, such as a gateway or a memory, confirm that the deploy deleted them.