MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / EC2Service

Class EC2Service

scripts/agents/devops/src/aws/ec2.py:23–828  ·  view source on GitHub ↗

Service class for managing AWS EC2 resources. Provides methods for creating, configuring, and managing EC2 instances and related resources like security groups, key pairs, and volumes.

Source from the content-addressed store, hash-verified

21
22
23class EC2Service(AWSBaseService):
24 """
25 Service class for managing AWS EC2 resources.
26
27 Provides methods for creating, configuring, and managing EC2 instances
28 and related resources like security groups, key pairs, and volumes.
29 """
30
31 SERVICE_NAME = "ec2"
32
33 def __init__(
34 self,
35 credentials: Optional[AWSCredentials] = None,
36 region: Optional[str] = None,
37 profile_name: Optional[str] = None,
38 endpoint_url: Optional[str] = None,
39 skip_verification: bool = False
40 ):
41 self.skip_verification = skip_verification
42 super().__init__(credentials, region, profile_name, endpoint_url)
43
44 def _verify_access(self) -> None:
45 """Verify EC2 access by describing instances."""
46 if not self.skip_verification:
47 try:
48 self.client.describe_instances(MaxResults=5)
49 except Exception as e:
50 self.handle_error(e, "verify_ec2_access")
51
52 #
53 # Instance Management
54 #
55
56 @aws_operation("list_instances")
57 def list_instances(
58 self,
59 filters: Optional[List[Dict[str, Any]]] = None,
60 instance_ids: Optional[List[str]] = None
61 ) -> List[Dict[str, Any]]:
62 """
63 List EC2 instances with optional filtering.
64
65 Args:
66 filters: List of filters to apply. Each filter is a dict with 'Name' and 'Values' keys.
67 Example: [{'Name': 'instance-state-name', 'Values': ['running']}]
68 instance_ids: Optional list of instance IDs to filter by.
69
70 Returns:
71 List of instance details.
72 """
73 kwargs = {}
74 if filters:
75 kwargs['Filters'] = filters
76 if instance_ids:
77 kwargs['InstanceIds'] = instance_ids
78
79 response = self.client.describe_instances(**kwargs)
80

Callers 5

ec2_serviceFunction · 0.90
mainFunction · 0.90
handle_ec2_commandFunction · 0.85
handle_deploy_commandFunction · 0.85
deploy_to_awsMethod · 0.85

Calls

no outgoing calls

Tested by 1

ec2_serviceFunction · 0.72