継続は力なり

タイトル通り定期的な更新を心掛けるブログです。

Bedrock AgentCore Runtime のチュートリアルを触ってみたメモ

タダです.

Bedrock AgentCore がプレビューリリースされました.自分も気になっていたもののサービスを触れていなかったのですが,Bedrock AgentCore Runtime に関するチュートリアル記事がでたためこれはチャンスと思って触ってみました.

aws.amazon.com

aws.amazon.com

Bedrock AgentCore Runtime のチュートリアル

Bedrock AgentCore Runtime はAI エージェントを本番環境向けにデプロイ・ホスティングするで,チュートリアルでは Strands Agent SDK を使って最低限のエージェントを動作させる内容です.以下のコードが最低限のエージェントを動かすコードでプロンプトに対する回答を返すだけなんですが,このコード量でやってくれるのは驚きですね.

from bedrock_agentcore.runtime import BedrockAgentCoreApp
from strands import Agent

app = BedrockAgentCoreApp()
agent = Agent()

@app.entrypoint
def invoke(payload):
    user_message = payload.get("prompt")
    result = agent(user_message)
    return {"result": result.message}

if __name__ == "__main__":
    app.run()

次にエージェントを動かすために必要なパッケージを requirements.txt で定義して Bedrock AgentCore をデプロイ設定を行います.

❯ agentcore configure -e my_agent.py                                             
Configuring Bedrock AgentCore...
Entrypoint parsed: file=/tmp/bedrock-agent-core-runtime-sandbox/my_agent.py, bedrock_agentcore_name=my_agent
Agent name: my_agent

🔐 Execution Role
Press Enter to auto-create execution role, or provide execution role ARN/name to use existing
Execution role ARN/name (or press Enter to auto-create):
✓ Will auto-create execution role

🏗️  ECR Repository
Press Enter to auto-create ECR repository, or provide ECR Repository URI to use existing
ECR Repository URI (or press Enter to auto-create):
✓ Will auto-create ECR repository

🔍 Detected dependency file: requirements.txt
Press Enter to use this file, or type a different path (use Tab for autocomplete):
Path or Press Enter to use detected dependency file:
✓ Using detected file: requirements.txt

🔐 Authorization Configuration
By default, Bedrock AgentCore uses IAM authorization.
Configure OAuth authorizer instead? (yes/no) [no]: no
✓ Using default IAM authorization
Configuring BedrockAgentCore agent: my_agent

⚠️  ℹ️  No container engine found (Docker/Finch/Podman not installed)
✅ Default deployment uses CodeBuild (no container engine needed)
💡 Run 'agentcore launch' for cloud-based building and deployment
💡 For local builds, install Docker, Finch, or Podman
Generated Dockerfile: /tmp/bedrock-agent-core-runtime-sandbox/Dockerfile
Generated .dockerignore: /tmp/bedrock-agent-core-runtime-sandbox/.dockerignore
Keeping 'my_agent' as default agent
╭──────────────────────────────────────────────────────────────────────────── Bedrock AgentCore Configured ────────────────────────────────────────────────────────────────────────────╮
│ Configuration Summary                                                                                                                                                                │
│                                                                                                                                                                                      │
│ Name: my_agent                                                                                                                                                                       │
│ Runtime: None                                                                                                                                                                        │
│ Region: us-east-1                                                                                                                                                                    │
│ Account: 1234567891011                                                                                                                                                                │
│ Execution Role: None                                                                                                                                                                 │
│ ECR: Auto-create                                                                                                                                                                     │
│ Authorization: IAM (default)                                                                                                                                                         │
│                                                                                                                                                                                      │
│ Configuration saved to: /tmp/bedrock-agent-core-runtime-sandbox/.bedrock_agentcore.yaml                                                 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

設定に関する質問を回答すると以下のファイルが追加されます.

  • .bedrock_agentcore.yaml
  • Dockerfile
  • .dockerignore

デプロイコマンドを実行するとバージニアリージョンに Bedrock AgentCore Runtime のリソースができていました.

❯ agentcore launch                  
🚀 Launching Bedrock AgentCore (codebuild mode - RECOMMENDED)...
   • Build ARM64 containers in the cloud with CodeBuild
   • No local Docker required (DEFAULT behavior)
   • Production-ready deployment

💡 Deployment options:
   • agentcore launch                → CodeBuild (current)
   • agentcore launch --local        → Local development
   • agentcore launch --local-build  → Local build + cloud deploy

