🧬
AWS CLIのプロファイル名を指定してStrands Agentsを使用する方法
Strands Agentsの概要
Strands AgentsとはAWSが開発したAIエージェント構築のためのSDKです。
Pythonコード数行でAIエージェントを簡単に構築できることが特長です。
AWS CLIのプロファイル名を指定してStrands Agentsを使用してみた
まず、私はStrands Agentsのユーザガイドのトップページに載っているソースコードをそのまま実行してみました。
from strands import Agent
# Create an agent with default settings
agent = Agent()
# Ask the agent a question
agent("Tell me about agentic AI")
すると、botocore.exceptions.NoCredentialsError: Unable to locate credentialsというエラーが出てしまいました…。
どうやらAWSの認証情報を設定しておかないといけないようです。
普段、Boto3 (AWS SDK for Python) を使うときは、以下のようにAWS CLIのプロファイル名を指定して実行しています。
import boto3
session = boto3.Session(profile_name="test")
そこで、今回も同じようにプロファイル名を指定できるか調べてみたところ、Strands Agentsのユーザガイドに書式が掲載されていました。
import boto3
from strands.models import BedrockModel
from strands import Agent
session = boto3.Session(profile_name="test")
bedrock_model = BedrockModel(
model_id="jp.anthropic.claude-sonnet-4-5-20250929-v1:0",
boto_session=session
)
agent = Agent(model=bedrock_model)
agent("Tell me about agentic AI")
これで普段使用しているAWS認証情報で実行することができました。
Discussion