boto3-assist 0.9.2__py3-none-any.whl → 0.9.4__py3-none-any.whl

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.
@@ -0,0 +1,4 @@
1
+ from aws_lambda_powertools.utilities.typing import LambdaContext
2
+
3
+
4
+ class MockLambdaContext(LambdaContext)
@@ -32,3 +32,15 @@ class InvalidRoutePath(Exception):
32
32
  "message": message,
33
33
  }
34
34
  super().__init__(self.message)
35
+
36
+
37
+ class FileNotFound(Exception):
38
+ """File Not Found Error"""
39
+
40
+ def __init__(self, message="File Not Found"):
41
+ """Invalid Route"""
42
+ self.message = {
43
+ "status_code": 404,
44
+ "message": message,
45
+ }
46
+ super().__init__(self.message)
@@ -18,7 +18,7 @@ from boto3_assist.s3.s3_connection import S3Connection
18
18
  from boto3_assist.utilities.datetime_utility import DatetimeUtility
19
19
  from boto3_assist.utilities.file_operations import FileOperations
20
20
  from boto3_assist.utilities.http_utility import HttpUtility
21
-
21
+ from boto3_assist.errors.custom_exceptions import FileNotFound
22
22
 
23
23
  logger = Logger(child=True)
24
24
 
@@ -193,6 +193,12 @@ class S3Object:
193
193
 
194
194
  return response
195
195
 
196
+ def put(self, *, bucket: str, key: str, data: bytes | str) -> str:
197
+ """
198
+ Uploads a file object to s3. Returns the full s3 path s3://<bucket>/<key>
199
+ """
200
+ return self.upload_file_obj(bucket=bucket, key=key, file_obj=data)
201
+
196
202
  def upload_file_obj(self, *, bucket: str, key: str, file_obj: bytes | str) -> str:
197
203
  """
198
204
  Uploads a file object to s3. Returns the full s3 path s3://<bucket>/<key>
@@ -414,6 +420,19 @@ class S3Object:
414
420
  The "Body" is a streaming body object. You can read it like a file.
415
421
  For example:
416
422
 
423
+ with response["Body"] as f:
424
+ data = f.read()
425
+ print(data)
426
+
427
+ """
428
+ return self.get_object(bucket_name=bucket_name, key=key)
429
+
430
+ def get_object(self, bucket_name: str, key: str) -> Dict[str, Any]:
431
+ """
432
+ Gets a file from s3 and returns the response.
433
+ The "Body" is a streaming body object. You can read it like a file.
434
+ For example:
435
+
417
436
  with response["Body"] as f:
418
437
  data = f.read()
419
438
  print(data)
@@ -443,15 +462,28 @@ class S3Object:
443
462
 
444
463
  except Exception as e: # pylint: disable=W0718
445
464
  error = str(e)
446
- logger.error({"metric_filter": "s3_download_error", "error": str(e)})
447
- raise RuntimeError(
448
- {
449
- "metric_filter": "s3_download_error",
450
- "error": str(e),
451
- "bucket": bucket_name,
452
- "key": key,
453
- }
454
- ) from e
465
+ error_info = {
466
+ "metric_filter": "s3_download_error",
467
+ "error": str(e),
468
+ "bucket": bucket_name,
469
+ "key": key,
470
+ }
471
+
472
+ logger.error(error_info)
473
+ # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3/client/get_object.html
474
+ error = str(e)
475
+ if "An error occurred (AccessDenied)" in error:
476
+ if (
477
+ "is not authorized to perform: s3:ListBucket on resource" in error
478
+ and "because no identity-based policy allows the s3:ListBucket action"
479
+ in error
480
+ ):
481
+ # the file is not found but you're getting a access error since you don't
482
+ # have s3:ListBucket. To make life easier, we're just going to return a 404 error
483
+ raise FileNotFound("File Not Found") from e
484
+
485
+ # last ditch
486
+ raise RuntimeError(error_info) from e
455
487
 
456
488
  finally:
457
489
  logger.debug(
boto3_assist/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '0.9.2'
1
+ __version__ = '0.9.4'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: boto3_assist
3
- Version: 0.9.2
3
+ Version: 0.9.4
4
4
  Summary: Additional boto3 wrappers to make your life a little easier
5
5
  Author-email: Eric Wilson <boto3-assist@geekcafe.com>
6
6
  License-File: LICENSE-EXPLAINED.txt
@@ -3,8 +3,9 @@ boto3_assist/boto3session.py,sha256=Q9sByNC0r_aMQfHnIEnxtTaiCMUqikm8UeSTxV7-Np0,
3
3
  boto3_assist/connection.py,sha256=-z_OZtZmSVjSSECpoqx1FnqW7B9A_LovfN_cJ_nhHgg,4361
4
4
  boto3_assist/connection_tracker.py,sha256=UgfR9RlvXf3A4ssMr3gDMpw89ka8mSRvJn4M34SzhbU,4378
5
5
  boto3_assist/http_status_codes.py,sha256=G0zRSWenwavYKETvDF9tNVUXQz3Ae2gXdBETYbjvJe8,3284
6
- boto3_assist/version.py,sha256=HSMl6bLm3r1Ias1jHIPpJeQ0IYNuuSdlT38MTb79ewM,22
6
+ boto3_assist/version.py,sha256=PrvpsFpxFfV-9CkerqH8w9aj7jp44ZzlQ22FXf5IOIk,22
7
7
  boto3_assist/aws_lambda/event_info.py,sha256=OkZ4WzuGaHEu_T8sB188KBgShAJhZpWASALKRGBOhMg,14648
8
+ boto3_assist/aws_lambda/mock_context.py,sha256=kLLwt46a2ZrGF8jEmBWDFrH9sFavZSrB4k7EZZK2hs8,105
8
9
  boto3_assist/cloudwatch/cloudwatch_connection.py,sha256=mnGWaLSQpHh5EeY7Ek_2o9JKHJxOELIYtQVMX1IaHn4,2480
9
10
  boto3_assist/cloudwatch/cloudwatch_connection_tracker.py,sha256=mzRtO1uHrcfJNh1XrGEiXdTqxwEP8d1RqJkraMNkgK0,410
10
11
  boto3_assist/cloudwatch/cloudwatch_log_connection.py,sha256=qQMZHjUJ6gA8wU9utjQhOURXNSPH2RjxSoAy83bvoCs,1737
@@ -33,13 +34,13 @@ boto3_assist/ec2/ec2_connection.py,sha256=IrtaidH6_SF5l3OeNehRsTlC-sX7EURVqcO-U6
33
34
  boto3_assist/environment_services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
35
  boto3_assist/environment_services/environment_loader.py,sha256=1uVLqSPQriUWazGXpxPJBLveGL8rLZaT5ZsciqqjVek,3979
35
36
  boto3_assist/environment_services/environment_variables.py,sha256=4ccBKdPt6O7hcRT3zBHd8vqu8yQU8udmoD5RLAT3iMs,6801
36
- boto3_assist/errors/custom_exceptions.py,sha256=zC2V2Y4PUtKj3uLPn8mB-JessksKWJWvKM9kp1dmvt8,760
37
+ boto3_assist/errors/custom_exceptions.py,sha256=QAMW49NbClELVnRd00u4NHfzVtRS3Tc1TrsIMUP9wLw,1041
37
38
  boto3_assist/models/serializable_model.py,sha256=ZMrRJRvJWLY8PBSKK_nPCgYKv1qUxDPEVdcADKbIHsI,266
38
39
  boto3_assist/s3/s3.py,sha256=ESTPXtyDi8mrwHaYNWjQLNGTuTUV4CxKDqw-O_KGzKs,2052
39
40
  boto3_assist/s3/s3_bucket.py,sha256=GfyBbuI5BWz_ybwU_nDqUZiC0wt24PNt49GKZmb05OY,2018
40
41
  boto3_assist/s3/s3_connection.py,sha256=0JgEDNoDFPQTo5hQe-lS8mWnFBJ2S8MDSl0LPG__lZo,2008
41
42
  boto3_assist/s3/s3_event_data.py,sha256=vwty34zDgTeSLNCLAWVxvhSQKT7hIpM7fZrWm5w6znM,4063
42
- boto3_assist/s3/s3_object.py,sha256=8diOon_TbH0BWpVNM84grDgXOmXq5C41N8wDa6E2B8c,21319
43
+ boto3_assist/s3/s3_object.py,sha256=2O9AYLQ6sfkkTE4_LzHBTyfz2CSKg6a9umBc71pj6vQ,22716
43
44
  boto3_assist/securityhub/securityhub.py,sha256=nGmHd_R3awDeB_QRzPfNAtQauLdVA1hlRlkaZA4oZjg,5409
44
45
  boto3_assist/securityhub/securityhub_connection.py,sha256=hWfcj9gjS2lNXUObyw4cShtveoqJPIp8kKFuz-fz1J4,1449
45
46
  boto3_assist/utilities/datetime_utility.py,sha256=dgAMB9VqakrYIPXlSoVQiLSsc_yhrJK4gMfJO9mX90w,11112
@@ -50,8 +51,8 @@ boto3_assist/utilities/logging_utility.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
50
51
  boto3_assist/utilities/numbers_utility.py,sha256=EjCnQhSbD5TRnuReKBD_GQyynp7Wit5M2bSfOfQGJBU,10051
51
52
  boto3_assist/utilities/serialization_utility.py,sha256=oS-tVGfP0fPq6FD5RE09DuNUB6tqR76QmthJTDERJRE,17203
52
53
  boto3_assist/utilities/string_utility.py,sha256=5BpDaqGZI8cSM-3YFQLU1fKcWcqG9r1_GPgDstCWFIs,10318
53
- boto3_assist-0.9.2.dist-info/METADATA,sha256=5oFr8lP2FCKNxukVMxX30Okf69fkLvbHTH3hkRpqBqE,1728
54
- boto3_assist-0.9.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
55
- boto3_assist-0.9.2.dist-info/licenses/LICENSE-EXPLAINED.txt,sha256=WFREvTpfTjPjDHpOLADxJpCKpIla3Ht87RUUGii4ODU,606
56
- boto3_assist-0.9.2.dist-info/licenses/LICENSE.txt,sha256=PXDhFWS5L5aOTkVhNvoitHKbAkgxqMI2uUPQyrnXGiI,1105
57
- boto3_assist-0.9.2.dist-info/RECORD,,
54
+ boto3_assist-0.9.4.dist-info/METADATA,sha256=30NkYeb-PZlihZ_LxQ1Ho3cZDoC2jbllHjho4Cud-gA,1728
55
+ boto3_assist-0.9.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
56
+ boto3_assist-0.9.4.dist-info/licenses/LICENSE-EXPLAINED.txt,sha256=WFREvTpfTjPjDHpOLADxJpCKpIla3Ht87RUUGii4ODU,606
57
+ boto3_assist-0.9.4.dist-info/licenses/LICENSE.txt,sha256=PXDhFWS5L5aOTkVhNvoitHKbAkgxqMI2uUPQyrnXGiI,1105
58
+ boto3_assist-0.9.4.dist-info/RECORD,,