Metadata-Version: 2.1
Name: aws_hexagonal_adapters
Version: 1.2.4
Summary: Adapters following hexagonal architecture to connect various AWS services.
Project-URL: Home, https://github.com/airmonitor/aws-hexagonal-adapters
Project-URL: Bug_Tracker, https://github.com/airmonitor/aws-hexagonal-adapters/issues
Author-email: Tomasz Szuster <tomasz.szuster@gmail.com>
License: MIT License
        
        Copyright (c) 2023 Tomasz Szuster
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.11
Requires-Dist: aws-lambda-powertools>=2.30
Requires-Dist: boto3>=1.33.1
Requires-Dist: botocore>=1.33.1
Requires-Dist: mypy-boto3-dynamodb>=1.34
Requires-Dist: mypy-boto3-events>=1.34
Requires-Dist: mypy-boto3-s3>=1.34
Requires-Dist: mypy-boto3-ses>=1.34
Requires-Dist: mypy-boto3-sqs>=1.34
Requires-Dist: mypy-boto3-ssm>=1.34
Description-Content-Type: text/markdown

[![auto-merge](https://github.com/airmonitor/aws-hexagonal-adapters/actions/workflows/auto_merge.yml/badge.svg)](https://github.com/airmonitor/aws-hexagonal-adapters/actions/workflows/auto_merge.yml)
[![tests](https://github.com/airmonitor/aws-hexagonal-adapters/actions/workflows/tests.yml/badge.svg)](https://github.com/airmonitor/aws-hexagonal-adapters/actions/workflows/tests.yml)

# aws-hexagonal-adapters
Adapters following hexagonal architecture to connect various AWS services


# Example usage

## S3
### Download object
```python
from os import environ

from aws_hexagonal_adapters.s3_service import S3Service

S3_SERVICE = S3Service(region_name=environ["CURRENT_REGION"])

# Download file
S3_SERVICE.download(
    bucket="bucket_name", local_path=f"/tmp/object", remote_path="object"
)
```

### Upload object
```python
from os import environ

from aws_hexagonal_adapters.s3_service import S3Service

S3_SERVICE = S3Service(region_name=environ["CURRENT_REGION"])

# Download file
S3_SERVICE.upload(
    bucket="bucket_name",
    local_path=f"/tmp/object_name",
    remote_path="object_name",
    extra_args={"StorageClass": "STANDARD_IA"},
)
```

### List objects
```python
from os import environ

from aws_hexagonal_adapters.s3_service import S3Service

S3_SERVICE = S3Service(region_name=environ["CURRENT_REGION"])

# Download file
S3_SERVICE.list_files(bucket="bucket_name", prefix="folder_name")
```

### Delete object
```python
from os import environ

from aws_hexagonal_adapters.s3_service import S3Service

S3_SERVICE = S3Service(region_name=environ["CURRENT_REGION"])

# Download file
S3_SERVICE.delete_object(bucket="bucket_name", key="object_name")
```

### Delete objects
```python
from os import environ

from aws_hexagonal_adapters.s3_service import S3Service

S3_SERVICE = S3Service(region_name=environ["CURRENT_REGION"])
objects = ["folder/object1.txt", "folder/object2.txt", "folder/object3.txt"]
# Download file
S3_SERVICE.delete_objects(bucket="bucket_name", keys=objects)
```

## DynamoDB
### Get Item
```python
from os import environ

from aws_hexagonal_adapters.dynamo_db_service import DynamoDBService

DYNAMODB_SERVICE = DynamoDBService(region_name=environ["REGION_NAME"])

item = DYNAMODB_SERVICE.get_item(
    table_name=environ["DYNAMODB_TABLE_NAME"],
    key={"pk": f'{environ["DYNAMODB_TABLE_ITEM_NAME"]}', "sk": "1"},
)
```
### Get Items
```python
from os import environ

from boto3.dynamodb.conditions import Key

from aws_hexagonal_adapters.dynamo_db_service import DynamoDBService

DYNAMODB_SERVICE = DynamoDBService(region_name=environ["REGION_NAME"])

item = DYNAMODB_SERVICE.get_items(
    table_name=environ["DYNAMODB_TABLE_NAME"],
    filter_expression=Key("sk").eq("2"),
)
```

### Scan
```python
from os import environ

from aws_hexagonal_adapters.dynamo_db_service import DynamoDBService

DYNAMODB_SERVICE = DynamoDBService(region_name=environ["REGION_NAME"])

item = DYNAMODB_SERVICE.scan_items(
    table_name=environ["DYNAMODB_TABLE_NAME"],
    index_name=environ["DYNAMODB_INDEX_NAME"],
)
```

## SQS
```python
from os import environ

from aws_hexagonal_adapters.sqs_service import SQSService

SQS_SERVICE = SQSService(region_name=environ["REGION_NAME"])

messages = SQS_SERVICE.receive_messages(queue_url=environ["SQS_QUEUE_NAME"])
```
