boto3-assist 0.12.0__tar.gz → 0.14.0__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.
Files changed (138) hide show
  1. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/PKG-INFO +1 -1
  2. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/pyproject.toml +1 -1
  3. boto3_assist-0.14.0/src/boto3_assist/boto3session.py +87 -0
  4. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/connection.py +7 -2
  5. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_connection.py +5 -1
  6. boto3_assist-0.14.0/src/boto3_assist/role_assumption_mixin.py +38 -0
  7. boto3_assist-0.14.0/src/boto3_assist/session_setup_mixin.py +29 -0
  8. boto3_assist-0.14.0/src/boto3_assist/version.py +1 -0
  9. boto3_assist-0.12.0/src/boto3_assist/boto3session.py +0 -190
  10. boto3_assist-0.12.0/src/boto3_assist/version.py +0 -1
  11. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.env.docker +0 -0
  12. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.env.docker.001 +0 -0
  13. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.env.docker.nosql.workbench +0 -0
  14. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.env.unittest +0 -0
  15. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.gitignore +0 -0
  16. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.vscode/launch.json +0 -0
  17. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.vscode/settings.json +0 -0
  18. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/.vscode/tasks.json +0 -0
  19. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/LICENSE-EXPLAINED.txt +0 -0
  20. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/LICENSE.txt +0 -0
  21. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/README.md +0 -0
  22. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/aws_regions_with_status.csv +0 -0
  23. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/aws_regions_with_status.json +0 -0
  24. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/devops/build.py +0 -0
  25. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/devops/readme.md +0 -0
  26. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/__init__.py +0 -0
  27. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/cloudwatch/log_report.py +0 -0
  28. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/models/order_item_model.py +0 -0
  29. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/models/order_model.py +0 -0
  30. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/models/product_model.py +0 -0
  31. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/models/user_model.py +0 -0
  32. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/models/user_post_model.py +0 -0
  33. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/order_example/main.py +0 -0
  34. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/order_example/products.json +0 -0
  35. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/order_item_service.py +0 -0
  36. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/order_service.py +0 -0
  37. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/product_service.py +0 -0
  38. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/table_service.py +0 -0
  39. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/user_post_service.py +0 -0
  40. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/user_service.py +0 -0
  41. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/user_service_client_example.py +0 -0
  42. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/services/user_service_resource_example.py +0 -0
  43. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/dynamodb/user_post_example/main.py +0 -0
  44. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/examples/ec2/regions_report.py +0 -0
  45. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/module-headers.txt +0 -0
  46. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/mypy.ini +0 -0
  47. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/requirements-dev.txt +0 -0
  48. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/requirements.txt +0 -0
  49. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/run-checks.sh +0 -0
  50. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/run_unit_tests.sh +0 -0
  51. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/__init__.py +0 -0
  52. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/aws_lambda/event_info.py +0 -0
  53. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/aws_lambda/mock_context.py +0 -0
  54. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cloudwatch/cloudwatch_connection.py +0 -0
  55. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cloudwatch/cloudwatch_connection_tracker.py +0 -0
  56. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cloudwatch/cloudwatch_log_connection.py +0 -0
  57. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cloudwatch/cloudwatch_logs.py +0 -0
  58. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cloudwatch/cloudwatch_query.py +0 -0
  59. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cognito/cognito_authorizer.py +0 -0
  60. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cognito/cognito_connection.py +0 -0
  61. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cognito/cognito_utility.py +0 -0
  62. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cognito/jwks_cache.py +0 -0
  63. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/cognito/user.py +0 -0
  64. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/connection_tracker.py +0 -0
  65. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb.py +0 -0
  66. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_helpers.py +0 -0
  67. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_importer.py +0 -0
  68. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_index.py +0 -0
  69. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_iservice.py +0 -0
  70. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_key.py +0 -0
  71. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_model_base.py +0 -0
  72. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_model_base_interfaces.py +0 -0
  73. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_reindexer.py +0 -0
  74. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_reserved_words.py +0 -0
  75. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/dynamodb_reserved_words.txt +0 -0
  76. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/readme.md +0 -0
  77. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/dynamodb/troubleshooting.md +0 -0
  78. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/ec2/ec2_connection.py +0 -0
  79. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/environment_services/__init__.py +0 -0
  80. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/environment_services/environment_loader.py +0 -0
  81. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/environment_services/environment_variables.py +0 -0
  82. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/errors/custom_exceptions.py +0 -0
  83. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/http_status_codes.py +0 -0
  84. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/models/serializable_model.py +0 -0
  85. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/s3/s3.py +0 -0
  86. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/s3/s3_bucket.py +0 -0
  87. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/s3/s3_connection.py +0 -0
  88. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/s3/s3_event_data.py +0 -0
  89. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/s3/s3_object.py +0 -0
  90. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/securityhub/securityhub.py +0 -0
  91. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/securityhub/securityhub_connection.py +0 -0
  92. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/ssm/connection.py +0 -0
  93. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/ssm/parameter_store/parameter_store.py +0 -0
  94. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/datetime_utility.py +0 -0
  95. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/dictionary_utility.py +0 -0
  96. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/file_operations.py +0 -0
  97. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/http_utility.py +0 -0
  98. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/logging_utility.py +0 -0
  99. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/numbers_utility.py +0 -0
  100. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/serialization_utility.py +0 -0
  101. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/src/boto3_assist/utilities/string_utility.py +0 -0
  102. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/__init__.py +0 -0
  103. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/integration/cross_account_connection_test.py +0 -0
  104. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/integration/tenant.py +0 -0
  105. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/integration/tenant_services.py +0 -0
  106. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/__init__.py +0 -0
  107. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dbmodels/cms/base.py +0 -0
  108. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dbmodels/cms/content_block.py +0 -0
  109. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dbmodels/cms/page.py +0 -0
  110. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dbmodels/cms/template.py +0 -0
  111. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dbmodels/simple_model.py +0 -0
  112. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dbmodels/user_model.py +0 -0
  113. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dbmodels/user_required_fields_model.py +0 -0
  114. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dynamodb_model_base_test.py +0 -0
  115. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dynamodb_model_projections_test.py +0 -0
  116. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dynamodb_model_serializtion_test.py +0 -0
  117. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dynamodb_moto_sorting_test.py +0 -0
  118. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/dynamodb_tests/dynamodb_reindex_test.py +0 -0
  119. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/examples_test/__init__.py +0 -0
  120. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/examples_test/user_service_test.py +0 -0
  121. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/lambda_tests/__init__.py +0 -0
  122. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/lambda_tests/event_info_test.py +0 -0
  123. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/models_tests/__init__.py +0 -0
  124. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/models_tests/models/person.py +0 -0
  125. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/models_tests/models/user.py +0 -0
  126. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/models_tests/serializable_model_person_test.py +0 -0
  127. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/models_tests/serializable_model_user_test.py +0 -0
  128. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/models_tests/serializable_model_wide_test.py +0 -0
  129. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/parameter_store/__init__.py +0 -0
  130. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/parameter_store/parameter_store_test.py +0 -0
  131. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/s3/__init__.py +0 -0
  132. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/s3/files/test.txt +0 -0
  133. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/s3/s3_event_data_test.py +0 -0
  134. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/s3/s3_file_delete_test.py +0 -0
  135. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/s3/s3_file_upload_test.py +0 -0
  136. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/utilities/__init__.py +0 -0
  137. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/utilities/serialization_utility_test.py +0 -0
  138. {boto3_assist-0.12.0 → boto3_assist-0.14.0}/tests/unit/utilities/string_utility_test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: boto3_assist
