Sign inSign up

lecole/docker-helloworld

By lecole

•Updated about 4 years ago

Image
0

518

lecole/docker-helloworld repository overview

⁠Skydera Data Access Library

Access Dynamodb

Environment Variables

The Boto3 library will look for the authentication credentials in two locations.

First Boto3 will check these environment variables for credentials:

AWS_ACCESS_KEY_ID The access key for the service worker AWS account. AWS_SECRET_ACCESS_KEY The secret key for the service worker AWS account.

Second will be from local credential files located within the user home directory (in e.g. ~/.aws/credentials):

.. code-block:: ini

[default]
aws_access_key_id = SERVICE_WORKER_KEY
aws_secret_access_key = SERVICE_WORKER_SECRET

Quick Start


First, install the library from the internal PyPy repo:

.. code-block:: sh

$ pip install syntheseas-data-access

Parameters

* RegionName (string) ``[REQUIRED]``
    * us-west-2 (Current location of table)
* ProfileName (string)
    * Name of the profile you setup
* DriverType (string) ``[REQUIRED]``
    * dynamodb

.. code-block:: python

from syntheseas.data_access.dal import Dal

d_db = Dal(region_name='us-west-2', profile_name='prod').factory(driver_type='dynamodb')

Available methods


  • get_item
  • put_item
  • delete_item
  • query_items
  • batch_put_items

⁠Method definitions

-- get_item()

Required Syntax response = d_db.get_item(table_name='string', kc_hash='string', kc_hash_val='string', index_name='string', attribs=['string', 'string'...])

Parameters - TableName (string) (table_name) [REQUIRED] The name of the table containing the requested item.

- KeyCondition Hash (string) (kc_hash) ``[REQUIRED]``
    The name of the hash key you are requesting.

- KeyCondition HashValue (string) (kc_hash_val)  ``[REQUIRED]``
    The value of the hash key you are requesting.

- IndexName (string) (index_name)
    The index you would like to have the requested item searched from.

- Attributes (list) (attribs)
    List of Attributes you would like to return. This only returns the requested list. \
    If you need the hash or range keys, you will need to add them to the attribute list.

-- put_item()

Required Syntax response = d_db.put_item(table_name, item)

Parameters - TableName (string) (table_name) [REQUIRED] The name of the table to put the item.

- Item (dictionary) (item) ``[REQUIRED]``
    The item to be place in the table.

-- delete_item()

Required Syntax response = d_db.delete_item(table_name, item_key)

Parameters - TableName (string) (table_name) [REQUIRED] The name of the table to put the item.

- ItemKey (dictionary) (item_key) ``[REQUIRED]``
    The hash key and range key for the item to be deleted.

-- query_items()

Required Syntax response = d_db.query_items(table_name, kc_hash, kc_hash_val, kc_range=None, kc_range_val=None, kc_range_type=None, kc_range_start=None, kc_range_end=None, extend_data=None, index_name=None, attribs=None, exp_name=None, exp_val=None, exc_start_key=None, limit=None, scan_forward=None, count=None, total_items=None)

Parameters - TableName (string) (table_name) [REQUIRED] The name of the table containing the requested items.

- KeyCondition Hash (string) (kc_hash) ``[REQUIRED]``
    The name of the hash key you are requesting.

- KeyCondition HashValue (string) (kc_hash_val) ``[REQUIRED]``
    The value of the hash key you are requesting.

- KeyCondition Range (string) (kc_range)
    The name of the range key you are requesting.

- KeyCondition RangeValue (string | number) (kc_range_val)
    The value of the range key you are requesting.

- KeyCondition RangeType (string) (kc_range_type)
    The value of the range comparison.
    There are currently three different comparison types, Between, BeginsWith and Equals
    Acceptable strings: 'btw', 'bgw','eq'

- KeyCondition RangeStart (string | number) (kc_range_start)
    The value of the range comparison types. This value will depend on the
    type of the range key.

- KeyCondition RangeEnd (string | number) (kc_range_end)
    The value of the range comparison types. This value will depend on the
    type of the range key.

- ExtendData (bool) (extend_data)
    To return attributes in addition to index keys, when querying against an index. If an index is not provided, this variable is ignored.

- IndexName (string) (index_name)
    The index you would like to have the requested item searched from.

- Attributes (list) (attribs)
    List of Attributes you would like to return. This only returns the requested list. \
    If you need the hash or range keys, you will need to add them to the attribute list.

