Skip to main content

JustBard's Python based AWS Utilities

Project description

jblib-aws

Author: Justin Bard

This module was written to minimize the need to write the functions I use often.

INSTALL: python3 -m pip install jblibaws


The source code can be viewed here: https://github.com/ANamelessDrake/jblib-aws

More of my projects can be found here: http://justbard.com


talk_with_dynamo

A class that provides functionality for interacting with AWS DynamoDB tables. It allows you to perform various operations like querying, getting items, updating, inserting, deleting, and scanning the table.

class talk_with_dynamo(table, boto_session, region='us-east-1')

Example:
    table_name = "table-name"
    boto_session = boto3.session.Session()
    dynamo = talk_with_dynamo(table_name, boto_session) # Generate Database Object

    response = dynamo.query(partition_key=None, partition_key_attribute=None, sorting_key=False, 
			sorting_key_attribute=False, index=False, queryOperator=False, 
			betweenValue=False, keyConditionExpression=None, scanIndexForward=True, limit=None):
    print("Response: {}".format(response))

    getResponse = dynamo.getItem(partition_key, partition_key_attribute, sorting_key=False, sorting_key_attribute=False)

    batch_keys = {'tableName': {'Keys': [{'PartitionKey': 'PartitionKeyAttribute', 'SortingKey': 'SortingKey'}]}}
    batchResponse = dynamo.batchGetItem(batch_keys)

    insert_response = dynamo.insert(json_object)
    print("Insert Response: {}".format(insert_response))

    update_response = dynamo.update(partition_key_attribute, sorting_key_attribute, update_key, update_attribute)

    update_response = dynamo.updateV2(partition_key_attribute, update_key, update_attribute, sorting_key_attribute=None,
				conditionExpression=None, conditionCheck=None, sorting_key=None, max_tries=5, 
				additionalUpdateExpressions=None, expressionAttributeValues=None, 
				expressionAttributeNames=None, returnValues="UPDATED_NEW"):

    delete_response = dynamo.delete(partition_key_attribute, sorting_key_attribute=False, sorting_key=None, partition_key=None)

    scan_results = dynamo.scan(filter_expression=None, expression_attribute_values=None, max_pages=None)

    get_table_description = dynamo.getTableDescription()

    dynamo.clearTable() # Delete all entries in a table -- Use with caution

extractDynamoDBData

Extracts and cleans data from a payload retrieved from DynamoDB.

Parameters:

  • payload (dict): The payload containing data retrieved from DynamoDB as a dictionary.
  • record (str): The key to access a specific piece of data within the payload.
  • dataType (str, optional): The type of data to retrieve. Default is "S" (string).

Returns:

  • str or int or False: The extracted and cleaned data based on the specified record and dataType.
  • Returns False if the specified record is not found, or if there is an error during data extraction.
function extractDynamoDBData(payload, record, dataType="S")

Example:
    payload = {
        "name": "John Doe",
        "age": {
            "N": "30"
        },
        "address": "123 Main Street"
    }
    data = returnData(payload, "name")
    print(data)  # Output: "John Doe"

    data = returnData(payload, "age", dataType="N")
    print(data)  # Output: 30

    data = returnData(payload, "email")
    print(data)  # Output: False (record not found in payload)

talk_with_cognito

A class that provides functionality for interacting with AWS Cognito. It allows you to get a user's email address using their Cognito user ID.

    class talk_with_cognito(boto_client, cognito_user_pool_id)

        Example:

        Functions:
            get_user_email(cognito_user_id)
            - Gets User Email Address

get_secret

A function that retrieves a decoded secret from AWS Secrets Manager.

    function get_secret(secret_name, region='us-east-1')

        Example:

        Functions:
            get_secret(secret_name)
            - Returns decoded secret from AWS Secrets Manager

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jblibaws-1.2.7.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jblibaws-1.2.7-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file jblibaws-1.2.7.tar.gz.

File metadata

  • Download URL: jblibaws-1.2.7.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for jblibaws-1.2.7.tar.gz
Algorithm Hash digest
SHA256 1e4496fc528742530a55c2d08f966e005430caefb849da62650a7642942297ee
MD5 3596d46f620bf455200d907f28d313e8
BLAKE2b-256 e1a555a8c0f3741c12ee6e26bfb0dc75ae6639ce1f0694c11a354c342bb44f50

See more details on using hashes here.

File details

Details for the file jblibaws-1.2.7-py3-none-any.whl.

File metadata

  • Download URL: jblibaws-1.2.7-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for jblibaws-1.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 61d03cf034fc847c4138804dbfb825876a1f58e6433096ccb21ecd75d0187255
MD5 9ea1ec1bd1abdef1ba3a97589c5d909e
BLAKE2b-256 1faf319b6eead6e4e84f2723abe2aabea6cae47405e260859a10f4e014f2adf2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page