File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/boto_dynamodb.cpython-310.pyc
Back
o ;jyt � @ s� d Z ddlZddlZddlZddlZddlZddlm mZ ej ej dejd� e�� Z G dd� de�Zdd� Z d#dd�Zd d� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd � Zd$d!d"�ZdS )%a� Manage DynamoDB Tables ====================== .. versionadded:: 2015.5.0 Create and destroy DynamoDB tables. Be aware that this interacts with Amazon's services, and so may incur charges. This module uses ``boto``, which can be installed via package, or pip. This module accepts explicit DynamoDB credentials but can also utilize IAM roles assigned to the instance through Instance Profiles. Dynamic credentials are then automatically obtained from AWS API and no further configuration is necessary. More information available `here <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html>`_. If IAM roles are not used you need to specify them either in a pillar file or in the minion's config file: .. code-block:: yaml keyid: GKTADJGHEIQSXMKKRBJ08H key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs region: us-east-1 It's also possible to specify ``key``, ``keyid`` and ``region`` via a profile, either passed in as a dict, or as a string to pull from pillars or minion config: .. code-block:: yaml myprofile: keyid: GKTADJGHEIQSXMKKRBJ08H key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs region: us-east-1 .. code-block:: yaml Ensure DynamoDB table does not exist: boto_dynamodb.absent: - table_name: new_table - keyid: GKTADJGHEIQSXMKKRBJ08H - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs - region: us-east-1 Ensure DynamoDB table exists: boto_dynamodb.present: - table_name: new_table - read_capacity_units: 1 - write_capacity_units: 2 - hash_key: primary_id - hash_key_data_type: N - range_key: start_timestamp - range_key_data_type: N - keyid: GKTADJGHEIQSXMKKRBJ08H - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs - region: us-east-1 - local_indexes: - index: - name: "primary_id_end_timestamp_index" - hash_key: primary_id - hash_key_data_type: N - range_key: end_timestamp - range_key_data_type: N - global_indexes: - index: - name: "name_end_timestamp_index" - hash_key: name - hash_key_data_type: S - range_key: end_timestamp - range_key_data_type: N - read_capacity_units: 3 - write_capacity_units: 4 It's possible to specify cloudwatch alarms that will be setup along with the DynamoDB table. Note the alarm name will be defined by the name attribute provided, plus the DynamoDB resource name. .. code-block:: yaml Ensure DynamoDB table exists: boto_dynamodb.present: - name: new_table - read_capacity_units: 1 - write_capacity_units: 2 - hash_key: primary_id - hash_key_data_type: N - range_key: start_timestamp - range_key_data_type: N - alarms: ConsumedWriteCapacityUnits: name: 'DynamoDB ConsumedWriteCapacityUnits **MANAGED BY SALT**' attributes: metric: ConsumedWriteCapacityUnits namespace: AWS/DynamoDB statistic: Sum comparison: '>=' # threshold_percent is used to calculate the actual threshold # based on the provisioned capacity for the table. threshold_percent: 0.75 period: 300 evaluation_periods: 2 unit: Count description: 'DynamoDB ConsumedWriteCapacityUnits' alarm_actions: [ 'arn:aws:sns:us-east-1:1234:my-alarm' ] insufficient_data_actions: [] ok_actions: [ 'arn:aws:sns:us-east-1:1234:my-alarm' ] - keyid: GKTADJGHEIQSXMKKRBJ08H - key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs - region: us-east-1 You can also use alarms from pillars, and override values from the pillar alarms by setting overrides on the resource. Note that 'boto_dynamodb_alarms' will be used as a default value for all resources, if defined and can be used to ensure alarms are always set for a resource. Setting the alarms in a pillar: .. code-block:: yaml boto_dynamodb_alarms: ConsumedWriteCapacityUnits: name: 'DynamoDB ConsumedWriteCapacityUnits **MANAGED BY SALT**' attributes: metric: ConsumedWriteCapacityUnits namespace: AWS/DynamoDB statistic: Sum comparison: '>=' # threshold_percent is used to calculate the actual threshold # based on the provisioned capacity for the table. threshold_percent: 0.75 period: 300 evaluation_periods: 2 unit: Count description: 'DynamoDB ConsumedWriteCapacityUnits' alarm_actions: [ 'arn:aws:sns:us-east-1:1234:my-alarm' ] insufficient_data_actions: [] ok_actions: [ 'arn:aws:sns:us-east-1:1234:my-alarm' ] Ensure DynamoDB table exists: boto_dynamodb.present: - name: new_table - read_capacity_units: 1 - write_capacity_units: 2 - hash_key: primary_id - hash_key_data_type: N - range_key: start_timestamp - range_key_data_type: N - alarms: ConsumedWriteCapacityUnits: attributes: threshold_percent: 0.90 period: 900 � Nz.%(asctime)s %(name)s %(levelname)s %(message)s)�level�format�streamc @ s e Zd ZdZdS )�GsiNotUpdatableErrorz7Raised when a global secondary index cannot be updated.N)�__name__� __module__�__qualname__�__doc__� r r �M/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/boto_dynamodb.pyr � s r c C s dt v rdS dS )z2 Only load if boto_dynamodb is available. �boto_dynamodb.existsZ boto_dynamodb)Fz(boto_dynamodb module could not be loaded)�__salt__r r r r �__virtual__� s r �boto_dynamodb_alarms�boto_dynamodb_backup_configsc "