AgentCore Gateway 시작하기
이 빠른 시작 안내서에서는 AgentCore CLI를 사용하여 게이트웨이를 설정하고 에이전트에 통합하는 방법을 알아봅니다. 보다 포괄적인 가이드와 예제는 Amazon Bedrock AgentCore Gateway GitHub 리포지토리
참고
AgentCore CLI는 AgentCore Gateway 리소스를 관리하기 위한 명령과 대화형 TUI 마법사를 모두 제공합니다. 전체 AWS SDK API 참조는 AgentCore 컨트롤 플레인 작업을
사전 조건
시작하기 전에 다음이 있는지 확인합니다.
-
AWS 자격 증명이 구성된 계정입니다. 자격 증명을 구성하려면 CLI 시작하기의 단계에 따라 AWS 명령줄 인터페이스를 설치하고 사용할 수 있습니다. AWS
-
Node.js 18 이상이 설치되었습니다( AgentCore CLI용).
-
Python 3.10 이상이 설치됨(에이전트 스크립트용).
-
역할, Lambda 함수를 생성하고 Amazon Bedrock AgentCore를 사용하기 위한 IAM 권한.
-
모델 액세스 - Amazon Bedrock 콘솔(또는 데모 에이전트용 다른 모델)에서 Anthropic의 Claude Sonnet 3.7 활성화
1단계: 설정 및 설치
AgentCore CLI를 전역적으로 설치합니다.
npm install -g @aws/agentcore
에이전트와 게이트웨이를 사용하여 새 AgentCore 프로젝트를 생성합니다.
예
2단계: 게이트웨이 생성
AgentCore CLI를 사용하여 게이트웨이와 대상을 프로젝트에 추가합니다.
예
대신 JWT 기반 권한 부여를 사용하려면 OAuth 검색 URL--authorizer-type CUSTOM_JWT로를 지정합니다.
예
3단계: 설정 실행
프로젝트를 AWS다음에 배포합니다.
agentcore deploy
CLI는 AWS CDK 스택을 합성하고 게이트웨이, 대상 및 에이전트를 Amazon Bedrock AgentCore에 배포합니다. 이 작업은 약 2~3분이 걸립니다.
4단계: 에이전트와 함께 게이트웨이 사용
AgentCore CLI를 사용하여 게이트웨이 URL을 검색합니다.
agentcore status
라는 새 파일을 run_agent.py 생성하고 다음 코드를 삽입합니다. 먼저 Python 종속성을 설치합니다.
pip install strands-agents mcp
""" Agent script to test the Gateway Run this after setup: python run_agent.py """ from strands import Agent from strands.models import BedrockModel from strands.tools.mcp.mcp_client import MCPClient from mcp.client.streamable_http import streamablehttp_client import json import sys def create_streamable_http_transport(mcp_url: str): return streamablehttp_client(mcp_url) def get_full_tools_list(client): """Get all tools with pagination support""" more_tools = True tools = [] pagination_token = None while more_tools: tmp_tools = client.list_tools_sync(pagination_token=pagination_token) tools.extend(tmp_tools) if tmp_tools.pagination_token is None: more_tools = False else: more_tools = True pagination_token = tmp_tools.pagination_token return tools def run_agent(): # Get the gateway URL from agentcore status gateway_url = "<YOUR_GATEWAY_URL>" # Replace with URL from 'agentcore status' # Model configuration - change if needed model_id = "anthropic.claude-3-7-sonnet-20250219-v1:0" print("Starting AgentCore Gateway Test Agent") print(f"Gateway URL: {gateway_url}") print(f"Model: {model_id}") print("-" * 60) # Setup Bedrock model bedrockmodel = BedrockModel( model_id=model_id, streaming=True, ) # Setup MCP client (no auth token needed for NONE authorizer) mcp_client = MCPClient(lambda: create_streamable_http_transport(gateway_url)) with mcp_client: # List available tools tools = get_full_tools_list(mcp_client) print(f"\nAvailable tools: {[tool.tool_name for tool in tools]}") print("-" * 60) # Create agent agent = Agent(model=bedrockmodel, tools=tools) # Interactive loop print("\nInteractive Agent Ready!") print("Try asking: 'What's the weather in Seattle?'") print("Type 'exit', 'quit', or 'bye' to end.\n") while True: user_input = input("You: ") if user_input.lower() in ["exit", "quit", "bye"]: print("Goodbye!") break print("\nThinking...\n") response = agent(user_input) print(f"\nAgent: {response.message.get('content', response)}\n") if __name__ == "__main__": run_agent()
에이전트 실행
에이전트를 실행하고 도구와 상호 작용하여 게이트웨이를 테스트합니다.
python run_agent.py
이것이 바로 입니다! 에이전트가 시작되고 다음과 같은 질문을 할 수 있습니다.
-
“시애틀의 날씨는 어떤가요?”
-
“뉴욕은 몇 시인가요?”
빌드한 내용
이 시작하기 자습서를 통해 다음 리소스를 생성했습니다.
-
MCP 서버(게이트웨이) :의 관리형 엔드포인트
https://gateway-id.gateway.bedrock-agentcore.region.amazonaws.com/mcp -
Lambda 도구: 테스트 데이터를 반환하는 모의 함수(오늘날: "72°F, Sunny", 시간: "2:30 PM")
-
AI 에이전트: 도구를 검색하고 사용할 수 있는 Claude 기반 어시스턴트
문제 해결
다음 표에는 몇 가지 가능한 문제와 해결 방법이 나와 있습니다.
| 문제 | Solution |
|---|---|
|
"'strands'라는 모듈 없음" |
실행: |
|
“모델이 활성화되지 않음” |
Bedrock 콘솔에서 Claude Sonnet 3.7 활성화 → 모델 액세스 |
|
“AccessDeniedException” |
bedrock-agentcore에 대한 IAM 권한 확인:* |
|
게이트웨이가 응답하지 않음 |
DNS 전파를 위해 생성 후 30~60초 대기 |
빠른 검증
터미널에서 다음 명령을 실행하여 게이트웨이가 작동하는지 확인합니다.
# Check your Gateway is working curl -X POST YOUR_GATEWAY_URL \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' # Watch live logs aws logs tail /aws/bedrock-agentcore/gateways/YOUR_GATEWAY_ID --follow
정리
프로젝트에서 게이트웨이와 해당 대상을 제거하려면:
agentcore remove gateway --name TestGateway
모든 리소스를 제거하고 재배포하려면:
agentcore remove all agentcore deploy
다음 단계
-
사용자 지정 Lambda 도구: 비즈니스 로직을 사용하여 Lambda 함수 생성
-
자체 APIs 추가: 실제 서비스에 대한 OpenAPI 사양으로 게이트웨이 확장
-
프로덕션 설정: VPC 엔드포인트, 사용자 지정 도메인 및 모니터링 구성