get_ec2_instances
Retrieve AWS EC2 instances by region and state to monitor cloud infrastructure and manage resources.
Instructions
EC2 인스턴스 목록을 조회합니다
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_ec2_instances"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | AWS 리전 (기본값: ap-northeast-2) | ap-northeast-2 |
| state | No | 인스턴스 상태 필터 (running, stopped, pending 등) |
Implementation Reference
- src/index.ts:118-172 (handler)The main handler function that fetches EC2 instances using AWS SDK's DescribeInstancesCommand, applies optional state filter, extracts relevant instance details, and returns formatted markdown text.
async function getEC2Instances(args: any) { const region = args?.region || 'ap-northeast-2'; const state = args?.state; const client = new EC2Client({ region }); const filters = []; if (state) { filters.push({ Name: 'instance-state-name', Values: [state] }); } const command = new DescribeInstancesCommand({ Filters: filters.length > 0 ? filters : undefined }); const response = await client.send(command); const instances = []; for (const reservation of response.Reservations || []) { for (const instance of reservation.Instances || []) { const nameTag = instance.Tags?.find(tag => tag.Key === 'Name'); instances.push({ id: instance.InstanceId, name: nameTag?.Value || 'N/A', type: instance.InstanceType, state: instance.State?.Name, privateIp: instance.PrivateIpAddress, publicIp: instance.PublicIpAddress || 'N/A', launchTime: instance.LaunchTime?.toISOString(), az: instance.Placement?.AvailabilityZone }); } } return { content: [ { type: 'text', text: `📊 EC2 인스턴스 목록 (${region})\n\n` + `총 ${instances.length}개 인스턴스\n\n` + instances.map(i => `🖥️ **${i.name}** (${i.id})\n` + ` 상태: ${i.state}\n` + ` 타입: ${i.type}\n` + ` Private IP: ${i.privateIp}\n` + ` Public IP: ${i.publicIp}\n` + ` 가용영역: ${i.az}\n` ).join('\n') } ] }; } - src/index.ts:39-53 (schema)Input schema defining optional 'region' (default 'ap-northeast-2') and 'state' (enum: running, stopped, pending, terminated) parameters for the tool.
inputSchema: { type: 'object', properties: { region: { type: 'string', description: 'AWS 리전 (기본값: ap-northeast-2)', default: 'ap-northeast-2' }, state: { type: 'string', description: '인스턴스 상태 필터 (running, stopped, pending 등)', enum: ['running', 'stopped', 'pending', 'terminated'] } } } - src/index.ts:36-54 (registration)Tool metadata registration in ListToolsRequestSchema handler, including name, description, and input schema.
{ name: 'get_ec2_instances', description: 'EC2 인스턴스 목록을 조회합니다', inputSchema: { type: 'object', properties: { region: { type: 'string', description: 'AWS 리전 (기본값: ap-northeast-2)', default: 'ap-northeast-2' }, state: { type: 'string', description: '인스턴스 상태 필터 (running, stopped, pending 등)', enum: ['running', 'stopped', 'pending', 'terminated'] } } } }, - src/index.ts:93-95 (registration)Switch case in CallToolRequestSchema handler that dispatches execution to the getEC2Instances function.
case 'get_ec2_instances': return await getEC2Instances(args);