Class: Webhookdb::Replicator::AwsPricingV1
- Includes:
- DBAdapter::ColumnTypes
- Defined in:
- lib/webhookdb/replicator/aws_pricing_v1.rb
Defined Under Namespace
Classes: ServiceBackfiller
Constant Summary collapse
- CURRENCIES =
["USD", "CNY"].freeze
Constants included from DBAdapter::ColumnTypes
DBAdapter::ColumnTypes::BIGINT, DBAdapter::ColumnTypes::BIGINT_ARRAY, DBAdapter::ColumnTypes::BOOLEAN, DBAdapter::ColumnTypes::COLUMN_TYPES, DBAdapter::ColumnTypes::DATE, DBAdapter::ColumnTypes::DECIMAL, DBAdapter::ColumnTypes::DOUBLE, DBAdapter::ColumnTypes::FLOAT, DBAdapter::ColumnTypes::INTEGER, DBAdapter::ColumnTypes::INTEGER_ARRAY, DBAdapter::ColumnTypes::OBJECT, DBAdapter::ColumnTypes::TEXT, DBAdapter::ColumnTypes::TEXT_ARRAY, DBAdapter::ColumnTypes::TIMESTAMP, DBAdapter::ColumnTypes::UUID
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #_backfillers ⇒ Object
- #_denormalized_columns ⇒ Object
- #_parallel_backfill ⇒ Object
- #_remote_key_column ⇒ Object
- #_resource_and_event(request) ⇒ Object
- #_resource_to_data ⇒ Object
- #_timestamp_column_name ⇒ Object
- #_update_where_expr ⇒ Object
- #_webhook_response(_request) ⇒ Object
- #calculate_webhook_state_machine ⇒ Webhookdb::Replicator::StateMachineStep
- #create_pricing_client ⇒ Object
- #with_pricing_client ⇒ Object
Methods inherited from Base
#_any_subscriptions_to_notify?, #_backfill_state_change_fields, #_clear_backfill_information, #_clear_webook_information, #_coalesce_excluded_on_update, #_enqueue_backfill_jobs, #_extra_index_specs, #_fetch_enrichment, #_find_dependency_candidate, #_notify_dependents, #_prepare_for_insert, #_publish_rowupsert, #_store_enrichment_body?, #_to_json, #_upsert_update_expr, #_upsert_webhook, #_verify_backfill_err_msg, #_webhook_state_change_fields, #admin_dataset, #backfill, #backfill_not_supported_message, #calculate_and_backfill_state_machine, #calculate_backfill_state_machine, #calculate_dependency_state_machine_step, #calculate_preferred_create_state_machine, chunked_row_update_bounds, #clear_backfill_information, #clear_webhook_information, #create_table, #create_table_modification, #data_column, #dbadapter_table, #denormalized_columns, #descriptor, #dispatch_request_to, #documentation_url, #enqueue_sync_targets, #enrichment_column, #ensure_all_columns, #ensure_all_columns_modification, #find_dependent, #find_dependent!, #indices, #initialize, #on_dependency_webhook_upsert, #preferred_create_state_machine_method, #preprocess_headers_for_logging, #primary_key_column, #process_state_change, #process_webhooks_synchronously?, #qualified_table_sequel_identifier, #readonly_dataset, #remote_key_column, #requires_sequence?, #resource_name_plural, #resource_name_singular, #schema_and_table_symbols, #storable_columns, #synchronous_processing_response_body, #timestamp_column, #upsert_has_deps?, #upsert_webhook, #upsert_webhook_body, #verify_backfill_credentials, #webhook_endpoint, #webhook_response
Constructor Details
This class inherits a constructor from Webhookdb::Replicator::Base
Class Method Details
.descriptor ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 13 def self.descriptor return Webhookdb::Replicator::Descriptor.new( name: "aws_pricing_v1", ctor: self, resource_name_singular: "AWS Price List", feature_roles: [], supports_backfill: true, description: "Fetch, parse, and process AWS price list information from the API into a " \ "relational, fully searchable table.", api_docs_url: "https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/" \ "price-list-query-api-find-services-products.html", ) end |
Instance Method Details
#_backfillers ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 144 def _backfillers pricing = self.create_pricing_client backfillers = [] effective_date = Time.now.iso8601 # backfillers << ServiceBackfiller.new(self, 'AmazonEC2', 'USD', effective_date) pricing.describe_services.each do |services_resp| services_resp.services.map do |srv| CURRENCIES.each do |currency_code| backfillers << ServiceBackfiller.new(self, srv.service_code, currency_code, effective_date) end end end return backfillers end |
#_denormalized_columns ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 27 def _denormalized_columns return [ # Product Webhookdb::Replicator::Column.new(:product_sku, TEXT, index: true), Webhookdb::Replicator::Column.new(:product_family, TEXT, index: true), Webhookdb::Replicator::Column.new(:product_attributes, OBJECT), Webhookdb::Replicator::Column.new(:product_group, TEXT, index: true), Webhookdb::Replicator::Column.new(:product_location, TEXT, index: true), Webhookdb::Replicator::Column.new(:product_region, TEXT, index: true), Webhookdb::Replicator::Column.new(:product_operation, TEXT, index: true), Webhookdb::Replicator::Column.new(:product_usagetype, TEXT, index: true), Webhookdb::Replicator::Column.new(:publication_date, TIMESTAMP, index: true), Webhookdb::Replicator::Column.new(:service_code, TEXT, index: true), Webhookdb::Replicator::Column.new(:version, TEXT, index: true), # Term (OnDemand, etc) Webhookdb::Replicator::Column.new(:term_type, TEXT), Webhookdb::Replicator::Column.new(:term_code, TEXT, index: true), Webhookdb::Replicator::Column.new(:offer_term_code, TEXT, index: true), Webhookdb::Replicator::Column.new(:effective_date, TIMESTAMP, index: true), # Term fields # Webhookdb::Replicator::Column.new(:rate_code, TEXT, index: true), Webhookdb::Replicator::Column.new(:applies_to, TEXT_ARRAY), Webhookdb::Replicator::Column.new(:begin_range, DECIMAL), Webhookdb::Replicator::Column.new(:description, TEXT), Webhookdb::Replicator::Column.new(:end_range, DECIMAL), Webhookdb::Replicator::Column.new(:unit, TEXT), Webhookdb::Replicator::Column.new(:term_attributes, OBJECT), Webhookdb::Replicator::Column.new(:price_per_unit_raw, OBJECT), Webhookdb::Replicator::Column.new(:price_per_unit_amount, DECIMAL), Webhookdb::Replicator::Column.new(:price_per_unit_currency, TEXT), ] end |
#_parallel_backfill ⇒ Object
142 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 142 def _parallel_backfill = 3 |
#_remote_key_column ⇒ Object
64 65 66 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 64 def _remote_key_column return Webhookdb::Replicator::Column.new(:rate_code, TEXT) end |
#_resource_and_event(request) ⇒ Object
72 73 74 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 72 def _resource_and_event(request) return request.body, nil end |
#_resource_to_data ⇒ Object
76 77 78 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 76 def _resource_to_data(*) return {} end |
#_timestamp_column_name ⇒ Object
68 69 70 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 68 def return :publication_date end |
#_update_where_expr ⇒ Object
80 81 82 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 80 def _update_where_expr return self.qualified_table_sequel_identifier[:publication_date] < Sequel[:excluded][:publication_date] end |
#_webhook_response(_request) ⇒ Object
84 85 86 87 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 84 def _webhook_response(_request) # There are no webhooks to respond to, these are backfill-only integrations return Webhookdb::WebhookResponse.ok end |
#calculate_webhook_state_machine ⇒ Webhookdb::Replicator::StateMachineStep
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 90 def calculate_webhook_state_machine step = Webhookdb::Replicator::StateMachineStep.new if self.service_integration.backfill_key.blank? step.output = %(In order to populate AWS prices, you'll need to allow WebhookDB to access the Pricing service in your account. We use 3rd party roles for this. (Note: self-hosted WebhookDB customers have other auth methods available). Here's how to do this from the AWS Console; you can do this via CDK or similar if you wish, too. - Log into AWS - Go to IAM - Go to 'Policies' on the nav bar - Create a policy like this (name it whatever you want, we'll use "WebhookDBPricing"): { "Version": "2012-10-17", "Statement": [ { "Sid": "WebhookDBPricing", "Effect": "Allow", "Action": [ "pricing:DescribeServices", "pricing:ListPriceLists", "pricing:GetAttributeValues", "pricing:GetPriceListFileUrl", "pricing:GetProducts" ], "Resource": "*" } ] } - Go to 'Roles' in the nav bar. - Choose 'AWS Account' as the entity type. - Choose 'Another AWS Account' and enter our Account ID: #{Webhookdb::AWS.external_account_id} - Check 'Require an external ID'. Choose whatever you wish. Here's one to try: WHDBPR-#{SecureRandom.hex(8)} - Go to the next page. Choose the policy created earlier (WebhookDBPricing). - Go to the next page. Give the role a name like 'WebhookDBPricing'. - Create the role. - Find the newly created role, and copy the ARN and External ID. ) return step.prompting("Role ARN").backfill_key(self.service_integration) elsif self.service_integration.backfill_secret.blank? return step.prompting("External ID", secret: true).backfill_secret(self.service_integration) end step.output = %(Your AWS pricing database will be filled shortly. It normally takes about 20 minutes to sync. #{self._query_help_output}) return step.completed end |
#create_pricing_client ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 171 def create_pricing_client role_arn = self.service_integration.backfill_key external_id = self.service_integration.backfill_secret assume_resp = Webhookdb::AWS.sts_client.assume_role( role_arn:, external_id:, role_session_name: "webhoookdb_aws_pricing_v1", ) return Aws::Pricing::Client.new( session_token: assume_resp.credentials.session_token, region: "us-east-1", # Lots of extra retries. It's almost always going to be because throttling. retry_base_delay: 5, retry_limit: 10, ) end |
#with_pricing_client ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/webhookdb/replicator/aws_pricing_v1.rb', line 159 def with_pricing_client raise LocalJumpError unless block_given? @pricing_client ||= self.create_pricing_client begin return yield(@pricing_client) rescue StandardError => e raise e unless e.to_s.include?("The security token included in the request is invalid") @pricing_client = self.create_pricing_client return yield(@pricing_client) end end |