AWS News Blog

New Resource APIs in Version 2 of the AWS SDK for Ruby

We are launching a preview of a new, resource-style API model for the AWS SDK for Ruby. I will summarize the preview here, and refer you to the post AWS SDK for Ruby 2 Preview Release on the AWS Ruby Development Blog for full information!

If youve used Version 1 of the AWS SDK for Ruby, you are likely already familiar with resource objects available for a number of services. These resource objects allow you to work with AWS resources as Ruby objects with attributes that are automatically loaded from the service and instance methods that map to API actions that can be taken on the resource. The interface also provides collection classes for easy iteration.

With the lessons learned from resource objects in Version 1, were now introducing improved resource APIs in the Version 2 of the SDK. We have made three big changes to the model. First, resource objects now hold on to metadata retrieved from the service until explicitly reloaded by the user. This provides more control over network calls made by the SDK and helps users avoid unwanted or unnecessary HTTP requests. Second, we are newly introducing resource waiters, which allow you to wait on a resource to reach a specified state. Third, the resource objects are now data-driven by models defined in JSON. This allows a more structured and consistent definition of resource objects across different AWS services. Additionally, because we plan to share the same models in AWS SDKs for other languages, customers who need to work with multiple languages will be able to easily go from one language to another and work with similar resource definitions in the future.

Heres an example of using a resource object representing an EC2 instance, along with a waiter method wait_until_stopped (new in the Version 2 SDK):


  instance = ec2.instance('i-1234567') # Get reference to instance
  instance.stop # Stop instance
  instance.wait_until_stopped # Wait until instance is stopped
  puts instance.id + 'has been stopped.'

The resource APIs and resource waiters are now available for the following 6 services in the Version 2 preview release of the SDK for Ruby: Amazon Elastic Compute Cloud (Amazon EC2), Amazon Simple Storage Service (Amazon S3), AWS Identity and Access Management (IAM), Amazon Glacier, Amazon Simple Notification Service (Amazon SNS), and Amazon Simple Queue Service (Amazon SQS). The SDK is also available as a Ruby Gem that can be installed as follows:


$ gem install aws-sdk -pre

We plan to introduce resource APIs for additional services and AWS SDKs for other languages in the future, so stay tuned and happy coding!

Jeff;

PS – To learn more about Resource APIs, visit the AWS Ruby Development Blog.

TAGS:
Jeff Barr

Jeff Barr

Jeff Barr is Chief Evangelist for AWS. He started this blog in 2004 and has been writing posts just about non-stop ever since.