~中略~
╭─────────────────────────────────────────────────────────────────────────── CodeBuild Deployment Complete ────────────────────────────────────────────────────────────────────────────╮
│ CodeBuild ARM64 Deployment Successful!                                                                                                                                               │
│                                                                                                                                                                                      │
│ Agent Name: my_agent                                                                                                                                                                 │
│ CodeBuild ID: bedrock-agentcore-my_agent-builder:e3b04eab-b507-407e-9100-14b3dbbdbbdd                                                                                                │
│ Agent ARN: arn:aws:bedrock-agentcore:us-east-1:1234567891011:runtime/my_agent-agpWz56yJQ                                                                                              │
│ ECR URI: 1234567891011.dkr.ecr.us-east-1.amazonaws.com/bedrock-agentcore-my_agent:latest                                                                                              │
│                                                                                                                                                                                      │
│ ARM64 container deployed to Bedrock AgentCore.                                                                                                                                       │
│                                                                                                                                                                                      │
│ You can now check the status of your Bedrock AgentCore endpoint with:                                                                                                                │
│ agentcore status                                                                                                                                                                     │
│                                                                                                                                                                                      │
│ You can now invoke your Bedrock AgentCore endpoint with:                                                                                                                             │
│ agentcore invoke '{"prompt": "Hello"}'                                                                                                                                               │
│                                                                                                                                                                                      │
│ 📋 Agent logs available at:                                                                                                                                                          │
│    /aws/bedrock-agentcore/runtimes/my_agent-agpWz56yJQ-DEFAULT                                                                                                                       │
│    /aws/bedrock-agentcore/runtimes/my_agent-agpWz56yJQ-DEFAULT/runtime-logs                                                                                                          │
│                                                                                                                                                                                      │
│ 💡 Tail logs with:                                                                                                                                                                   │
│    aws logs tail /aws/bedrock-agentcore/runtimes/my_agent-agpWz56yJQ-DEFAULT --follow                                                                                                │
│    aws logs tail /aws/bedrock-agentcore/runtimes/my_agent-agpWz56yJQ-DEFAULT --since 1h                                                                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

デプロイで来たのでプロンプトで話しかけて見るときは以下のように行ってみます.Hello に対する回答が返ってきました.

❯ agentcore invoke '{"prompt": "Hello"}'     
Payload:
{
  "prompt": "Hello"
}
Invoking BedrockAgentCore agent 'my_agent' via cloud endpoint
Session ID: bf85fc18-907a-4c79-bc75-1bf9e3873a89

Response:
{
  "ResponseMetadata": {
    "RequestId": "cda0512b-20fb-437c-9e2a-ad63acb9d0b6",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Sun, 17 Aug 2025 00:55:21 GMT",
      "content-type": "application/json",
      "transfer-encoding": "chunked",
      "connection": "keep-alive",
      "x-amzn-requestid": "cda0512b-20fb-437c-9e2a-ad63acb9d0b6",
      "baggage": "Self=1-68a12877-50cf024362bf33431a52a653,session.id=bf85fc18-907a-4c79-bc75-1bf9e3873a89",
      "x-amzn-bedrock-agentcore-runtime-session-id": "bf85fc18-907a-4c79-bc75-1bf9e3873a89",
      "x-amzn-trace-id": "Root=1-68a12877-12b90c6d736ddc9c6f483e71;Self=1-68a12877-50cf024362bf33431a52a653"
    },
    "RetryAttempts": 0
  },
  "runtimeSessionId": "bf85fc18-907a-4c79-bc75-1bf9e3873a89",
  "traceId": "Root=1-68a12877-12b90c6d736ddc9c6f483e71;Self=1-68a12877-50cf024362bf33431a52a653",
  "baggage": "Self=1-68a12877-50cf024362bf33431a52a653,session.id=bf85fc18-907a-4c79-bc75-1bf9e3873a89",
  "contentType": "application/json",
  "statusCode": 200,
  "response": [
    "b'{\"result\": {\"role\": \"assistant\", \"content\": [{\"text\": \"Hello! How are you doing today? Is there anything I can help you with?\"}]}}'"
  ]
}

このエージェントのログは CloudWatch Logs に出力され,トレースも CloudWatch の GenAI Observability のページで確認することができました.

まとめ

サクッと Bedrock AgentCore Runtime にデプロイや操作を試すのに良いコンテンツだと感じました!まだ自分自身で Bedrock AgentCore の関連コンポーネントや使用感を理解しきれていないためもっと触ってみます.