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
ssm is a helper method.
- #stack_resources(stack_name) ⇒ Object
- #status ⇒ Object
- #task_definition_arns(family, max_items = 10) ⇒ Object
-
#waf_client ⇒ Object
waf is a helper method.
Instance Method Details
#acm ⇒ Object
19 20 21 |
# File 'lib/ufo/aws_services.rb', line 19 def acm Aws::ACM::Client.new() end |
#applicationautoscaling ⇒ Object
24 25 26 |
# File 'lib/ufo/aws_services.rb', line 24 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
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ufo/aws_services.rb', line 90 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
29 30 31 |
# File 'lib/ufo/aws_services.rb', line 29 def cloudformation Aws::CloudFormation::Client.new() end |
#cloudwatchlogs ⇒ Object
34 35 36 |
# File 'lib/ufo/aws_services.rb', line 34 def cloudwatchlogs Aws::CloudWatchLogs::Client.new() end |
#ec2 ⇒ Object
39 40 41 |
# File 'lib/ufo/aws_services.rb', line 39 def ec2 Aws::EC2::Client.new() end |
#ecr ⇒ Object
44 45 46 |
# File 'lib/ufo/aws_services.rb', line 44 def ecr Aws::ECR::Client.new() end |
#ecs ⇒ Object
49 50 51 |
# File 'lib/ufo/aws_services.rb', line 49 def ecs Aws::ECS::Client.new() end |
#elb ⇒ Object
54 55 56 |
# File 'lib/ufo/aws_services.rb', line 54 def elb Aws::ElasticLoadBalancingV2::Client.new() end |
#find_stack(stack_name) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ufo/aws_services.rb', line 102 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
ssm is a helper method
60 61 62 |
# File 'lib/ufo/aws_services.rb', line 60 def ssm_client Aws::SSM::Client.new() end |
#stack_resources(stack_name) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/ufo/aws_services.rb', line 114 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
134 135 136 |
# File 'lib/ufo/aws_services.rb', line 134 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
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ufo/aws_services.rb', line 121 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 |
#waf_client ⇒ Object
waf is a helper method
66 67 68 |
# File 'lib/ufo/aws_services.rb', line 66 def waf_client Aws::WAFV2::Client.new() end |