3
- Version: 0.12.0
3
+ Version: 0.14.0
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
@@ -15,7 +15,7 @@ addopts = "-m 'not integration'"
15
15
 
16
16
  [project]
17
17
  name = "boto3_assist"
18
- version = "0.12.0"
18
+ version = "0.14.0"
19
19
 
20
20
  authors = [
21
21
  { name="Eric Wilson", email="boto3-assist@geekcafe.com" }
@@ -0,0 +1,87 @@
1
+ """
2
+ Geek Cafe, LLC
3
+ Maintainers: Eric Wilson
4
+ MIT License. See Project Root for the license information.
5
+ """
6
+
7
+ from typing import Optional, List, Any
8
+ import boto3
9
+ from botocore.config import Config
10
+ from .session_setup_mixin import SessionSetupMixin
11
+ from .role_assumption_mixin import RoleAssumptionMixin
12
+
13
+
14
+ class Boto3SessionManager(SessionSetupMixin, RoleAssumptionMixin):
15
+ def __init__(
16
+ self,
17
+ service_name: str,
18
+ *,
19
+ aws_profile: Optional[str] = None,
20
+ aws_region: Optional[str] = None,
21
+ assume_role_arn: Optional[str] = None,
22
+ assume_role_chain: Optional[List[str]] = None,
23
+ assume_role_session_name: Optional[str] = None,
24
+ assume_role_duration_seconds: Optional[int] = 3600,
25
+ config: Optional[Config] = None,
26
+ aws_endpoint_url: Optional[str] = None,
27
+ aws_access_key_id: Optional[str] = None,
28
+ aws_secret_access_key: Optional[str] = None,
29
+ aws_session_token: Optional[str] = None,
30
+ ):
31
+ self.service_name = service_name
32
+ self.aws_profile = aws_profile
33
+ self.aws_region = aws_region
34
+ self.config = config
35
+ self.endpoint_url = aws_endpoint_url
36
+ self.assume_role_chain = assume_role_chain or (
37
+ [assume_role_arn] if assume_role_arn else []
38
+ )
39
+ self.assume_role_session_name = (
40
+ assume_role_session_name or f"AssumeRoleSessionFor{service_name}"
41
+ )
42
+ self.assume_role_duration_seconds = assume_role_duration_seconds
43
+ self.aws_access_key_id = aws_access_key_id
44
+ self.aws_secret_access_key = aws_secret_access_key
45
+ self.aws_session_token = aws_session_token
46
+
47
+ self.__session: Optional[boto3.Session] = None
48
+ self.__client: Any = None
49
+ self.__resource: Any = None
50
+
51
+ self.__initialize()
52
+
53
+ def __initialize(self):
54
+ base_session = self._create_base_session(
55
+ self.aws_profile,
56
+ self.aws_region,
57
+ self.aws_access_key_id,
58
+ self.aws_secret_access_key,
59
+ self.aws_session_token,
60
+ )
61
+
62
+ if self.assume_role_chain:
63
+ self.__session = self._assume_roles_in_chain(
64
+ base_session,
65
+ self.assume_role_chain,
66
+ self.assume_role_session_name,
67
+ self.assume_role_duration_seconds,
68
+ self.aws_region,
69
+ )
70
+ else:
71
+ self.__session = base_session
72
+
73
+ @property
74
+ def client(self) -> Any:
75
+ if not self.__client:
76
+ self.__client = self.__session.client(
77
+ self.service_name, config=self.config, endpoint_url=self.endpoint_url
78
+ )
79
+ return self.__client
80
+
81
+ @property
82
+ def resource(self) -> Any:
83
+ if not self.__resource:
84
+ self.__resource = self.__session.resource(
85
+ self.service_name, config=self.config, endpoint_url=self.endpoint_url
86
+ )
87
+ return self.__resource
@@ -4,7 +4,7 @@ Maintainers: Eric Wilson
4
4
  MIT License. See Project Root for the license information.
5
5
  """
6
6
 
7
- from typing import Optional
7
+ from typing import Optional, List
8
8
 
9
9
  from aws_lambda_powertools import Logger
10
10
  from boto3_assist.boto3session import Boto3SessionManager
@@ -31,6 +31,8 @@ class Connection:
31
31
  aws_secret_access_key: Optional[str] = None,
32
32
  aws_end_point_url: Optional[str] = None,
33
33
  assume_role_arn: Optional[str] = None,
34
+ assume_role_chain: Optional[List[str]] = None,
35
+ assume_role_duration_seconds: Optional[int] = 3600,
34
36
  ) -> None:
35
37
  self.__aws_profile = aws_profile
36
38
  self.__aws_region = aws_region
@@ -40,7 +42,8 @@ class Connection:
40
42
  self.__session: Boto3SessionManager | None = None
41
43
  self.__assume_role_arn: Optional[str] = assume_role_arn
42
44
  self.__service_name: str | None = service_name
43
-
45
+ self.__assume_role_chain = assume_role_chain
46
+ self.__assume_role_duration_seconds = assume_role_duration_seconds
44
47
  if self.__service_name is None:
45
48
  raise RuntimeError(
46
49
  "Service Name is not available. The service name is required."
@@ -75,6 +78,8 @@ class Connection:
75
78
  aws_secret_access_key=self.aws_secret_access_key,
76
79
  aws_endpoint_url=self.end_point_url,
77
80
  assume_role_arn=self.__assume_role_arn,
81
+ assume_role_chain=self.__assume_role_chain,
82
+ assume_role_duration_seconds=self.__assume_role_duration_seconds,
78
83
  )
79
84
 
80
85
  tracker.add(service_name=self.service_name)
@@ -4,7 +4,7 @@ Maintainers: Eric Wilson
4
4
  MIT License. See Project Root for the license information.
5
5
  """
6
6
 
7
- from typing import Optional
7
+ from typing import Optional, List
8
8
  from typing import TYPE_CHECKING
9
9
 
10
10
  from aws_lambda_powertools import Logger
@@ -33,6 +33,8 @@ class DynamoDBConnection(Connection):
33
33
  aws_access_key_id: Optional[str] = None,
34
34
  aws_secret_access_key: Optional[str] = None,
35
35
  assume_role_arn: Optional[str] = None,
36
+ assume_role_chain: Optional[List[str]] = None,
37
+ assume_role_duration_seconds: Optional[int] = 3600,
36
38
  ) -> None:
