Module: Ufo::AwsServices
- Extended by:
- Memoist
- Included in:
- Ecr::Auth, Ecr::Cleaner, CLI::Base, CLI::Ps, Cfn::Base, Cfn::Stack::Builder::Resources::TaskDefinition::Reconstructor, Cfn::Stack::Status, Info, LogGroup, TaskDefinition::Helpers::Ssm::Fetcher, TaskDefinition::Helpers::StackOutput, TaskDefinition::Helpers::Vpc
- Defined in:
- lib/ufo/aws_services.rb
Instance Method Summary collapse
- #acm ⇒ Object
- #applicationautoscaling ⇒ Object
-
#aws_options ⇒ Object
Override the AWS retry settings with AWS clients.
- #cloudformation ⇒ Object
- #cloudwatchlogs ⇒ Object
- #ec2 ⇒ Object
- #ecr ⇒ Object
- #ecs ⇒ Object
- #elb ⇒ Object
- #find_stack(stack_name) ⇒ Object
- #ssm_client ⇒ Object
- #stack_resources(stack_name) ⇒ Object
- #status ⇒ Object
- #task_definition_arns(family, max_items = 10) ⇒ Object
Instance Method Details
#acm ⇒ Object
18 19 20 |
# File 'lib/ufo/aws_services.rb', line 18 def acm Aws::ACM::Client.new() end |
#applicationautoscaling ⇒ Object
23 24 25 |
# File 'lib/ufo/aws_services.rb', line 23 def applicationautoscaling Aws::ApplicationAutoScaling::Client.new() end |
#aws_options ⇒ Object
Override the AWS retry settings with AWS clients.
The aws-sdk-core has exponential backup with this formula:
2 ** c.retries * c.config.retry_base_delay
Source:
https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
So the max delay will be 2 ** 7 * 0.6 = 76.8s
Only scoping this to deploy because dont want to affect people’s application that use the aws sdk.
There is also additional rate backoff logic elsewhere, since this is only scoped to deploys.
Useful links:
https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/retry_errors.rb
https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ufo/aws_services.rb', line 82 def = { retry_limit: 7, # default: 3 retry_base_delay: 0.6, # default: 0.3 } .merge!( log_level: :debug, logger: Logger.new($stdout), ) if ENV['UFO_DEBUG_AWS_SDK'] end |
#cloudformation ⇒ Object
28 29 30 |
# File 'lib/ufo/aws_services.rb', line 28 def cloudformation Aws::CloudFormation::Client.new() end |
#cloudwatchlogs ⇒ Object
33 34 35 |
# File 'lib/ufo/aws_services.rb', line 33 def cloudwatchlogs Aws::CloudWatchLogs::Client.new() end |
#ec2 ⇒ Object
38 39 40 |
# File 'lib/ufo/aws_services.rb', line 38 def ec2 Aws::EC2::Client.new() end |
#ecr ⇒ Object
43 44 45 |
# File 'lib/ufo/aws_services.rb', line 43 def ecr Aws::ECR::Client.new() end |
#ecs ⇒ Object
48 49 50 |
# File 'lib/ufo/aws_services.rb', line 48 def ecs Aws::ECS::Client.new() end |
#elb ⇒ Object
53 54 55 |
# File 'lib/ufo/aws_services.rb', line 53 def elb Aws::ElasticLoadBalancingV2::Client.new() end |
#find_stack(stack_name) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ufo/aws_services.rb', line 94 def find_stack(stack_name) resp = cloudformation.describe_stacks(stack_name: stack_name) resp.stacks.first rescue Aws::CloudFormation::Errors::ValidationError => e # example: Stack with id demo-web does not exist if e. =~ /Stack with/ && e. =~ /does not exist/ nil else raise end end |
#ssm_client ⇒ Object
58 59 60 |
# File 'lib/ufo/aws_services.rb', line 58 def ssm_client Aws::SSM::Client.new end |
#stack_resources(stack_name) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/ufo/aws_services.rb', line 106 def stack_resources(stack_name) resp = cloudformation.describe_stack_resources(stack_name: stack_name) resp.stack_resources rescue Aws::CloudFormation::Errors::ValidationError => e e..include?("does not exist") ? return : raise end |
#status ⇒ Object
126 127 128 |
# File 'lib/ufo/aws_services.rb', line 126 def status CfnStatus.new(@stack_name) # NOTE: @stack_name must be set in the including Class end |
#task_definition_arns(family, max_items = 10) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ufo/aws_services.rb', line 113 def task_definition_arns(family, max_items=10) resp = ecs.list_task_definitions( family_prefix: family, sort: "DESC", ) arns = resp.task_definition_arns arns = arns.select do |arn| task_definition = arn.split('/').last.split(':').first task_definition == family end arns[0..max_items] end |