- ExpressionAttributeNames (dictionary) (exp_name)
    One of more substitution tokens for attribute names in an expression.

    * To access an attribute whose name conflicts with a DynamoDB reserved word.
    * To create a placeholder for repeating occurrences of an attribute name in an expression.
    * To prevent special characters in an attribute name from being misinterpreted in an expression.

- ExpressionAttributeValues (dictionary) (exp_val)
    One or more values that can be substituted in an expression.

- ExclusiveStartKey (dictionary) (exc_start_key)
    Content of the last process key. This data is used to page though query results.

- Limit (number) (limit)
    Total number of desired records to be returned.

- ScanForward (bool) (scan_forward)
    Specifies the order for index traversal: If true (default), the traversal is preformed in
    ascending order; if false, the traversal is preformed in descending order.

- Count (bool) (count)
    Returns the number of matching items, rather than the matching items themselves.

- TotalItems (query return values) (total_items)
    To call the query recursively to gather all the records.

-- batch_put_items()

Required Syntax response = d_db.batch_put_items(table_name, items)

Parameters - TableName (string) [REQUIRED] The name of the table to put the item.

- Items (list) ``[REQUIRED]``
    A list of items (dictionaries) to be place in the table. This function will batch your list \
    of items and paralyzed places them in the table on a single call.

⁠Examples

Connection to the factory, will required the region name you would like to use. The profile is optional, if you have a configuration profile setup on your local machine.

.. code-block:: python

from syntheseas.data_access.dal import Dal

d_db = Dal(region_name='us-west-2', profile_name='prod').factory(driver_type='dynamodb')

Get Item from an Index with specific attribute being returned

.. code-block:: python

data1 = d_db.get_item(table_name='comp-data-prod',
          kc_hash='run_identifier',
          kc_hash_val='ed884193-9882-49ab-a3cd-1a0776edfc66',
          index_name='run_identifier-index',
          attribs=['pure_plate_index', 's3_bucket', 'analytic_class', 'sequence'],
          )

Get Item from an Index with all attribute being returned

.. code-block:: python

data2 = d_db.get_item(table_name='comp-data-prod',
                      kc_hash='run_identifier',
                      kc_hash_val='ed884193-9882-49ab-a3cd-1a0776edfc66',
                      index_name='run_identifier-index',
                      )

Query index with a limit and return specific attribute being returned

.. code-block:: python

data3 = d_db.query_items(table_name='comp-data-prod',
                             kc_hash='workorder_id',
                             kc_hash_val='56a94a91a59d2746caa75179',
                             index_name='workorder_id-index',
                             extend_data=True,
                             attribs=['pure_plate_index', 's3_bucket', 'analytic_class', 'sequence'],
                             limit=30)

Query index for a specific Hash and Range key, with specific attributes (This is similar to get_item). Range type accepts three types, Equals, Between, and BeginsWith ('eq', 'btw', 'bgw')

.. code-block:: python

data4 = d_db.query_items(table_name='comp-data-prod',
                         kc_hash='pk',
                         kc_hash_val='comp-data:esi',
                         kc_range='run_time',
                         kc_range_val=1453693549000,
                         kc_range_type='eq',
                         extend_data=True,
                         index_name='pk-run_time-index',
                         attribs=['pure_plate_index', 's3_bucket', 'analytic_class', 'sequence']
                         )

Query index for a specific Hash and Range key, with all attributes

.. code-block:: python

data5 = d_db.get_item(table_name='comp-data-prod',
                      kc_hash='pk',
                      kc_hash_val='comp-data:esi',
                      kc_range='run_time',
                      kc_range_val=1453693549000,
                      index_name='pk-run_time-index',
                      )

Query table with a range, specifying extended data, this will return with all attributes.

.. code-block:: python

data6 = d_db.query_items(table_name='comp-data-prod',
                         kc_hash='pk',
                         kc_hash_val='comp-data:esi',
                         kc_range='run_time',
                         kc_range_type='btw',
                         kc_range_start=1453693549000,
                         kc_range_end=1453702878000,
                         index_name='pk-run_time-index',
                         extend_data=True,
                         limit=30
                         )

Delete Item from the table.

.. code-block:: python

data7 = d_db.delete_item(table_name='comp-data-prod',
                          item_key={
                              'pk': 'comp-data:esi',
                              'sk_gsi_1_pk': '011ffb3b-9f99-47fc-94c7-a11e1373a626:1456862542000'
                               },
                          )

Tag summary

Content type

Image

Digest

sha256:d1f8ef57b…

Size

96.3 MB

Last updated

about 4 years ago

docker pull lecole/docker-helloworld