Sha256: 4fdb761e7a543b751fea49000c52627a7b1aa63a925ab8d21710f2cf04e4f38e

Contents?: true

Size: 1.34 KB

Versions: 12

Compression:

Stored size: 1.34 KB

Contents

module Meroku
  module Aws
    # Logic related to the ec2 instances we use as servers
    module Ec2
      def tag
        {
          resource_type: 'instance',
          tags: [
            {
              key: 'Name',
              value: 'node'
            }
          ]
        }
      end

      def make_instance
        ec2_client.run_instances(
          image_id: 'ami-841f46ff',
          min_count: 1,
          max_count: 1,
          key_name: 'meroku.id_rsa',
          instance_type: 't2.micro',
          tag_specifications: [tag]
        ).instances.first
      end

      def ec2_client
        ::Aws::EC2::Client.new(
          region: 'us-east-1',
          credentials: ::Aws::Credentials.new(
            ENV['AWS_ACCESS_KEY'],
            ENV['AWS_SECRET']
          )
        )
      end

      def self.ec2_client
        ::Aws::EC2::Client.new(
          region: 'us-east-1',
          credentials: ::Aws::Credentials.new(
            ENV['AWS_ACCESS_KEY'],
            ENV['AWS_SECRET']
          )
        )
      end

      def self.associate_address(eipalloc, id)
        retries ||= 0
        ec2_client.associate_address(allocation_id: eipalloc, instance_id: id)
      rescue ::Aws::EC2::Errors::InvalidInstanceID
        sleep 1
        puts 'retrying associate_address()'
        retry if (retries += 1) < 15
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
meroku-2.0.22 lib/meroku/aws/ec2.rb
meroku-2.0.21 lib/meroku/aws/ec2.rb
meroku-2.0.20 lib/meroku/aws/ec2.rb
meroku-2.0.19 lib/meroku/aws/ec2.rb
meroku-2.0.18 lib/meroku/aws/ec2.rb
meroku-2.0.17 lib/meroku/aws/ec2.rb
meroku-2.0.16 lib/meroku/aws/ec2.rb
meroku-2.0.14 lib/meroku/aws/ec2.rb
meroku-2.0.13 lib/meroku/aws/ec2.rb
meroku-2.0.11 lib/meroku/aws/ec2.rb
meroku-2.0.10 lib/meroku/aws/ec2.rb
meroku-2.0.9 lib/meroku/aws/ec2.rb