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': 'agn_com_ci_us.us-east-1.snowflakecomputing.com', 'username': '******', 'password': '*****', 'account': 'agn_com_ci_us', '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': 'agn_com_ci_us.us-east-1.snowflakecomputing.com', 'username': '******', 'password': '********', 'account': 'agn_com_ci_us', '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(['+19493241296'])
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("rewati.raman@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.0.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

ohmylamb-1.0.0-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

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