boto3-assist 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/PKG-INFO +1 -1
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/pyproject.toml +1 -1
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/s3/s3.py +38 -2
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/utilities/file_operations.py +10 -0
- boto3_assist-0.2.4/src/boto3_assist/version.py +1 -0
- boto3_assist-0.2.4/tests/s3/__init__.py +0 -0
- boto3_assist-0.2.4/tests/s3/files/test.txt +1 -0
- boto3_assist-0.2.4/tests/s3/s3_file_upload_test.py +48 -0
- boto3_assist-0.2.2/src/boto3_assist/version.py +0 -1
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.env.docker +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.env.docker.001 +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.env.docker.nosql.workbench +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.env.unittest +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.gitignore +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.vscode/launch.json +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.vscode/settings.json +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/.vscode/tasks.json +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/LICENSE-EXPLAINED.txt +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/LICENSE.txt +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/README.md +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/aws_regions_with_status.csv +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/aws_regions_with_status.json +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/devops/build.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/devops/readme.md +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/cloudwatch/log_report.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/models/order_item_model.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/models/order_model.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/models/product_model.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/models/user_model.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/models/user_post_model.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/order_example/main.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/order_example/products.json +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/order_item_service.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/order_service.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/product_service.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/table_service.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/user_post_service.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/user_service.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/user_service_client_example.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/user_service_resource_example.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/user_post_example/main.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/ec2/regions_report.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/module-headers.txt +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/mypy.ini +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/requirements-dev.txt +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/requirements.txt +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/run-checks.sh +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/boto3session.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/cloudwatch/cloudwatch_connection.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/cloudwatch/cloudwatch_connection_tracker.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/cloudwatch/cloudwatch_log_connection.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/cloudwatch/cloudwatch_logs.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/cloudwatch/cloudwatch_query.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/connection.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/connection_tracker.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_connection.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_connection_tracker.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_helpers.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_importer.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_index.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_iservice.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_key.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_model_base.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_model_base_interfaces.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_reindexer.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_reserved_words.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_reserved_words.txt +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/readme.md +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/troubleshooting.md +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/ec2/ec2_connection.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/environment_services/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/environment_services/environment_loader.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/environment_services/environment_variables.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/errors/custom_exceptions.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/s3/s3_connection.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/utilities/datetime_utility.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/utilities/http_utility.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/utilities/logging_utility.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/utilities/serialization_utility.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/utilities/string_utility.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/__top/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/dynamodb_model_base_test.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/dynamodb_model_projections_test.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/dynamodb_model_serializtion_test.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/dynamodb_moto_sorting_test.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/dynamodb_reindex_test.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/models/cms/base.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/models/cms/content_block.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/models/cms/page.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/models/cms/template.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/models/simple_model.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/models/user_model.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/examples_test/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/examples_test/user_service_test.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/utilities/__init__.py +0 -0
- {boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/utilities/serialization_utility_test.py +0 -0
|
@@ -7,6 +7,7 @@ MIT License. See Project Root for the license information.
|
|
|
7
7
|
import os
|
|
8
8
|
import tempfile
|
|
9
9
|
import time
|
|
10
|
+
import io
|
|
10
11
|
from typing import Any, Dict, List, Optional
|
|
11
12
|
|
|
12
13
|
from aws_lambda_powertools import Logger
|
|
@@ -50,6 +51,19 @@ class S3(S3Connection):
|
|
|
50
51
|
aws_secret_access_key=aws_secret_access_key,
|
|
51
52
|
)
|
|
52
53
|
|
|
54
|
+
def create_bucket(self, bucket_name: str) -> None:
|
|
55
|
+
"""
|
|
56
|
+
Create an S3 bucket
|
|
57
|
+
:param bucket_name: Bucket to create
|
|
58
|
+
:return: True if bucket is created, else False
|
|
59
|
+
"""
|
|
60
|
+
try:
|
|
61
|
+
self.client.create_bucket(Bucket=bucket_name)
|
|
62
|
+
logger.info(f"Bucket {bucket_name} created")
|
|
63
|
+
except ClientError as e:
|
|
64
|
+
logger.exception(e)
|
|
65
|
+
raise e
|
|
66
|
+
|
|
53
67
|
def generate_presigned_url(
|
|
54
68
|
self,
|
|
55
69
|
bucket_name: str,
|
|
@@ -139,7 +153,7 @@ class S3(S3Connection):
|
|
|
139
153
|
|
|
140
154
|
return response
|
|
141
155
|
|
|
142
|
-
def upload_file_obj(self, bucket: str, key: str, file_obj: bytes) -> str:
|
|
156
|
+
def upload_file_obj(self, bucket: str, key: str, file_obj: bytes | str) -> str:
|
|
143
157
|
"""
|
|
144
158
|
Uploads a file object to s3. Returns the full s3 path s3://<bucket>/<key>
|
|
145
159
|
"""
|
|
@@ -156,7 +170,13 @@ class S3(S3Connection):
|
|
|
156
170
|
}
|
|
157
171
|
)
|
|
158
172
|
try:
|
|
159
|
-
|
|
173
|
+
# convert if necessary
|
|
174
|
+
file_obj: bytes = (
|
|
175
|
+
file_obj.encode("utf-8") if isinstance(file_obj, str) else file_obj
|
|
176
|
+
)
|
|
177
|
+
self.client.upload_fileobj(
|
|
178
|
+
Fileobj=io.BytesIO(file_obj), Bucket=bucket, Key=key
|
|
179
|
+
)
|
|
160
180
|
|
|
161
181
|
except ClientError as ce:
|
|
162
182
|
error = {
|
|
@@ -503,3 +523,19 @@ class S3(S3Connection):
|
|
|
503
523
|
else:
|
|
504
524
|
# Not in AWS Lambda, use the system's default temp directory
|
|
505
525
|
return tempfile.gettempdir()
|
|
526
|
+
|
|
527
|
+
def encode(
|
|
528
|
+
self, text: str, encoding: str = "utf-8", errors: str = "strict"
|
|
529
|
+
) -> bytes:
|
|
530
|
+
"""
|
|
531
|
+
Encodes a string for s3
|
|
532
|
+
"""
|
|
533
|
+
return text.encode(encoding=encoding, errors=errors)
|
|
534
|
+
|
|
535
|
+
def decode(
|
|
536
|
+
self, file_obj: bytes, encoding: str = "utf-8", errors: str = "strict"
|
|
537
|
+
) -> str:
|
|
538
|
+
"""
|
|
539
|
+
Decodes bytes to a string
|
|
540
|
+
"""
|
|
541
|
+
return file_obj.decode(encoding=encoding, errors=errors)
|
|
@@ -58,6 +58,16 @@ class FileOperations:
|
|
|
58
58
|
dirname = os.path.dirname(path)
|
|
59
59
|
return dirname
|
|
60
60
|
|
|
61
|
+
@staticmethod
|
|
62
|
+
def read_file(path: str, encoding: str = "utf-8") -> str:
|
|
63
|
+
"""
|
|
64
|
+
Read a file
|
|
65
|
+
"""
|
|
66
|
+
logger.debug(f"reading file {path}")
|
|
67
|
+
with open(path, "r", encoding=encoding) as file:
|
|
68
|
+
data = file.read()
|
|
69
|
+
return data
|
|
70
|
+
|
|
61
71
|
@staticmethod
|
|
62
72
|
def write_to_file(path: str, data: str, append: bool = False) -> str:
|
|
63
73
|
"""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.2.4'
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test upload file
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import unittest
|
|
3
|
+
import moto
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from boto3_assist.s3.s3 import S3
|
|
6
|
+
from boto3_assist.environment_services.environment_loader import EnvironmentLoader
|
|
7
|
+
from boto3_assist.utilities.file_operations import FileOperations
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@moto.mock_aws
|
|
11
|
+
class S3FileUploadTest(unittest.TestCase):
|
|
12
|
+
"""Test S3 File Upload"""
|
|
13
|
+
|
|
14
|
+
def setUp(self):
|
|
15
|
+
"""Setup"""
|
|
16
|
+
ev: EnvironmentLoader = EnvironmentLoader()
|
|
17
|
+
# NOTE: you need to make sure the the env file below exists or you will get an error
|
|
18
|
+
ev.load_environment_file(file_name=".env.unittest")
|
|
19
|
+
|
|
20
|
+
def test_upload_file(self):
|
|
21
|
+
"""Test uploading a file"""
|
|
22
|
+
s3 = S3()
|
|
23
|
+
bucket_name: str = "test-bucket"
|
|
24
|
+
s3.create_bucket(bucket_name)
|
|
25
|
+
local_file_path: Path = Path(
|
|
26
|
+
os.path.join(os.path.dirname(__file__), "files", "test.txt")
|
|
27
|
+
)
|
|
28
|
+
if not os.path.exists(local_file_path):
|
|
29
|
+
raise FileNotFoundError(f"File not found: {local_file_path}")
|
|
30
|
+
|
|
31
|
+
s3.upload_file(
|
|
32
|
+
bucket=bucket_name, key="test.txt", local_file_path=local_file_path
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def test_upload_file_obj(self):
|
|
36
|
+
"""Test uploading a file"""
|
|
37
|
+
s3 = S3()
|
|
38
|
+
bucket_name: str = "test-bucket"
|
|
39
|
+
s3.create_bucket(bucket_name)
|
|
40
|
+
local_file_path: Path = Path(
|
|
41
|
+
os.path.join(os.path.dirname(__file__), "files", "test.txt")
|
|
42
|
+
)
|
|
43
|
+
if not os.path.exists(local_file_path):
|
|
44
|
+
raise FileNotFoundError(f"File not found: {local_file_path}")
|
|
45
|
+
|
|
46
|
+
data = FileOperations.read_file(local_file_path)
|
|
47
|
+
|
|
48
|
+
s3.upload_file_obj(bucket=bucket_name, key="test.txt", file_obj=data)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.2.2'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/examples/dynamodb/services/user_service_client_example.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/cloudwatch/cloudwatch_connection.py
RENAMED
|
File without changes
|
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/cloudwatch/cloudwatch_log_connection.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_connection_tracker.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_reserved_words.py
RENAMED
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/dynamodb/dynamodb_reserved_words.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/src/boto3_assist/utilities/serialization_utility.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{boto3_assist-0.2.2 → boto3_assist-0.2.4}/tests/dynamodb/dynamodb_model_serializtion_test.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|