Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

#643 PPYolo-E

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-344-PP-Yolo-E-Training-Replicate-Recipe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  1. import sys
  2. import boto3
  3. import logging
  4. from botocore.exceptions import ClientError, ProfileNotFound
  5. class AWSConnector:
  6. """
  7. AWSConnector - Connects to AWS using Credentials File or IAM Role
  8. """
  9. @staticmethod
  10. def __create_boto_3_session(profile_name: str):
  11. """
  12. __create_boto_3_session
  13. :param profile_name:
  14. :return:
  15. """
  16. current_class_name = __class__.__name__
  17. logger = logging.getLogger(current_class_name)
  18. try:
  19. try:
  20. if profile_name and boto3.session.Session(profile_name=profile_name).get_credentials():
  21. # TRY USING A SPECIFIC PROFILE_NAME (USING A CREDENTIALS FILE)
  22. logger.info("Trying to connect to AWS using Credentials File with profile_name: " + profile_name)
  23. session = boto3.Session(profile_name=profile_name)
  24. return session
  25. except ProfileNotFound as profileNotFoundException:
  26. logger.debug(
  27. "[" + current_class_name + "] - Could not find profile name - Trying using Default Profile/IAM Role" + str(profileNotFoundException)
  28. )
  29. # TRY USING AN IAM ROLE (OR *DEFAULT* CREDENTIALS - USING A CREDENTIALS FILE)
  30. logger.info("Trying to connect to AWS using IAM role or Default Credentials")
  31. session = boto3.Session()
  32. return session
  33. except Exception as ex:
  34. logger.critical("[" + current_class_name + "] - Caught Exception while trying to connect to AWS Credentials Manager " + str(ex))
  35. return None
  36. @staticmethod
  37. def get_aws_session(profile_name: str) -> boto3.Session:
  38. """
  39. get_aws_session - Connects to AWS to retrieve an AWS Session
  40. :param profile_name: The Config Profile (Environment Name in Credentials file)
  41. :return: boto3 Session
  42. """
  43. current_class_name = __class__.__name__
  44. logger = logging.getLogger(current_class_name)
  45. aws_session = AWSConnector.__create_boto_3_session(profile_name=profile_name)
  46. if aws_session is None:
  47. logger.error("Failed to initiate an AWS Session")
  48. return aws_session
  49. @staticmethod
  50. def get_aws_client_for_service_name(profile_name: str, service_name: str) -> boto3.Session.client:
  51. """
  52. get_aws_client_for_service_name - Connects to AWS to retrieve the relevant Client
  53. :param profile_name: The Config Profile (Environment Name in Credentials file)
  54. :param service_name: The AWS Service name to get the Client for
  55. :return: Service client instance
  56. """
  57. current_class_name = __class__.__name__
  58. logger = logging.getLogger(current_class_name)
  59. aws_session = AWSConnector.__create_boto_3_session(profile_name=profile_name)
  60. if aws_session is None:
  61. logger.error("Failed to connect to AWS client: " + str(service_name))
  62. return aws_session.client(service_name=service_name)
  63. @staticmethod
  64. def get_aws_resource_for_service_name(profile_name: str, service_name: str) -> boto3.Session.resource:
  65. """
  66. Connects to AWS to retrieve the relevant Resource (More functionality then Client)
  67. :param profile_name: The Config Profile (Environment Name in Credentials file)
  68. :param service_name: The AWS Service name to get the Client for
  69. :return: Service client instance
  70. """
  71. current_class_name = __class__.__name__
  72. logger = logging.getLogger(current_class_name)
  73. aws_session = AWSConnector.__create_boto_3_session(profile_name=profile_name)
  74. if aws_session is None:
  75. logger.error("Failed to connect to AWS client: " + str(service_name))
  76. return aws_session.resource(service_name=service_name)
  77. @staticmethod
  78. def is_client_error(code):
  79. e = sys.exc_info()[1]
  80. if isinstance(e, ClientError) and e.response["Error"]["Code"] == code:
  81. return ClientError
  82. return type("NeverEverRaisedException", (Exception,), {})
Discard
Tip!

Press p or to see the previous file or, n or to see the next file