37
39
  super().__init__(
38
40
  service_name="dynamodb",
@@ -42,6 +44,8 @@ class DynamoDBConnection(Connection):
42
44
  aws_secret_access_key=aws_secret_access_key,
43
45
  aws_end_point_url=aws_end_point_url,
44
46
  assume_role_arn=assume_role_arn,
47
+ assume_role_chain=assume_role_chain,
48
+ assume_role_duration_seconds=assume_role_duration_seconds,
45
49
  )
46
50
 
47
51
  self.__dynamodb_client: DynamoDBClient | None = None
@@ -0,0 +1,38 @@
1
+ """
2
+ Geek Cafe, LLC
3
+ Maintainers: Eric Wilson
4
+ MIT License. See Project Root for the license information.
5
+ """
6
+
7
+ import boto3
8
+ from typing import List
9
+
10
+
11
+ class RoleAssumptionMixin:
12
+ def _assume_roles_in_chain(
13
+ self,
14
+ base_session: boto3.Session,
15
+ role_chain: List[str],
16
+ session_name: str,
17
+ duration_seconds: int,
18
+ region: str,
19
+ ) -> boto3.Session:
20
+ session = base_session
21
+
22
+ for role_arn in role_chain:
23
+ sts_client = session.client("sts")
24
+ response = sts_client.assume_role(
25
+ RoleArn=role_arn,
26
+ RoleSessionName=session_name,
27
+ DurationSeconds=duration_seconds,
28
+ )
29
+ creds = response["Credentials"]
30
+
31
+ session = boto3.Session(
32
+ aws_access_key_id=creds["AccessKeyId"],
33
+ aws_secret_access_key=creds["SecretAccessKey"],
34
+ aws_session_token=creds["SessionToken"],
35
+ region_name=region,
36
+ )
37
+
38
+ return session
@@ -0,0 +1,29 @@
1
+ """
2
+ Geek Cafe, LLC
3
+ Maintainers: Eric Wilson
4
+ MIT License. See Project Root for the license information.
5
+ """
6
+
7
+ import boto3
8
+ from typing import Optional
9
+
10
+
11
+ class SessionSetupMixin:
12
+ def _create_base_session(
13
+ self,
14
+ aws_profile: Optional[str],
15
+ aws_region: Optional[str],
16
+ aws_access_key_id: Optional[str],
17
+ aws_secret_access_key: Optional[str],
18
+ aws_session_token: Optional[str],
19
+ ) -> boto3.Session:
20
+ try:
21
+ return boto3.Session(
22
+ profile_name=aws_profile,
23
+ region_name=aws_region,
24
+ aws_access_key_id=aws_access_key_id,
25
+ aws_secret_access_key=aws_secret_access_key,
26
+ aws_session_token=aws_session_token,
27
+ )
28
+ except Exception as e:
29
+ raise RuntimeError(f"Failed to create boto3 session: {e}") from e
@@ -0,0 +1 @@
1
+ __version__ = '0.14.0'
@@ -1,190 +0,0 @@
1
- """
2
- Geek Cafe, LLC
3
- Maintainers: Eric Wilson
4
- MIT License. See Project Root for the license information.
5
- """
6
-
7
- from typing import Any, Optional
8
-
9
- import boto3
10
- from aws_lambda_powertools import Logger
11
- from botocore.config import Config
12
- from botocore.exceptions import ProfileNotFound
13
- from boto3_assist.environment_services.environment_variables import EnvironmentVariables
14
-
15
-
16
- logger = Logger(__name__)
17
-
18
-
19
- class Boto3SessionManager:
20
- """Manages Boto3 Sessions"""
21
-
22
- def __init__(
23
- self,
24
- service_name: str,
25
- *,
26
- aws_profile: Optional[str] = None,
27
- aws_region: Optional[str] = None,
28
- assume_role_arn: Optional[str] = None,
29
- assume_role_session_name: Optional[str] = None,
30
- # cross_account_role_arn: Optional[str] = None,
31
- config: Optional[Config] = None,
32
- aws_endpoint_url: Optional[str] = None,
33
- aws_access_key_id: Optional[str] = None,
34
- aws_secret_access_key: Optional[str] = None,
35
- aws_session_token: Optional[str] = None,
36
- ):
37
- self.service_name = service_name
38
- self.aws_profile = aws_profile
39
- self.aws_region = aws_region
40
- self.assume_role_arn = assume_role_arn
41
- self.assume_role_session_name = assume_role_session_name
42
- self.config = config
43
- # # self.cross_account_role_arn = cross_account_role_arn
44
- self.endpoint_url = aws_endpoint_url
45
- self.aws_access_key_id = aws_access_key_id
46
- self.aws_secret_access_key = aws_secret_access_key
47
- self.aws_session_token = aws_session_token
48
-
49
- self.__session: Any = None
50
- self.__client: Any = None
51
- self.__resource: Any = None
52
-
53
- self.__setup()
54
-
55
- def __setup(self):
56
- """Setup AWS session, client, and resource."""
57
-
58
- profile = self.aws_profile or EnvironmentVariables.AWS.profile()
59
- region = self.aws_region or EnvironmentVariables.AWS.region()
60
-
61
- logger.debug("Connecting without assuming a role.")
62
- self.__session = self.__get_aws_session(profile, region)
63
-
64
- if profile:
65
- print(f"Connecting with a profile: {profile}")
66
-
67
- if self.assume_role_arn:
68
- self.__assume_role()
69
-
70
- def __assume_role(self):
71
- """Assume an AWS IAM role."""
72
- try:
73
- if not self.__session:
74
- raise RuntimeError(
75
- "Session must be established before assuming a role."
76
- )
77
-
78
- logger.debug(f"Assuming role {self.assume_role_arn}")
79
-
80
- sts_client = self.__session.client("sts")
81
- session_name = (
82
- self.assume_role_session_name
83
- or f"AssumeRoleSessionFor{self.service_name}"
84
- )
85
-
86
- assumed_role_response = sts_client.assume_role(
87
- RoleArn=self.assume_role_arn,
88
- RoleSessionName=session_name,
89
- )
90
- credentials = assumed_role_response["Credentials"]
91
-
92
- # Now override the session with assumed credentials
93
- self.__session = boto3.Session(
94
- aws_access_key_id=credentials["AccessKeyId"],
95
- aws_secret_access_key=credentials["SecretAccessKey"],
96
- aws_session_token=credentials["SessionToken"],
97
- region_name=self.aws_region,
98
- )
99
- logger.debug("Successfully assumed role and created new session.")
100
-
101
- except Exception as e:
102
- logger.error(f"Error assuming role: {e}")
103
- raise RuntimeError(f"Failed to assume role {self.assume_role_arn}") from e
104
-
105
- def __get_aws_session(
106
- self, aws_profile: Optional[str] = None, aws_region: Optional[str] = None
107
- ) -> boto3.Session | None:
108
- """Get a boto3 session for AWS."""
109
- logger.debug({"profile": aws_profile, "region": aws_region})
110
- try:
111
- self.aws_profile = aws_profile or EnvironmentVariables.AWS.profile()
112
- self.aws_region = aws_region or EnvironmentVariables.AWS.region()
113
- tmp_access_key_id = self.aws_access_key_id
114
- tmp_secret_access_key = self.aws_secret_access_key
115
- if not EnvironmentVariables.AWS.display_aws_access_key_id():
116
- tmp_access_key_id = (
117
- "None" if tmp_access_key_id is None else "***************"
118
- )
119
- if not EnvironmentVariables.AWS.display_aws_secret_access_key():
120
- tmp_secret_access_key = (
121
- "None" if tmp_secret_access_key is None else "***************"
122
- )
123
-
124
- logger.debug(
125
- {
126
- "profile": self.aws_profile,
127
- "region": self.aws_region,
128
- "aws_access_key_id": tmp_access_key_id,
129
- "aws_secret_access_key": tmp_secret_access_key,
130
- "aws_session_token": (
131
- "*******" if self.aws_session_token is not None else ""
132
- ),
133
- }
134
- )
135
- logger.debug("Creating boto3 session")
136
- session = self.__create_boto3_session()
137
- # if self.aws_profile or self.aws_region
138
- # else boto3.Session()
139
-
140
- except Exception as e:
141
- logger.error(e)
142
- raise RuntimeError("Failed to create a boto3 session.") from e
143
-
144
- logger.debug({"session": session})
145
- return session
146
-
147
- @property
148
- def client(self) -> Any:
149
- """Return the boto3 client connection."""
150
- if not self.__client:
151
- logger.debug(f"Creating {self.service_name} client")
152
- self.__client = self.__session.client(
153
- self.service_name,
154
- config=self.config,
155
- endpoint_url=self.endpoint_url,
156
- )
157
-
158
- return self.__client
159
-
160
- @property
161
- def resource(self) -> Any:
162
- """Return the boto3 resource connection."""
163
- if not self.__resource:
164
- logger.debug(f"Creating {self.service_name} resource")
165
- self.__resource = self.__session.resource(
166
- self.service_name,
167
- config=self.config,
168
- endpoint_url=self.endpoint_url,
169
- )
170
- return self.__resource
171
-
172
- def __create_boto3_session(self) -> boto3.Session | None:
173
- try:
174
- logger.debug(f"Creating session for {self.service_name}")
175
- session = boto3.Session(
176
- profile_name=self.aws_profile,
177
- region_name=self.aws_region,
178
- aws_access_key_id=self.aws_access_key_id,
179
- aws_secret_access_key=self.aws_secret_access_key,
180
- aws_session_token=self.aws_session_token,
181
- )
182
- return session
183
- except ProfileNotFound as e:
184
- print(
185
- f"An error occurred setting up the boto3 sessions. Profile not found: {e}"
186
- )
187
- raise e
188
- except Exception as e:
189
- print(f"An error occurred setting up the boto3 sessions: {e}")
190
- raise e
@@ -1 +0,0 @@
1
- __version__ = '0.12.0'
File without changes
File without changes
File without changes
File without changes
File without changes