Various utilities for working with AWS in Python 3. for the mir project
Project description
navalmartin_mir_aws_utils
Various utilities for working with AWS in Python. The official PyPi package can be found here.
Dependencies
- boto3
Installation
Installing the utilities via pip
pip install navalmartin-mir-aws-utils
For a specific version you can use
pip install navalmartin-mir-aws-utils==x.x.x
You can uninstall the project via
pip uninstall navalmartin_mir_aws_utils
How to use
Create an ImageBatch
from navalmartin_mir_aws_utils.image_s3_batch import ImagePathBatch
from navalmartin_mir_aws_utils.aws_credentials import AWSCredentials_S3
AWS_REGION = "YOUR_AWS_REGION"
AWS_S3_BUCKET_NAME = "YOUR_AWS_S3_BUCKET_NAME"
AWS_ACCESS_KEY = "YOUR_AWS_ACCESS_KEY"
AWS_SECRET_ACCESS_KEY = "YOUR_AWS_SECRET_ACCESS_KEY"
IMAGE_STR_TYPES = ('.jpg', '.png')
if __name__ == '__main__':
aws_s3_credentials = AWSCredentials_S3(aws_s3_bucket_name=AWS_S3_BUCKET_NAME,
aws_region=AWS_REGION,
aws_access_key=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
image_prefix = 'some/image/prefix/'
image_batch = ImagePathBatch(s3_credentials=aws_s3_credentials)
# read the images
image_batch.read(image_prefixes=(image_prefix,),
valid_image_extensions=IMAGE_STR_TYPES,
delimiter='/')
for image_file in image_batch:
print(image_file)
Send a message to an SQS queue
from navalmartin_mir_aws_utils.aws_credentials import AWSCredentials_SQS
from navalmartin_mir_aws_utils.sqs_queue_config import SQSMessageConfig
from navalmartin_mir_aws_utils.sqs_utils import send_sqs_message
AWS_REGION = "YOUR_AWS_REGION"
AWS_S3_BUCKET_NAME = "YOUR_AWS_S3_BUCKET_NAME"
AWS_ACCESS_KEY = "YOUR_AWS_ACCESS_KEY"
AWS_SECRET_ACCESS_KEY = "YOUR_AWS_SECRET_ACCESS_KEY"
AWS_SQS_URL = "YOUR_AWS_SQS_URL"
AWS_SQS_NAME = "YOUR_AWS_SQS_NAME"
AWS_SQS_GROUP_ID = "YOUR_AWS_SQS_GROUP_ID"
if __name__ == '__main__':
aws_sqs_credentials = AWSCredentials_SQS(aws_sqs_queue_name=AWS_SQS_NAME,
aws_queue_url=AWS_SQS_URL,
aws_region=AWS_REGION,
aws_access_key=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
message = "task_id:123"
sqs_msg = SQSMessageConfig(message_body=message,
message_group_id=AWS_SQS_GROUP_ID,
message_attributes=None,
message_deduplication_id="123")
response = send_sqs_message(sqs_credentials=aws_sqs_credentials,
sqs_msg=sqs_msg)
print(response)
read_response = read_one_sqs_message(aws_sqs_credentials)
print(read_response)
receipt_handle = read_response['Messages'][0]['ReceiptHandle']
# get the receipt handler to delete the message
# this signals that the message has been consumed
delete_response = delete_sqs_message(aws_sqs_credentials, receipt_handle=receipt_handle)
print(delete_response)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for navalmartin_mir_aws_utils-0.0.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a5a3db366e2c7a911e2e0fc0a39a1fc4233c03cde4a1f1755f453a4c054793e |
|
MD5 | 94d4ae3b2d4fcad419c23082bcad6ab1 |
|
BLAKE2b-256 | def2244dec2c48d5578424e8f0fb82c2f85844a0f0dbbfa4cfe21c326ba1a274 |
Close
Hashes for navalmartin_mir_aws_utils-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aafc9e915cb3dcc521b1b7e74bca6385d5fcaa670f3232bb44a85a772215b55d |
|
MD5 | 1376f646daf6aef596ee166af9f265ec |
|
BLAKE2b-256 | d6dad5caecfb75665e7f486f6e41a06b1cdf9c4cea490ad35446c17dfa400cb9 |