Class: MovableInk::AWS
- Inherits:
-
Object
- Object
- MovableInk::AWS
- Includes:
- ApiGateway, Athena, Autoscaling, EC2, EKS, ElastiCache, Metadata, Route53, S3, SNS, SSM
- Defined in:
- lib/movable_ink/aws.rb,
lib/movable_ink/aws/s3.rb,
lib/movable_ink/aws/ec2.rb,
lib/movable_ink/aws/eks.rb,
lib/movable_ink/aws/sns.rb,
lib/movable_ink/aws/ssm.rb,
lib/movable_ink/version.rb,
lib/movable_ink/aws/athena.rb,
lib/movable_ink/aws/errors.rb,
lib/movable_ink/aws/route53.rb,
lib/movable_ink/aws/metadata.rb,
lib/movable_ink/aws/api_gateway.rb,
lib/movable_ink/aws/autoscaling.rb,
lib/movable_ink/aws/elasticache.rb
Defined Under Namespace
Modules: ApiGateway, Athena, Autoscaling, EC2, EKS, ElastiCache, Errors, Metadata, Route53, S3, SNS, SSM
Constant Summary collapse
- VERSION =
'2.5.0'
Class Method Summary collapse
Instance Method Summary collapse
- #datacenter(region: my_region) ⇒ Object
-
#initialize(ipv4: nil, environment: nil, global_service: nil, instance_id: nil, availability_zone: nil) ⇒ AWS
constructor
A new instance of AWS.
- #my_region ⇒ Object
- #regions ⇒ Object
- #run_with_backoff(quiet: false, tries: 9) ⇒ Object
Methods included from EKS
Methods included from ApiGateway
Methods included from ElastiCache
#all_elasticache_replicas, #elasticache, #elasticache_primary, #elasticache_replica_in_my_az, #elasticache_replicas, #node_group_members, #node_group_members_in_my_az, #replication_group
Methods included from S3
Methods included from Athena
Methods included from SSM
#extract_parameters, #get_role_secrets, #get_secret, #run_with_backoff_and_client_fallback, #ssm_client, #ssm_client_failover
Methods included from Route53
#delete_resource_record_sets, #find_health_check_by_tag, #get_health_check_tags, #get_resource_record_sets_by_instance_name, #list_all_r53_resource_record_sets, #list_health_checks, #resource_record_sets, #route53
Methods included from Autoscaling
#autoscaling, #complete_lifecycle_action, #delete_role_tag, #keep_instance_alive, #mark_me_as_healthy, #mark_me_as_unhealthy, #record_lifecycle_action_heartbeat
Methods included from SNS
#notify_and_sleep, #notify_slack, #send_alert, #sns, #sns_pagerduty_topic_arn, #sns_slack_topic_arn, #sns_topics
Methods included from EC2
#all_instances, #assign_ip_address, #available_elastic_ips, #default_filter, #ec2, #elastic_ips, #instance_ip_addresses_by_role, #instance_ip_addresses_by_role_ordered, #instance_tags, #instances, #instances_with_consul_discovery, #instances_with_ec2_discovery, #load_all_instances, #load_mi_env, #map_ec2_consul_endpoint, #map_k8s_consul_endpoint, #me, #mi_env, #mi_env_cache_file_path, #private_ip_addresses, #redis_by_role, #statsd_host, #thopter, #thopter_instance, #unassigned_elastic_ips
Methods included from Metadata
#availability_zone, #http, #instance_id, #instance_type, #private_ipv4, #retrieve_metadata
Constructor Details
#initialize(ipv4: nil, environment: nil, global_service: nil, instance_id: nil, availability_zone: nil) ⇒ AWS
Returns a new instance of AWS.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/movable_ink/aws.rb', line 43 def initialize( ipv4: nil, environment: nil, global_service: nil, instance_id: nil, availability_zone: nil ) @mi_env = environment @ipv4 = ipv4 @instance_id = instance_id @availability_zone = availability_zone if global_service @availability_zone = 'us-east-1a' @instance_id = global_service @ipv4 = global_service end end |
Class Method Details
.regions ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/movable_ink/aws.rb', line 32 def regions { 'iad' => 'us-east-1', 'rld' => 'us-west-2', 'dub' => 'eu-west-1', 'ord' => 'us-east-2', 'fra' => 'eu-central-1' } end |
Instance Method Details
#datacenter(region: my_region) ⇒ Object
119 120 121 |
# File 'lib/movable_ink/aws.rb', line 119 def datacenter(region: my_region) regions.key(region) end |
#my_region ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/movable_ink/aws.rb', line 111 def my_region @my_region ||= if ENV['AWS_REGION'].nil? availability_zone.chop else ENV['AWS_REGION'] end end |
#regions ⇒ Object
107 108 109 |
# File 'lib/movable_ink/aws.rb', line 107 def regions self.class.regions end |
#run_with_backoff(quiet: false, tries: 9) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/movable_ink/aws.rb', line 62 def run_with_backoff(quiet: false, tries: 9) tries.times do |num| begin return yield rescue Aws::EC2::Errors::RequestLimitExceeded, Aws::EC2::Errors::ResourceAlreadyAssociated, Aws::EC2::Errors::Unavailable, Aws::EC2::Errors::InternalError, Aws::EC2::Errors::Http503Error, Aws::EKS::Errors::TooManyRequestsException, Aws::SNS::Errors::ThrottledException, Aws::SNS::Errors::Throttling, Aws::AutoScaling::Errors::Throttling, Aws::AutoScaling::Errors::ThrottledException, Aws::S3::Errors::SlowDown, Aws::Route53::Errors::Throttling, Aws::Route53::Errors::ThrottlingException, Aws::Route53::Errors::PriorRequestNotComplete, Aws::Route53::Errors::ServiceUnavailable, Aws::SSM::Errors::TooManyUpdates, Aws::SSM::Errors::ThrottlingException, Aws::SSM::Errors::InternalServerError, Aws::SSM::Errors::Http503Error, Aws::SSM::Errors::Http502Error, Aws::Athena::Errors::ThrottlingException, MovableInk::AWS::Errors::NoEnvironmentTagError sleep_time = (num+1)**2 + rand(10) if quiet (num >= tries - 1) ? notify_and_sleep(sleep_time, $!.class) : sleep(sleep_time) else notify_and_sleep(sleep_time, $!.class) end rescue Aws::Errors::ServiceError => e = "#{e.class}: #{e.}\nFrom #{$0}\n```\n#{e.backtrace.first(3).join("\n").gsub("`","'")}\n```" notify_slack(subject: 'Unhandled AWS API Error', message: ) puts raise MovableInk::AWS::Errors::ServiceError end end = "From: #{$0}\n```\n#{Thread.current.backtrace.first(3).join("\n").gsub("`","'")}\n```" notify_slack(subject: "AWS API failed after #{tries} attempts", message: ) puts raise MovableInk::AWS::Errors::FailedWithBackoff end |