Aws-sdk-ruby: Seahorse::Client::NetworkingError: execution expired when calling Aws::EC2::Instance#start

Created on 19 Aug 2015  路  3Comments  路  Source: aws/aws-sdk-ruby

I'm using v2.1.11 and I'm trying to create and/or interact with EC2 instances thusly:

credentials = Aws::Credentials.new('aws_access_key_id', 'aws_secret_access_key')
client      = Aws::EC2::Client.new(region: 'us-west-2a', credentials: credentials)
ec2         = Aws::EC2::Instance.new({ id: 'SampleID', client: client, instance_type: 'sample.type', image_id: 'sample-id' })

When I call ec2.start (or any other method that might reach out to AWS itself), I get the following error:

Seahorse::Client::NetworkingError: execution expired
from /home/christopher/.rbenv/versions/2.1.5/lib/ruby/2.1.0/net/http.rb:879:in `initialize'

After some searching, I thought this might be related to SSL issues (though the error doesn't state anything about that), so for kicks I tried the following options, each in isolation:

  • Aws.use_bundled_cert!
  • Aws.config[:ssl_verify_peer] = false

In the same console and in the same codebase, I'm able to create Kinesis, S3, and AutoScale services without any errors using a similar pattern.

Thanks for your time!

guidance

Most helpful comment

+1 I just had this problem with AWS S3 upload in ruby, doing this:

s3 = Aws::S3::Resource.new
bucket = s3.bucket(ENV['S3_BUCKET'])
s3object = bucket.object('hello.png')
s3object.upload_file('/some/file')

I had AWS_REGION=us-east-1a in my .env file. Changed it to AWS_REGION=us-east-1 and it's fixed.

It would be nice if the error could be more informative.

All 3 comments

In your configuration, you gave the name of an availability zone where a region is expected. You should be able to simply replace "us-west-2a" with "us-west-2" and your code should work. The reason this gave you a networking error is because it was attempting to connect to ec2.us-west-2a.amazonaws.com which is not a valid domain.

Another note, it looks like you are trying to create an instance. Constructing an instance of the Aws::EC2::Instance class will only create a local reference to an instance by ID so that you can operate against it. For example, if I know the id of an instance I own, I can do the following to get status or to terminate it:

instance = Aws::EC2::Instance.new('i-12345678')
instance.state.name #=> "running"
instance.terminate

If you want to run a new instance you should use Aws::EC2::Resource#create_instances (http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Resource.html#create_instances-instance_method) or Aws::EC2::Client#run_isntances (http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#run_instances-instance_method):

ec2 = Aws::EC2::Resource.new(region: '...', access_key_id: '...', secret_access_key: '...')
instances = ec2.create_instances(instance_type: 'sample.type', image_id: 'sample-id', min_count: 2, max_count: 2)

Hope this helps!

I think you nailed it, thanks!

+1 I just had this problem with AWS S3 upload in ruby, doing this:

s3 = Aws::S3::Resource.new
bucket = s3.bucket(ENV['S3_BUCKET'])
s3object = bucket.object('hello.png')
s3object.upload_file('/some/file')

I had AWS_REGION=us-east-1a in my .env file. Changed it to AWS_REGION=us-east-1 and it's fixed.

It would be nice if the error could be more informative.

Was this page helpful?
0 / 5 - 0 ratings