get_ec2_instances
Retrieve EC2 instance details by region and state using the AWS Helper MCP Server. Filter instances by status like running, stopped, or pending for efficient cloud resource management.
Instructions
EC2 인스턴스 목록을 조회합니다
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | AWS 리전 (기본값: ap-northeast-2) | ap-northeast-2 |
| state | No | 인스턴스 상태 필터 (running, stopped, pending 등) |
Input Schema (JSON Schema)
{
"properties": {
"region": {
"default": "ap-northeast-2",
"description": "AWS 리전 (기본값: ap-northeast-2)",
"type": "string"
},
"state": {
"description": "인스턴스 상태 필터 (running, stopped, pending 등)",
"enum": [
"running",
"stopped",
"pending",
"terminated"
],
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/index.ts:118-172 (handler)The main handler function that executes the get_ec2_instances tool. It creates an EC2 client, applies optional state filters, fetches instances using DescribeInstancesCommand, extracts relevant fields including name tag, and returns a formatted text response listing the instances.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 for the get_ec2_instances tool, defining optional 'region' and 'state' parameters with types, descriptions, defaults, and enum for state.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)Registration of the get_ec2_instances tool in the 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'] } } } },