Class: AwsCftTools::Client::EC2
- Defined in:
- lib/aws_cft_tools/client/ec2.rb
Overview
EC2 Instance Client
All of the business logic behind direct interaction with the AWS API for EC2 instances and related resources.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#images ⇒ Array<OpenStruct>
Returns a list of available AMI images filtered by any environment or role specified in the options passed to the constructor.
-
#initialize(options) ⇒ EC2
constructor
A new instance of EC2.
-
#instances ⇒ Array<OpenStruct>
Returns a list of running instances filtered by any environment or role specified in the options passed to the constructor.
Methods inherited from Base
Constructor Details
#initialize(options) ⇒ EC2
Returns a new instance of EC2.
20 21 22 |
# File 'lib/aws_cft_tools/client/ec2.rb', line 20 def initialize() super() end |
Class Method Details
.aws_client_class ⇒ Object
24 25 26 |
# File 'lib/aws_cft_tools/client/ec2.rb', line 24 def self.aws_client_class Aws::EC2::Resource end |
Instance Method Details
#images ⇒ Array<OpenStruct>
Returns a list of available AMI images filtered by any environment or role specified in the options passed to the constructor.
Each image is represented by an OpenStruct with the following keys/methods:
-
image_id: the ID of the AMI or image
-
type: the type of AMI or image
-
public: a flag indicating if the image is public
-
created_at: the date/time at which the image was created
-
role: the value of the ‘Role` tag if not filtering by role
-
environment: the value of the ‘Environment` tag if not filtering by environment
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/aws_cft_tools/client/ec2.rb', line 65 def images @images ||= aws_client.images(owners: ['self'], filters: image_filters).map do |image| OpenStruct.new( (image, image_id: image.image_id, type: image.image_type, public: image.public, created_at: image.creation_date) ) end end |
#instances ⇒ Array<OpenStruct>
Returns a list of running instances filtered by any environment or role specified in the options passed to the constructor.
Each instance is represented by a Hash with the following keys:
-
private_ip: the private IP address of the instance
-
public_ip: the public IP address (if any) of the instance
-
instance: the ID of the instance
-
role: the value of the ‘Role` tag if not filtering by role
-
environment: the value of the ‘Environment` tag if not filtering by environment
41 42 43 44 45 46 47 48 49 |
# File 'lib/aws_cft_tools/client/ec2.rb', line 41 def instances @instances ||= aws_client.instances(filters: instance_filters).map do |instance| OpenStruct.new( (instance, private_ip: instance.private_ip_address, public_ip: instance.public_ip_address, instance: instance.instance_id) ) end end |