Reputation: 16769
I have an AWS app which starts up and terminates many EC2 instances from a few different AMI's.
I'm beginning to get this error, via the ruby api, Request limit exceeded. The limit is around 2,000 per hour for most accounts I believe. But I can't find any evidence of our usage that's anywhere near this high, after looking through all the logs I know to check.
Is there a way to get an accounting from Amazon of what EC2 API queries I'm making?
Are there any other tricks or good ways to nail down my excessive use, or what's causing the error?
Upvotes: 3
Views: 4702
Reputation: 6528
You can enable logging for the aws-sdk gem via AWS.config. Just pass in an instance of a ruby Logger.
require 'logger'
AWS.config(:logger => Logger.new($stdout))
You are likely running into a situation where it is running n+1 queries to fetch attributes from your EC2 resources. Here is an example:
ec2 = AWS::EC2.new
ec2.instances.each do |i|
puts i.status
end
1 request is performed to fetch the ids of each instances and then 1 request is performed per instance to get its status. You can improve this by running your code inside a memoize block:
AWS.memoize do
ec2.instances.each do |i|
puts i.status
end
end
You can also use AWS.start_memoizing (and AWS.stop_memoizing) to surround larger areas of code. I stronly suggest reading this blog article about how collections work in the aws-sdk: http://aws.typepad.com/aws/2012/01/how-collections-work-in-the-aws-sdk-for-ruby.html
Upvotes: 2