Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example listing and filtering EC2 instances and using stubs #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jkanywhere
Copy link

The API reference for AWS Ruby SDK v2 is quite good and detailed, but I struggle to find more complex examples showing how to put it together to achieve common functionality.

This example code shows

  • Using Resource interface to list EC2 instances
  • Client side filtering using regular expression match on Name tag
  • Using :stub_responses to mock API return values within RSpec

I hope this will help provide an even easier introduction to AWS Ruby SDK v2.

jkanywhere and others added 5 commits April 30, 2015 15:13
Client side filter for EC2 instances based on a Name tag pattern.
Use of RSpec to test that code using stubs.

RSpec example currently fails, and I do not know why.

Failures:

  1) InstanceManager#instances returns only EC2 instances with matching Name tag
     Failure/Error: expect(subject.instances.map(&:id)).to eq ["i-1", "i-2"]

       expected: ["i-1", "i-2"]
            got: ["i-1", "i-2", "i-1", "i-2"]

       (compared using ==)
     # ./spec/instance_manager_spec.rb:54:in `block (3 levels) in <top (required)>'
A very simple RSpec example showing how stub_responses affects the
Aws::EC2::Client interface correctly, but results in doubled resonses from the
Aws::EC2::Resource interface.
The default stub returns non-empty strings for all possible string
values. This causes the next token that trigger paging to appear
like there is a next response.

I updated your stubbs to use nil next tokens to avoid this issue.
Please feel free to open this as an issue against aws/aws-sdk-ruby as
this is a poor default experience.
Fix broken tests by using `nil` next tokens to avoid erroneous paging.
@jkanywhere
Copy link
Author

cc @trevorrowe , and thanks for your help.

And describe the `list_instances.rb`/`InstanceManager` example in the README.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants