ec2#
Abstract dataclass for EC2 instance.
- class simple_aws_ec2.ec2.EC2InstanceStatusEnum(value)[source]#
EC2 instance status enumerations.
See also: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-instance-state-changes.html
- class simple_aws_ec2.ec2.EC2InstanceStatusGroupEnum[source]#
Aggregate EC2 instance status into logical groups.
- Variables:
ended – status won’t change anymore
in_transition – status is in transition
- class simple_aws_ec2.ec2.EC2InstanceArchitectureEnum(value)[source]#
Ec2 instance architecture enumerations.
- class simple_aws_ec2.ec2.Ec2InstanceHypervisorEnum(value)[source]#
Ec2 instance hypervisor enumerations.
- class simple_aws_ec2.ec2.Ec2Instance(id: str, status: str, status_transition_reason: ~typing.Optional[str] = None, public_ip: ~typing.Optional[str] = None, private_ip: ~typing.Optional[str] = None, public_dns_name: ~typing.Optional[str] = None, private_dns_name: ~typing.Optional[str] = None, vpc_id: ~typing.Optional[str] = None, subnet_id: ~typing.Optional[str] = None, security_groups: ~typing.List[~typing.Dict[str, str]] = <factory>, image_id: ~typing.Optional[str] = None, platform: ~typing.Optional[str] = None, platform_details: ~typing.Optional[str] = None, instance_type: ~typing.Optional[str] = None, launch_time: ~typing.Optional[~datetime.datetime] = None, key_name: ~typing.Optional[str] = None, architecture: ~typing.Optional[str] = None, ebs_optimized: ~typing.Optional[bool] = None, ena_support: ~typing.Optional[bool] = None, hypervisor: ~typing.Optional[str] = None, iam_instance_profile_arn: ~typing.Optional[str] = None, iam_instance_profile_id: ~typing.Optional[str] = None, instance_lifecycle: ~typing.Optional[str] = None, root_device_name: ~typing.Optional[str] = None, root_device_type: ~typing.Optional[str] = None, spot_instance_request_id: ~typing.Optional[str] = None, sriov_net_support: ~typing.Optional[str] = None, virtualization_type: ~typing.Optional[str] = None, boot_mode: ~typing.Optional[str] = None, usage_operation: ~typing.Optional[str] = None, usage_operation_update_time: ~typing.Optional[~datetime.datetime] = None, current_instance_boot_mode: ~typing.Optional[str] = None, ipv6_address: ~typing.Optional[str] = None, tags: ~typing.Dict[str, str] = <factory>, data: ~typing.Dict[str, ~typing.Any] = <factory>)[source]#
Represent an EC2 instance.
- classmethod from_dict(dct: dict)[source]#
Create an EC2 instance object from the
describe_instancesAPI response.Ref:
- terminate_instance(ec2_client: EC2Client) TerminateInstancesResultTypeDef[source]#
Terminate instance.
- wait_for_status(ec2_client: EC2Client, stop_status: Union[EC2InstanceStatusEnum, List[EC2InstanceStatusEnum]], gap: Union[int, float] = 1, delays: Union[int, float] = 10, timeout: Union[int, float] = 300, instant: bool = True, error_status: Optional[Union[EC2InstanceStatusEnum, List[EC2InstanceStatusEnum]]] = None, indent: int = 0, verbose: bool = True) Ec2Instance[source]#
wait until the EC2 instance reaches the specified status defined in
stop_status. If reaches any of ``error_status ``, raise error.- Parameters:
ec2_client –
stop_status – status to stop waiting
gap – the time to wait before making first status check
delays – delay between each check
timeout – timeout in seconds
instant – if True, then the first check is instant
error_status – status to raise error
indent – indent level for logging
verbose – whether to print log
- Returns:
the
Ec2Instancerepresenting the latest status.
- wait_for_running(ec2_client: EC2Client, gap: Union[int, float] = 1, delays: Union[int, float] = 10, timeout: Union[int, float] = 300, instant: bool = True, indent: int = 0, verbose: bool = True) Ec2Instance[source]#
Similar to
Ec2Instance.wait_for_status(), but wait for EC2 instance to reach “running” status.
- wait_for_stopped(ec2_client: EC2Client, gap: Union[int, float] = 1, delays: Union[int, float] = 10, timeout: Union[int, float] = 300, instant: bool = True, indent: int = 0, verbose: bool = True) Ec2Instance[source]#
Similar to
Ec2Instance.wait_for_status(), but wait for EC2 instance to reach “stopped” status.
- wait_for_terminated(ec2_client: EC2Client, gap: Union[int, float] = 1, delays: Union[int, float] = 10, timeout: Union[int, float] = 300, instant: bool = True, indent: int = 0, verbose: bool = True) Ec2Instance[source]#
Similar to
Ec2Instance.wait_for_status(), but wait for EC2 instance to reach “terminated” status.
- classmethod query(ec2_client: EC2Client, filters: List[dict] = Sentinel('NOTHING'), instance_ids: List[str] = Sentinel('NOTHING')) Ec2InstanceIterProxy[source]#
A wrapper around
ec2_client.describe_instances.Multiple filters join with logic “AND”, multiple values in a filter join with logic “OR”.
- classmethod from_id(ec2_client: EC2Client, inst_id: str) Optional[Ec2Instance][source]#
Get ec2 instance details by it’s id.
- classmethod from_ec2_inside(ec2_client: EC2Client) Optional[Ec2Instance][source]#
Use ec2 metadata API to get the instance id.
Note
This function should only be called on an EC2 instance
- classmethod from_tag_key_value(ec2_client: EC2Client, key: str, value: Union[str, Iterable[str]]) Ec2InstanceIterProxy[source]#
Query EC2 Instance by tag key and values.
- Parameters:
key – tag key
value – tag value or values
- classmethod from_ec2_name(ec2_client: EC2Client, name: Union[str, Iterable[str]]) Ec2InstanceIterProxy[source]#
Get EC2 instance details by the
tag:name.
- classmethod get_ami_id() str[source]#
Get the AMI id of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_instance_id() str[source]#
Get the instance id of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_instance_type() str[source]#
Get the instance type of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_hostname() str[source]#
Get the hostname of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_local_hostname() str[source]#
Get the local hostname of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_local_ipv4() str[source]#
Get the local ipv4 of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_public_hostname() str[source]#
Get the public hostname of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_public_ipv4() str[source]#
Get the public ipv4 of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_security_groups() List[str][source]#
Get the security groups of the EC2 instance. This method should only be used within EC2 instance.
- classmethod get_iam_info() Dict[str, str][source]#
Get the IAM info of the EC2 instance. This method should only be used within EC2 instance.
Example response:
{ "Code" : "Success", "LastUpdated" : "2023-01-01T00:00:00Z", "InstanceProfileId" : "ABCD..." "InstanceProfileArn" : "arn:aws:iam::111122223333:instance-profile/profile-name", }
- class simple_aws_ec2.ec2.Ec2InstanceIterProxy(iterable: Iterable)[source]#
Advanced iterator proxy for
Ec2Instance.
- class simple_aws_ec2.ec2.ImageRootDeviceTypeEnum(value)[source]#
AMI Image root device type enumerations.
- class simple_aws_ec2.ec2.ImageVirtualizationTypeEnum(value)[source]#
AMI Image virtualization type enumerations.
- class simple_aws_ec2.ec2.Image(id: str, image_location: ~typing.Optional[str] = None, image_type: ~typing.Optional[str] = None, architecture: ~typing.Optional[str] = None, creation_date: ~typing.Optional[str] = None, public: ~typing.Optional[bool] = None, kernel_id: ~typing.Optional[str] = None, owner_id: ~typing.Optional[str] = None, platform: ~typing.Optional[str] = None, platform_details: ~typing.Optional[str] = None, usage_operation: ~typing.Optional[str] = None, ramdisk_id: ~typing.Optional[str] = None, state: ~typing.Optional[str] = None, state_reason_code: ~typing.Optional[str] = None, state_reason_message: ~typing.Optional[str] = None, description: ~typing.Optional[str] = None, ena_support: ~typing.Optional[bool] = None, hypervisor: ~typing.Optional[str] = None, image_owner_alias: ~typing.Optional[str] = None, name: ~typing.Optional[str] = None, root_device_name: ~typing.Optional[str] = None, root_device_type: ~typing.Optional[str] = None, sriov_net_support: ~typing.Optional[str] = None, virtualization_type: ~typing.Optional[str] = None, boot_mode: ~typing.Optional[str] = None, tpm_support: ~typing.Optional[str] = None, deprecation_time: ~typing.Optional[str] = None, imds_support: ~typing.Optional[str] = None, tags: ~typing.Dict[str, str] = <factory>, data: ~typing.Dict[str, ~typing.Any] = <factory>)[source]#
Represent an AMI image.
- classmethod from_dict(dct: dict)[source]#
Create an AMI Image object from the
describe_imagesAPI response.Ref:
- image_root_device_type_is_instance_store() bool[source]#
Check if the image root device type is instance store.
- image_virtualization_type_is_paravirtual() bool[source]#
Check if the image virtualization type is paravirtual.
- property os_type: ImageOSTypeEnum#
Try to use the image name and description to determine the OS type.
If the OS type cannot be determined, raise
CannotDetectOSTypeError.
- property users: List[str]#
Return the potential default user names for the Image. It try to use the image name and description to determine the OS type. If the OS type cannot be determined, raise
CannotDetectOSTypeError.
- classmethod query(ec2_client: EC2Client, filters: List[dict] = Sentinel('NOTHING'), image_ids: List[str] = Sentinel('NOTHING'), executable_users: List[str] = Sentinel('NOTHING'), owners: List[str] = Sentinel('NOTHING'), include_deprecated: bool = Sentinel('NOTHING')) ImageIterProxy[source]#
A wrapper around
ec2_client.describe_images.Multiple filters join with logic “AND”, multiple values in a filter join with logic “OR”.
- classmethod from_id(ec2_client: EC2Client, image_id: str) Optional[Image][source]#
Get
Imageobject by the image id.
- classmethod from_tag_key_value(ec2_client: EC2Client, key: str, value: Union[str, Iterable[str]]) ImageIterProxy[source]#
Query AMI Image by tag key and values.
- Parameters:
key – tag key
value – tag value or values
- classmethod from_image_name(ec2_client: EC2Client, name: Union[str, Iterable[str]]) ImageIterProxy[source]#
Get image details by the name of the AMI (provided during image creation). This name is not the
tag:name
- classmethod from_ec2_inside(ec2_client: EC2Client) Optional[Image][source]#
Use ec2 metadata API to get the instance id, then get the image details
Note
This function should only be called on an EC2 instance
- deregister(ec2_client: EC2Client, delete_snapshot: bool = False, skip_prompt: bool = False, verbose: bool = False)[source]#
Deregister this image.
- Parameters:
delete_snapshot – if True, also delete the snapshot.
skip_prompt – by default, it prompts to confirm. You can set it to True, to skip the prompt.
verbose – whether to print log
- wait_for_status(ec2_client: EC2Client, stop_status: Union[ImageStateEnum, List[ImageStateEnum]], gap: Union[int, float] = 1, delays: Union[int, float] = 10, timeout: Union[int, float] = 300, instant: bool = True, error_status: Optional[Union[ImageStateEnum, List[ImageStateEnum]]] = None, indent: int = 0, verbose: bool = True) Image[source]#
wait until the AMI Image reaches the specified status defined in
stop_status. If reaches any of ``error_status ``, raise error.- Parameters:
ec2_client –
stop_status – status to stop waiting
gap – the time to wait before making first status check
delays – delay between each check
timeout – timeout in seconds
instant – if True, then the first check is instant
error_status – status to raise error
indent – indent level for logging
verbose – whether to print log
- Returns:
the
Imagerepresenting the latest status.
- class simple_aws_ec2.ec2.ImageIterProxy(iterable: Iterable)[source]#
Advanced iterator proxy for
Image.
- class simple_aws_ec2.ec2.Eip(allocation_id: ~typing.Optional[str] = None, public_ip: ~typing.Optional[str] = None, association_id: ~typing.Optional[str] = None, instance_id: ~typing.Optional[str] = None, domain: ~typing.Optional[str] = None, network_interface_id: ~typing.Optional[str] = None, network_interface_owner_id: ~typing.Optional[str] = None, private_ip_address: ~typing.Optional[str] = None, public_ipv4_pool: ~typing.Optional[str] = None, network_border_group: ~typing.Optional[str] = None, customer_owned_ip: ~typing.Optional[str] = None, customer_owned_ipv4_pool: ~typing.Optional[str] = None, carrier_ip: ~typing.Optional[str] = None, tags: ~typing.Dict[str, str] = <factory>, data: ~typing.Dict[str, ~typing.Any] = <factory>)[source]#
Represent an Elastic IP Address.
- classmethod from_dict(dct: dict)[source]#
Create an AMI Image object from the
describe_imagesAPI response.Ref:
- classmethod query(ec2_client: EC2Client, filters: List[dict] = Sentinel('NOTHING'), allocation_ids: List[str] = Sentinel('NOTHING'), public_ips: List[str] = Sentinel('NOTHING')) EipIterProxy[source]#
A wrapper around
ec2_client.describe_addresses.Multiple filters join with logic “AND”, multiple values in a filter join with logic “OR”.