Skip to main content

Python3 classes and functions to execute common AWS operations.

Project description

Overview

Python3 classes and functions to execute common AWS operations.

Usage Example

"""Read secret string from AWS Secrets Manager."""
import aws_snippets

# secret_string = aws_snippets.readsecret('<secret-ID>')
secret_string = aws_snippets.readsecret('dkfjh765-sdfsf456-dfgd')
print(secret_string)

# Output: "I'm Batman!"

Get Full Functionality List from Docstring

Python Commands:

import aws_snippets
help(aws_snippets)

BASH Commands:

python -c 'import aws_snippets; help(aws_snippets)'

Output

Help on package aws_snippets:

NAME
   aws_snippets - Execute AWS operations.

PACKAGE CONTENTS


CLASSES
   builtins.object
      WriteLog

   class WriteLog(builtins.object)
   |  WriteLog(text)
   |
   |  Create JSON log object for CloudWatch.
   |
   |  # Import modules.
   |  import json
   |  from aws_snippets import WriteLog
   |
   |  # Initiate with empty dictionary.
   |  logger = WriteLog({})
   |
   |  # Collect entries to log.
   |  logger.log('<strkey>', '<value>')
   |  logger.log('<intkey>', <value>)
   |  logger.log('<boolkey>', <True/False>)
   |
   |  # Print out to CloudWatch as accumulated log.
   |  print(json.dumps(logger.text))
   |
   |  Methods defined here:
   |
   |  __init__(self, text)
   |      Initialize log content.
   |
   |  log(self, key, value)
   |      Update log content.
   |
   |  ----------------------------------------------------------------------
   |  Data descriptors defined here:
   |
   |  __dict__
   |      dictionary for instance variables (if defined)
   |
   |  __weakref__
   |      list of weak references to the object (if defined)

FUNCTIONS
   b64encode(cleartext: str, encoding: str = 'latin-1') -> str
      Encode strings using Base64.

      return str

   cfpurge(cf_dist: str, path: str, call_ref: str) -> dict
      Create Amazon CloudFront cache invalidation.

      return dict

   cleantmp(tmppath: str) -> None
      Clean Lambda /tmp path.

      return None

   dynamodbcreatetable(table: str, attrdictls: list, schemadictls: list, kmsid: str, tagdictls: list) -> None
      Create a table in DynamoDB.

      return None

   dynamodbdeleteallitems(table: str) -> None
      Delete all items from a DynamoDB table.

      return None

   dynamodbdeletetable(table: str) -> None
      Delete a table from DynamoDB.

      return None

   dynamodbgetitem(table: str, key: str, value: str) -> dict
      Get a single item from DynamoDB.

      return dict

   dynamodbputitem(table: str, itemdict: dict) -> None
      Put a single item into DynamoDB.

      return None

   dynamodbqueryitems(table: str, key: str, value: str) -> dict
      Get items based on keyword query from DynamoDB.

      return dict

   dynamodbscanallitems(table: str) -> dict
      Get all items from a table in DynamoDB.

      return dict

   dynamodbscanitems(table: str, key: str, value: str, patternexp: dict) -> dict
      Get all items from a DynamoDB table then filter by expression.

      return dict

   dynamodbupdateitem(table: str, keydict: dict, attributedict: dict, valuedict: dict, updateexpression: str) -> dict
      Update an item in a DynamoDB table.

      return dict

   httpget(url: str, headers: dict = {}, encoding: str = 'latin-1') -> dict
      Make HTTP requests using GET method.

      return dict

   httppost(url: str, headers: dict = {}, data: dict = {}, encoding: str = 'latin-1') -> str
      Make HTTP requests using POST method.

      return str

   kmsdecrypt(ciphertext: str, kmsid: str) -> str
      Decrypt strings using AWS KMS.

      return str

   kmsencrypt(cleartext: str, kmsid: str) -> str
      Encrypt strings using AWS KMS.

      return str

   randomize(length: int, punctuations: bool = False) -> str
      Create random strings.

      return str

   readsecret(id: str) -> str
      Read secret values in AWS Secrets Manager.

      return str

   sanitizerclean(input: str) -> str
      Sanitize input items.

      return str

   sanitizercleanlist(input: list, pattern: str) -> list
      Sanitize input list.

      return list

   sanitizercleanurl(url: str) -> str
      Sanitize input URLs.

      return str

   sanitizercleanurllist(input: list, pattern: str) -> list
      Sanitize input list.

      return list

   sanitizervalidate(input: str, pattern: str) -> bool
      Validate input items to RegEx patterns.

      return bool

   sanitizervalidatelist(input: list) -> bool
      Validate input list.

      return bool

   sha3512hash(clrtxt: str, condiments: str, encoding: str = 'latin-1') -> str
      Hash strings using SHA3_512 algorithm.

      return str

   snsnotify(topic: str, message: str, subject: str) -> None
      Send AWS SNS notifications.

      return None

   sqsmessage(queue_url: str, message: dict) -> dict
      Send messages into AWS SQS queues.

      return dict

DATA
   Union = typing.Union
      Union type; Union[X, Y] means either X or Y.

      To define a union, use e.g. Union[int, str].  Details:
      - The arguments must be types and there must be at least one.
      - None as an argument is a special case and is replaced by
         type(None).
      - Unions of unions are flattened, e.g.::

            Union[Union[int, str], float] == Union[int, str, float]

      - Unions of a single argument vanish, e.g.::

            Union[int] == int  # The constructor actually returns int

      - Redundant arguments are skipped, e.g.::

            Union[int, str, int] == Union[int, str]

      - When comparing unions, the argument order is ignored, e.g.::

            Union[int, str] == Union[str, int]

      - You cannot subclass or instantiate a union.
      - You can use Optional[X] as a shorthand for Union[X, None].

VERSION
   2024.1.0.0

FILE
   /Users/abdahmad/Desktop/aws_snippets/__init__.py

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

aws_snippets-2024.1.0.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

aws_snippets-2024.1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file aws_snippets-2024.1.0.0.tar.gz.

File metadata

  • Download URL: aws_snippets-2024.1.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/5.4.109+

File hashes

Hashes for aws_snippets-2024.1.0.0.tar.gz
Algorithm Hash digest
SHA256 38195c9d33c132e8c7c4fa85c78f6b8bf24d5cd939a8c9a6a32ac443a0dc8973
MD5 78f4c598cb28bb5c2df78d0f6b09abcc
BLAKE2b-256 a370b34ad99216a5295a50b021a6e8f579ffc8c1caac8f8d7d003d9a7c90dbea

See more details on using hashes here.

File details

Details for the file aws_snippets-2024.1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_snippets-2024.1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de047a679dc12aeb4622c4ceccc065483a1444dce5ba4f2dfcf2ad35b5ad3abe
MD5 013b4e40e6173f45c6f8ac3eb9d08133
BLAKE2b-256 7775076c4380339c11ec80307741a7033c760edba34c8b688449f9fb3b59d724

See more details on using hashes here.

Supported by

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