aws-python-utils
Simplify use of AWS resources in your code with aws-python-utils
Install
pip install aws-python-util
SecretManager Util
- Easy secret retrieval
get_secret()
Use ENVIRONMENT variable "AWS_SECRET_MANAGER_SECRET" or pass in secret_key name.
Example Usage
Via ENVIRONMENT variable
from aws_python_utils import secretmanager
import os
os.environ["AWS_SECRET_MANAGER_SECRET"] = "mysecret"
secretmanager = secretmanager.AwsSecretManager()
mysecret = secretmanager.get_secret()
Or pass in secret_key name ..
from aws_python_utils import secretmanager
import os
secretmanager = secretmanager.AwsSecretManager()
mysecret = secretmanager.get_secret(secret_key="mysecret")
S3 Util
- Streams an s3 object directly into a pandas DataFrame to avoid writing to disk and then loading from disk
- Uploads a DataFrame directly to s3
Example Usage
from aws_python_utils import s3
from io import BytesIO
import pandas as pd
import numpy as np
bucket,key = s3.AwsS3.get_bucket_and_key_from_s3_path("s3://my-bucket/mypath/to/object")
print("bucket = " + bucket) # my-bucket
print("key = " + key) # mypath/to/object
# download a tab separated file schema: id val1 val2
df = s3.AwsS3.download_s3_file(s3_path, header=0, sep='\t', index='id')
df2 = pd.DataFrame(np.random.randint(low=0, high=10, size=(5, 5)), columns=['a', 'b', 'c', 'd', 'e'])
io_buffer = BytesIO()
df2.to_csv(io_buffer, columns=['a', 'c', 'e'], sep='\t', index=False)
s3.AwsS3.upload_to_s3("s3://your-bucket/path/to/object.tsv", io_buffer)
EC2 Util
- Ami cleaner to mop up old ami's
Example Usage
from aws_python_utils.ec2 import AwsEC2
from datetime import datetime
ec2 = AwsEC2()
# keep latest 5 ami'
ec2.clean_images("my-service-ami-dev-*", num_to_keep=5, cutoff_date=datetime(2018, 8, 1), images_to_keep=['ami-keepmeid'])
Release files for aws-python-utils 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aws_python_utils-0.0.7.tar.gz | 6.0 kB | Details |
Release files / aws_python_utils-0.0.7.tar.gz
| Download URL | aws_python_utils-0.0.7.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3a8e8a85a8b79354c90c3e86df2d2592f2f101130546c76910b589a4620d972
|
|
BLAKE2b-256 checksum How to use checksums |
67052e5f3b21bf275d58c753b73c11e1d35822bbf944728624b978ee9e8689e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3
|