![]() |
![]()
| ![]() |
![]()
NAMENet::Amazon::EC2 - Perl interface to the Amazon Elastic Compute Cloud (EC2) environment. VERSIONEC2 Query API version: '2014-06-15' SYNOPSISuse Net::Amazon::EC2; my $ec2 = Net::Amazon::EC2->new( AWSAccessKeyId => 'PUBLIC_KEY_HERE', SecretAccessKey => 'SECRET_KEY_HERE', signature_version => 4, ); # Start 1 new instance from AMI: ami-XXXXXXXX my $instance = $ec2->run_instances(ImageId => 'ami-XXXXXXXX', MinCount => 1, MaxCount => 1); my $running_instances = $ec2->describe_instances; foreach my $reservation (@$running_instances) { foreach my $instance ($reservation->instances_set) { print $instance->instance_id . "\n"; } } my $instance_id = $instance->instances_set->[0]->instance_id; print "$instance_id\n"; # Terminate instance my $result = $ec2->terminate_instances(InstanceId => $instance_id); If an error occurs while communicating with EC2, these methods will throw a Net::Amazon::EC2::Errors exception. DESCRIPTIONThis module is a Perl interface to Amazon's Elastic Compute Cloud. It uses the Query API to communicate with Amazon's Web Services framework. CLASS METHODSnew(%params)This is the constructor, it will return you a Net::Amazon::EC2 object to work with. It takes these parameters:
OBJECT METHODSallocate_address()Acquires an elastic IP address which can be associated with an EC2-classic instance to create a movable static IP. Takes no arguments. Returns the IP address obtained. allocate_vpc_address()Acquires an elastic IP address which can be associated with a VPC instance to create a movable static IP. Takes no arguments. Returns the allocationId of the allocated address. associate_address(%params)Associates an elastic IP address with an instance. It takes the following arguments:
Returns true if the association succeeded. attach_volume(%params)Attach a volume to an instance.
Returns a Net::Amazon::EC2::Attachment object containing the resulting volume status. authorize_security_group_ingress(%params)This method adds permissions to a security group. It takes the following parameters:
Adding a rule can be done in two ways: adding a source group name + source group owner id, or, CIDR IP range. Both methods allow IP protocol, from port and to port specifications. Returns 1 if rule is added successfully. bundle_instance(%params)Bundles the Windows instance. This procedure is not applicable for Linux and UNIX instances. NOTE NOTE NOTE This is not well tested as I don't run windows instances
Returns a Net::Amazon::EC2::BundleInstanceResponse object cancel_bundle_task(%params)Cancels the bundle task. This procedure is not applicable for Linux and UNIX instances.
Returns a Net::Amazon::EC2::BundleInstanceResponse object confirm_product_instance(%params)Checks to see if the product code passed in is attached to the instance id, taking the following parameter:
Returns a Net::Amazon::EC2::ConfirmProductInstanceResponse object create_image(%params)Creates an AMI that uses an Amazon EBS root device from a "running" or "stopped" instance. AMIs that use an Amazon EBS root device boot faster than AMIs that use instance stores. They can be up to 1 TiB in size, use storage that persists on instance failure, and can be stopped and started.
Returns the ID of the AMI created. create_key_pair(%params)Creates a new 2048 bit key pair, taking the following parameter:
Returns a Net::Amazon::EC2::KeyPair object create_security_group(%params)This method creates a new security group. It takes the following parameters:
Returns 1 if the group creation succeeds. create_snapshot(%params)Create a snapshot of a volume. It takes the following arguments:
Returns a Net::Amazon::EC2::Snapshot object of the newly created snapshot. create_tags(%params)Creates tags.
Returns true if the tag creation succeeded. create_volume(%params)Creates a volume.
Returns a Net::Amazon::EC2::Volume object containing the resulting volume status delete_key_pair(%params)This method deletes a keypair. Takes the following parameter:
Returns 1 if the key was successfully deleted. delete_security_group(%params)This method deletes a security group. It takes the following parameter:
Returns 1 if the delete succeeded. delete_snapshot(%params)Deletes the snapshots passed in. It takes the following arguments:
Returns true if the deleting succeeded. delete_volume(%params)Delete a volume.
Returns true if the deleting succeeded. delete_tags(%params)Delete tags.
Returns true if the releasing succeeded. deregister_image(%params)This method will deregister an AMI. It takes the following parameter:
Returns 1 if the deregistering succeeded describe_addresses(%params)This method describes the elastic addresses currently allocated and any instances associated with them. It takes the following arguments:
Returns an array ref of Net::Amazon::EC2::DescribeAddress objects describe_availability_zones(%params)This method describes the availability zones currently available to choose from. It takes the following arguments:
Returns an array ref of Net::Amazon::EC2::AvailabilityZone objects describe_bundle_tasks(%params)Describes current bundling tasks. This procedure is not applicable for Linux and UNIX instances.
Returns a array ref of Net::Amazon::EC2::BundleInstanceResponse objects describe_image_attributes(%params)This method pulls a list of attributes for the image id specified
Returns a Net::Amazon::EC2::DescribeImageAttribute object * NOTE: There is currently a bug in Amazon's SOAP and Query API for when you try and describe the attributes: kernel, ramdisk, blockDeviceMapping, or platform AWS returns an invalid response. No response yet from Amazon on an ETA for getting that bug fixed. describe_images(%params)This method pulls a list of the AMIs which can be run. The list can be modified by passing in some of the following parameters:
Returns an array ref of Net::Amazon::EC2::DescribeImagesResponse objects describe_instances(%params)This method pulls a list of the instances which are running or were just running. The list can be modified by passing in some of the following parameters:
Returns an array ref of Net::Amazon::EC2::ReservationInfo objects describe_instance_status(%params)This method pulls a list of the instances based on some status filter. The list can be modified by passing in some of the following parameters:
Returns an array ref of Net::Amazon::EC2::InstanceStatuses objects _create_describe_instance_status(%instanceElement)Returns a blessed object. Used internally for wrapping describe_instance_status nextToken calls
Returns a Net::Amazon::EC2::InstanceStatuses object describe_instance_attribute(%params)Returns information about an attribute of an instance. Only one attribute can be specified per call.
Returns a Net::Amazon::EC2::DescribeInstanceAttributeResponse object describe_key_pairs(%params)This method describes the keypairs available on this account. It takes the following parameter:
Returns an array ref of Net::Amazon::EC2::DescribeKeyPairsResponse objects describe_regions(%params)Describes EC2 regions that are currently available to launch instances in for this account.
Returns an array ref of Net::Amazon::EC2::Region objects describe_reserved_instances(%params)Describes Reserved Instances that you purchased.
Returns an array ref of Net::Amazon::EC2::ReservedInstance objects describe_reserved_instances_offerings(%params)Describes Reserved Instance offerings that are available for purchase. With Amazon EC2 Reserved Instances, you purchase the right to launch Amazon EC2 instances for a period of time (without getting insufficient capacity errors) and pay a lower usage rate for the actual time used.
Returns an array ref of Net::Amazon::EC2::ReservedInstanceOffering objects describe_security_groups(%params)This method describes the security groups available to this account. It takes the following parameter:
Returns an array ref of Net::Amazon::EC2::SecurityGroup objects describe_snapshot_attribute(%params)Describes the snapshots attributes related to the snapshot in question. It takes the following arguments:
Returns a Net::Amazon::EC2::SnapshotAttribute object. describe_snapshots(%params)Describes the snapshots available to the user. It takes the following arguments:
Returns an array ref of Net::Amazon::EC2::Snapshot objects. describe_volumes(%params)Describes the volumes currently created. It takes the following arguments:
Returns an array ref of Net::Amazon::EC2::Volume objects. describe_subnets(%params)This method describes the subnets on this account. It takes the following parameters:
Returns an array ref of Net::Amazon::EC2::DescribeSubnetResponse objects describe_tags(%params)This method describes the tags available on this account. It takes the following parameter:
Returns an array ref of Net::Amazon::EC2::DescribeTags objects detach_volume(%params)Detach a volume from an instance.
Returns a Net::Amazon::EC2::Attachment object containing the resulting volume status. disassociate_address(%params)Disassociates an elastic IP address with an instance. It takes the following arguments:
Returns true if the disassociation succeeded. get_console_output(%params)This method gets the output from the virtual console for an instance. It takes the following parameters:
Returns a Net::Amazon::EC2::ConsoleOutput object or "undef" if there is no new output. (This can happen in cases where the console output has not changed since the last call.) get_password_data(%params)Retrieves the encrypted administrator password for the instances running Windows. This procedure is not applicable for Linux and UNIX instances.
Returns a Net::Amazon::EC2::InstancePassword object modify_image_attribute(%params)This method modifies attributes of an machine image.
Returns 1 if the modification succeeds. modify_instance_attribute(%params)Modify an attribute of an instance.
Returns 1 if the modification succeeds. modify_snapshot_attribute(%params)This method modifies attributes of a snapshot.
Returns 1 if the modification succeeds. monitor_instances(%params)Enables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide.
Returns an array ref of Net::Amazon::EC2::MonitoredInstance objects purchase_reserved_instances_offering(%params)Purchases a Reserved Instance for use with your account. With Amazon EC2 Reserved Instances, you purchase the right to launch Amazon EC2 instances for a period of time (without getting insufficient capacity errors) and pay a lower usage rate for the actual time used.
Returns 1 if the reservations succeeded. reboot_instances(%params)This method reboots an instance. It takes the following parameters:
Returns 1 if the reboot succeeded. register_image(%params)This method registers an AMI on the EC2. It takes the following parameter:
Returns the image id of the new image on EC2. release_address(%params)Releases an allocated IP address. It takes the following arguments:
Returns true if the releasing succeeded. reset_image_attribute(%params)This method resets an attribute for an AMI to its default state (NOTE: product codes cannot be reset). It takes the following parameters:
Returns 1 if the attribute reset succeeds. reset_instance_attribute(%params)Reset an attribute of an instance. Only one attribute can be specified per call.
Returns 1 if the reset succeeds. reset_snapshot_attribute(%params)This method resets an attribute for an snapshot to its default state. It takes the following parameters:
Returns 1 if the attribute reset succeeds. revoke_security_group_ingress(%params)This method revoke permissions to a security group. It takes the following parameters:
Revoking a rule can be done in two ways: revoking a source group name + source group owner id, or, by Protocol + start port + end port + CIDR IP. The two are mutally exclusive. Returns 1 if rule is revoked successfully. run_instances(%params)This method will start instance(s) of AMIs on EC2. The parameters indicate which AMI to instantiate and how many / what properties they have:
Returns a Net::Amazon::EC2::ReservationInfo object start_instances(%params)Starts an instance that uses an Amazon EBS volume as its root device.
Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects. stop_instances(%params)Stops an instance that uses an Amazon EBS volume as its root device.
Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects. terminate_instances(%params)This method shuts down instance(s) passed into it. It takes the following parameter:
Returns an array ref of Net::Amazon::EC2::InstanceStateChange objects. unmonitor_instances(%params)Disables monitoring for a running instance. For more information, refer to the Amazon CloudWatch Developer Guide.
Returns an array ref of Net::Amazon::EC2::MonitoredInstance objects TESTINGSet AWS_ACCESS_KEY_ID and SECRET_ACCESS_KEY environment variables to run the live tests. Note: because the live tests start an instance (and kill it) in both the tests and backwards compat tests there will be 2 hours of machine instance usage charges (since there are 2 instances started) which as of February 1st, 2010 costs a total of $0.17 USD Important note about the windows-only methods. These have not been well tested as I do not run windows-based instances, so exercise caution in using these. BUGSPlease report any bugs or feature requests to "bug-net-amazon-ec2 at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Amazon-EC2>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. AUTHORJeff Kim <cpan@chosec.com> CONTRIBUTORSJohn McCullough and others as listed in the Changelog MAINTAINERThe current maintainer is Mark Allen "<mallen@cpan.org>" COPYRIGHTCopyright (c) 2006-2010 Jeff Kim. Copyright (c) 2012 Mark Allen. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSOAmazon EC2 API: <http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/>
|