Skip to main content

A simple library to use AWS resources. And speedup development for lambda projects.

Project description

ohmylamb

A simple library to use AWS resources. And speedup development for lambda projects.

To install

pip install ohmylamb  

To Configure

To configure define team name, application name and environment name in app.ini file.

echo "[app]" >> app.ini
echo "name = adl-common-pytools" >> app.ini
echo "team = adl-dse" >> app.ini
echo "env = dev" >> app.ini

To import into code add following

from ohmylamb import ohmylamb as oml

Configuration handling

Configuration management has been split into two areas.

  • Application configuration. This comes from aap.ini file. This configuration can be accessed using following code.
    >>> oml.app_configuration("team")
    'adl-dse'
    
  • Infrastructure resources configurations. This comes from aws secret manager. In secret manager resource configuration are stored as key value pair under a key. Key convention: {team}/{env}/{resourcename}. Now team and env come from application configuration. And resource is the name of resource. Example:
    >>> oml.app_resource_conf("snowflake")
    (None, {'url': '****************', 'username': '******', 'password': '*****', 'account': '****************', 'account_region': 'us-east-1', 'adm_warehouse_db_schema': '*****************', 'bd_warehouse_db_schema': '*************'}) 
    
    For this to work user running above code should have access to the secret manager key. The above can also be fetched by following:
    @oml.AppResourceConfValue("snowflake")
    def getSnoflakeCredential():
        pass
    print(getSnoflakeCredential)
    (None, {'url': '****************', 'username': '******', 'password': '********', 'account': '****************', 'account_region': 'us-east-1', 'adm_warehouse_db_schema': '***********', 'bd_warehouse_db_schema': '*************'})
    
    

AWS Secret Manager

>>> oml.aws_secret_manager_secrets_map("adl-dse/dev/adl-common-pytools")
(None, {'test1': 'value1', 'test2': 'value2', 'comment': 'This is a test configuration'})

AWS S3

Functions for S3

  • oml.aws_s3_download_file(bucket, key, local_file_path) : will download file to local file path
  • oml.aws_s3_upload_file(bucket, key, local_file_path) : Will upload local file to s3

SMS Services

SMS notification can be set to one number or multiple by annotating a message:

@oml.SMSNotifier(['+1949*******'])
def notifyRaman(msg):
    return msg

notifyRaman("This is a test message")

SMS notification can be set to predefined group managed through git here.

@oml.SMSGroupNotifier("data_engineering")
def notifyProductionIssue(msg):
    return msg

notifyProductionIssue("Test failed")

SMS notification can be sent to individual by using their email id. Contact info is predefined individuals.csv file managed through git here.

@oml.SMSIndividualNotifier("****@gmail.com")
def notifyRaman(msg):
    return msg

notifyRaman("This is a test message")

Lambda Function Development

For lambda development create a main.py file with following content.

import os
import ohmylamb.ohmylamb as oml

# Your code goes here
def handler():
    pass

# Keep this at the end of the file
def lambda_handler(event, context):
   handler(event,context)

All that is need to be done is to be done in handler function. Annotate the function for type of trigger. Example if its a cron jon annotate it with aws_lambda_cronJobHandler or if its s3 event job then annotate it with aws_lambda_s3EventHandler. Example:

import os
import ohmylamb.ohmylamb as oml

# Your code goes here
@oml.aws_lambda_s3EventHandler
def handler():
    print("I will shout when time comes")

# Keep this at the end of the file
def lambda_handler(event, context):
    handler(event,context)

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

ohmylamb-1.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

ohmylamb-1.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file ohmylamb-1.0.1.tar.gz.

File metadata

  • Download URL: ohmylamb-1.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for ohmylamb-1.0.1.tar.gz
Algorithm Hash digest
SHA256 19e732eb9b0068b0f24fb24fbf288a0ed29a504cc42c6dcae8e42b4ff5728371
MD5 0659303153f6482642119009d762a323
BLAKE2b-256 269e07a21befcfba1f1173f43b07b907a55c743310769049ae39065df7e5faf8

See more details on using hashes here.

File details

Details for the file ohmylamb-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ohmylamb-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for ohmylamb-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65c68a80881dd61366b6eb000da86f490f012a952355f7c81a15e4b4da25f9de
MD5 f2523ac99b92b80e3166f83c711a3629
BLAKE2b-256 6a755adfc524acf2d624ea6c53d4d8c0dc5bcef99a2b14479876e5885f4efba7

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