From 7fdccdb0fc65b74641f79c4c2318374bb33644c2 Mon Sep 17 00:00:00 2001 From: Roja Reddy Sareddy Date: Thu, 17 Jul 2025 01:27:40 -0700 Subject: [PATCH 1/2] Fix: Do not generate empty classes --- src/sagemaker_core/tools/resources_codegen.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/sagemaker_core/tools/resources_codegen.py b/src/sagemaker_core/tools/resources_codegen.py index c4466e94..b8fb9643 100644 --- a/src/sagemaker_core/tools/resources_codegen.py +++ b/src/sagemaker_core/tools/resources_codegen.py @@ -339,8 +339,11 @@ def generate_resource_class( str: The formatted resource class. """ - # Initialize an empty string for the resource class - resource_class = "" + resource_class = f"class {resource_name}(Base):\n" + class_documentation_string = f"Class representing resource {resource_name}\n" + basic_class_content = resource_class + add_indent( + f'"""\n{class_documentation_string}\n"""\n', 4 + ) # _get_class_attributes will return value only if the resource has get or get_all method if class_attribute_info := self._get_class_attributes(resource_name, class_methods): @@ -348,11 +351,7 @@ def generate_resource_class( class_attribute_info ) - # Start defining the class - resource_class = f"class {resource_name}(Base):\n" - - class_documentation_string = f"Class representing resource {resource_name}\n\n" - class_documentation_string += f"Attributes:\n" + class_documentation_string += f"\nAttributes:\n" class_documentation_string += self._get_shape_attr_documentation_string( attributes_and_documentation ) @@ -444,9 +443,12 @@ def generate_resource_class( else: # If there's no 'get' or 'list' or 'create' method, generate a class with no attributes resource_attributes = [] - resource_class = f"class {resource_name}(Base):\n" - class_documentation_string = f"Class representing resource {resource_name}\n" - resource_class += add_indent(f'"""\n{class_documentation_string}\n"""\n', 4) + resource_class = basic_class_content + + # if there are no attributes or methods including addition operations + # class need not be generated + if resource_name not in self.resource_methods: + return "" if resource_name in self.resource_methods: # TODO: use resource_methods for all methods From 90facf706a205a2b059965aee122d165b22c19a5 Mon Sep 17 00:00:00 2001 From: Roja Reddy Sareddy Date: Thu, 17 Jul 2025 11:11:25 -0700 Subject: [PATCH 2/2] Fix: Do not generate empty classes --- src/sagemaker_core/main/resources.py | 20074 ++++++++++++------------- tst/tools/test_resources_codegen.py | 27 + 2 files changed, 9893 insertions(+), 10208 deletions(-) diff --git a/src/sagemaker_core/main/resources.py b/src/sagemaker_core/main/resources.py index 2f9acf68..b0cba972 100644 --- a/src/sagemaker_core/main/resources.py +++ b/src/sagemaker_core/main/resources.py @@ -1,3 +1,4 @@ + # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You @@ -25,22 +26,8 @@ from rich.style import Style from sagemaker_core.main.code_injection.codec import transform from sagemaker_core.main.code_injection.constants import Color -from sagemaker_core.main.utils import ( - SageMakerClient, - ResourceIterator, - Unassigned, - get_textual_rich_logger, - snake_to_pascal, - pascal_to_snake, - is_not_primitive, - is_not_str_dict, - is_primitive_list, - serialize, -) -from sagemaker_core.main.default_configs_helper import ( - load_default_configs_for_resource_name, - get_config_value, -) +from sagemaker_core.main.utils import SageMakerClient, ResourceIterator, Unassigned, get_textual_rich_logger, snake_to_pascal, pascal_to_snake, is_not_primitive, is_not_str_dict, is_primitive_list, serialize +from sagemaker_core.main.default_configs_helper import load_default_configs_for_resource_name, get_config_value from sagemaker_core.main.logs import MultiLogStreamHandler from sagemaker_core.main.exceptions import * import sagemaker_core.main.shapes as shapes @@ -51,13 +38,11 @@ class Base(BaseModel): model_config = ConfigDict(protected_namespaces=(), validate_assignment=True, extra="forbid") - + @classmethod - def get_sagemaker_client(cls, session=None, region_name=None, service_name="sagemaker"): - return SageMakerClient(session=session, region_name=region_name).get_client( - service_name=service_name - ) - + def get_sagemaker_client(cls, session = None, region_name = None, service_name = 'sagemaker'): + return SageMakerClient(session=session, region_name=region_name).get_client(service_name=service_name) + @staticmethod def get_updated_kwargs_with_configured_attributes( config_schema_for_resource: dict, resource_name: str, **kwargs @@ -75,30 +60,25 @@ def get_updated_kwargs_with_configured_attributes( configurable_attribute, resource_defaults, global_defaults ): resource_name = snake_to_pascal(configurable_attribute) - class_object = getattr(shapes, resource_name, None) or globals().get( - resource_name - ) + class_object = getattr(shapes, resource_name, None) or globals().get(resource_name) kwargs[configurable_attribute] = class_object(**config_value) except BaseException as e: logger.debug("Could not load Default Configs. Continuing.", exc_info=True) # Continue with existing kwargs if no default configs found - return kwargs - + return kwargs + + @staticmethod def populate_chained_attributes(resource_name: str, operation_input_args: Union[dict, object]): resource_name_in_snake_case = pascal_to_snake(resource_name) - updated_args = ( - vars(operation_input_args) - if type(operation_input_args) == object - else operation_input_args - ) + updated_args = vars(operation_input_args) if type(operation_input_args) == object else operation_input_args unassigned_args = [] keys = operation_input_args.keys() for arg in keys: value = operation_input_args.get(arg) arg_snake = pascal_to_snake(arg) - if value == Unassigned(): + if value == Unassigned() : unassigned_args.append(arg) elif value == None or not value: continue @@ -112,7 +92,10 @@ def populate_chained_attributes(resource_name: str, operation_input_args: Union[ elif isinstance(value, list) and is_primitive_list(value): continue elif isinstance(value, list) and value != []: - updated_args[arg] = [Base._get_chained_attribute(list_item) for list_item in value] + updated_args[arg] = [ + Base._get_chained_attribute(list_item) + for list_item in value + ] elif is_not_primitive(value) and is_not_str_dict(value) and type(value) == object: updated_args[arg] = Base._get_chained_attribute(item_value=value) @@ -126,11 +109,10 @@ def _get_chained_attribute(item_value: Any): class_object = globals().get(resource_name) or getattr(shapes, resource_name, None) if class_object is None: return item_value - return class_object( - **Base.populate_chained_attributes( - resource_name=resource_name, operation_input_args=vars(item_value) - ) - ) + return class_object(**Base.populate_chained_attributes( + resource_name=resource_name, + operation_input_args=vars(item_value) + )) @staticmethod def add_validate_call(func): @@ -138,14 +120,12 @@ def add_validate_call(func): def wrapper(*args, **kwargs): config = dict(arbitrary_types_allowed=True) return validate_call(config=config)(func)(*args, **kwargs) - return wrapper - class Action(Base): """ Class representing resource Action - + Attributes: action_name: The name of the action. action_arn: The Amazon Resource Name (ARN) of the action. @@ -155,14 +135,13 @@ class Action(Base): status: The status of the action. properties: A list of the action's properties. creation_time: When the action was created. - created_by: + created_by: last_modified_time: When the action was last modified. - last_modified_by: - metadata_properties: + last_modified_by: + metadata_properties: lineage_group_arn: The Amazon Resource Name (ARN) of the lineage group. - + """ - action_name: str action_arn: Optional[str] = Unassigned() source: Optional[shapes.ActionSource] = Unassigned() @@ -176,23 +155,23 @@ class Action(Base): last_modified_by: Optional[shapes.UserContext] = Unassigned() metadata_properties: Optional[shapes.MetadataProperties] = Unassigned() lineage_group_arn: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "action_name" - resource_name_split = resource_name.split("_") + resource_name = 'action_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object action") return None - + @classmethod @Base.add_validate_call def create( @@ -210,7 +189,7 @@ def create( ) -> Optional["Action"]: """ Create a Action resource - + Parameters: action_name: The name of the action. Must be unique to your account in an Amazon Web Services Region. source: The source type, ID, and URI. @@ -218,16 +197,16 @@ def create( description: The description of the action. status: The status of the action. properties: A list of properties to add to the action. - metadata_properties: + metadata_properties: tags: A list of tags to apply to the action. session: Boto3 session. region: Region name. - + Returns: The Action resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -241,38 +220,34 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating action resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ActionName": action_name, - "Source": source, - "ActionType": action_type, - "Description": description, - "Status": status, - "Properties": properties, - "MetadataProperties": metadata_properties, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Action", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ActionName': action_name, + 'Source': source, + 'ActionType': action_type, + 'Description': description, + 'Status': status, + 'Properties': properties, + 'MetadataProperties': metadata_properties, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Action', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_action(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(action_name=action_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -283,17 +258,17 @@ def get( ) -> Optional["Action"]: """ Get a Action resource - + Parameters: action_name: The name of the action to describe. session: Boto3 session. region: Region name. - + Returns: The Action resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -304,38 +279,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ActionName": action_name, + 'ActionName': action_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_action(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeActionResponse") + transformed_response = transform(response, 'DescribeActionResponse') action = cls(**transformed_response) return action - + @Base.add_validate_call def refresh( self, - ) -> Optional["Action"]: + + ) -> Optional["Action"]: """ Refresh a Action resource - + Returns: The Action resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -346,21 +320,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ActionName": self.action_name, + 'ActionName': self.action_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_action(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeActionResponse", self) + transform(response, 'DescribeActionResponse', self) return self - + @Base.add_validate_call def update( self, @@ -371,15 +345,15 @@ def update( ) -> Optional["Action"]: """ Update a Action resource - + Parameters: properties_to_remove: A list of properties to remove. - + Returns: The Action resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -391,38 +365,39 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating action resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ActionName": self.action_name, - "Description": description, - "Status": status, - "Properties": properties, - "PropertiesToRemove": properties_to_remove, + 'ActionName': self.action_name, + 'Description': description, + 'Status': status, + 'Properties': properties, + 'PropertiesToRemove': properties_to_remove, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_action(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Action resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -433,20 +408,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ActionName": self.action_name, + 'ActionName': self.action_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_action(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -462,7 +437,7 @@ def get_all( ) -> ResourceIterator["Action"]: """ Get all Action resources - + Parameters: source_uri: A filter that returns only actions with the specified source URI. action_type: A filter that returns only actions of the specified type. @@ -474,12 +449,12 @@ def get_all( max_results: The maximum number of actions to return in the response. The default value is 10. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Action resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -490,38 +465,37 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SourceUri": source_uri, - "ActionType": action_type, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'SourceUri': source_uri, + 'ActionType': action_type, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_actions", - summaries_key="ActionSummaries", - summary_name="ActionSummary", + list_method='list_actions', + summaries_key='ActionSummaries', + summary_name='ActionSummary', resource_cls=Action, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Algorithm(Base): """ Class representing resource Algorithm - + Attributes: algorithm_name: The name of the algorithm being described. algorithm_arn: The Amazon Resource Name (ARN) of the algorithm. @@ -534,9 +508,8 @@ class Algorithm(Base): validation_specification: Details about configurations for one or more training jobs that SageMaker runs to test the algorithm. product_id: The product identifier of the algorithm. certify_for_marketplace: Whether the algorithm is certified to be listed in Amazon Web Services Marketplace. - + """ - algorithm_name: str algorithm_arn: Optional[str] = Unassigned() algorithm_description: Optional[str] = Unassigned() @@ -548,44 +521,48 @@ class Algorithm(Base): algorithm_status_details: Optional[shapes.AlgorithmStatusDetails] = Unassigned() product_id: Optional[str] = Unassigned() certify_for_marketplace: Optional[bool] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "algorithm_name" - resource_name_split = resource_name.split("_") + resource_name = 'algorithm_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object algorithm") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "training_specification": { - "additional_s3_data_source": { - "s3_data_type": {"type": "string"}, - "s3_uri": {"type": "string"}, - } - }, - "validation_specification": {"validation_role": {"type": "string"}}, + config_schema_for_resource = \ + { + "training_specification": { + "additional_s3_data_source": { + "s3_data_type": { + "type": "string" + }, + "s3_uri": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Algorithm", **kwargs - ), - ) - + }, + "validation_specification": { + "validation_role": { + "type": "string" + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Algorithm", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -603,23 +580,23 @@ def create( ) -> Optional["Algorithm"]: """ Create a Algorithm resource - + Parameters: algorithm_name: The name of the algorithm. - training_specification: Specifies details about training jobs run by this algorithm, including the following: The Amazon ECR path of the container and the version digest of the algorithm. The hyperparameters that the algorithm supports. The instance types that the algorithm supports for training. Whether the algorithm supports distributed training. The metrics that the algorithm emits to Amazon CloudWatch. Which metrics that the algorithm emits can be used as the objective metric for hyperparameter tuning jobs. The input channels that the algorithm supports for training data. For example, an algorithm might support train, validation, and test channels. + training_specification: Specifies details about training jobs run by this algorithm, including the following: The Amazon ECR path of the container and the version digest of the algorithm. The hyperparameters that the algorithm supports. The instance types that the algorithm supports for training. Whether the algorithm supports distributed training. The metrics that the algorithm emits to Amazon CloudWatch. Which metrics that the algorithm emits can be used as the objective metric for hyperparameter tuning jobs. The input channels that the algorithm supports for training data. For example, an algorithm might support train, validation, and test channels. algorithm_description: A description of the algorithm. - inference_specification: Specifies details about inference jobs that the algorithm runs, including the following: The Amazon ECR paths of containers that contain the inference code and model artifacts. The instance types that the algorithm supports for transform jobs and real-time endpoints used for inference. The input and output content formats that the algorithm supports for inference. + inference_specification: Specifies details about inference jobs that the algorithm runs, including the following: The Amazon ECR paths of containers that contain the inference code and model artifacts. The instance types that the algorithm supports for transform jobs and real-time endpoints used for inference. The input and output content formats that the algorithm supports for inference. validation_specification: Specifies configurations for one or more training jobs and that SageMaker runs to test the algorithm's training code and, optionally, one or more batch transform jobs that SageMaker runs to test the algorithm's inference code. certify_for_marketplace: Whether to certify the algorithm so that it can be listed in Amazon Web Services Marketplace. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. session: Boto3 session. region: Region name. - + Returns: The Algorithm resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -632,37 +609,33 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating algorithm resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "AlgorithmName": algorithm_name, - "AlgorithmDescription": algorithm_description, - "TrainingSpecification": training_specification, - "InferenceSpecification": inference_specification, - "ValidationSpecification": validation_specification, - "CertifyForMarketplace": certify_for_marketplace, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Algorithm", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'AlgorithmName': algorithm_name, + 'AlgorithmDescription': algorithm_description, + 'TrainingSpecification': training_specification, + 'InferenceSpecification': inference_specification, + 'ValidationSpecification': validation_specification, + 'CertifyForMarketplace': certify_for_marketplace, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Algorithm', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_algorithm(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(algorithm_name=algorithm_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -673,17 +646,17 @@ def get( ) -> Optional["Algorithm"]: """ Get a Algorithm resource - + Parameters: algorithm_name: The name of the algorithm to describe. session: Boto3 session. region: Region name. - + Returns: The Algorithm resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -693,38 +666,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "AlgorithmName": algorithm_name, + 'AlgorithmName': algorithm_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_algorithm(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeAlgorithmOutput") + transformed_response = transform(response, 'DescribeAlgorithmOutput') algorithm = cls(**transformed_response) return algorithm - + @Base.add_validate_call def refresh( self, - ) -> Optional["Algorithm"]: + + ) -> Optional["Algorithm"]: """ Refresh a Algorithm resource - + Returns: The Algorithm resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -734,30 +706,31 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "AlgorithmName": self.algorithm_name, + 'AlgorithmName': self.algorithm_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_algorithm(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeAlgorithmOutput", self) + transform(response, 'DescribeAlgorithmOutput', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Algorithm resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -768,76 +741,74 @@ def delete( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "AlgorithmName": self.algorithm_name, + 'AlgorithmName': self.algorithm_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_algorithm(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Pending", "InProgress", "Completed", "Failed", "Deleting"], + target_status: Literal['Pending', 'InProgress', 'Completed', 'Failed', 'Deleting'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Algorithm resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Algorithm to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.algorithm_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Algorithm", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="Algorithm", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Algorithm", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -846,13 +817,13 @@ def wait_for_delete( ) -> None: """ Wait for a Algorithm resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -866,39 +837,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Algorithm to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.algorithm_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Algorithm", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -913,7 +879,7 @@ def get_all( ) -> ResourceIterator["Algorithm"]: """ Get all Algorithm resources - + Parameters: creation_time_after: A filter that returns only algorithms created after the specified time (timestamp). creation_time_before: A filter that returns only algorithms created before the specified time (timestamp). @@ -924,12 +890,12 @@ def get_all( sort_order: The sort order for the results. The default is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Algorithm resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -939,37 +905,36 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_algorithms", - summaries_key="AlgorithmSummaryList", - summary_name="AlgorithmSummary", + list_method='list_algorithms', + summaries_key='AlgorithmSummaryList', + summary_name='AlgorithmSummary', resource_cls=Algorithm, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class App(Base): """ Class representing resource App - + Attributes: app_arn: The Amazon Resource Name (ARN) of the app. app_type: The type of app. @@ -978,16 +943,15 @@ class App(Base): user_profile_name: The user profile name. space_name: The name of the space. If this value is not set, then UserProfileName must be set. status: The status. - recovery_mode: Indicates whether the application is launched in recovery mode. + recovery_mode: Indicates whether the application is launched in recovery mode. last_health_check_timestamp: The timestamp of the last health check. last_user_activity_timestamp: The timestamp of the last user's activity. LastUserActivityTimestamp is also updated when SageMaker AI performs health checks without user activity. As a result, this value is set to the same value as LastHealthCheckTimestamp. - creation_time: The creation time of the application. After an application has been shut down for 24 hours, SageMaker AI deletes all metadata for the application. To be considered an update and retain application metadata, applications must be restarted within 24 hours after the previous application has been shut down. After this time window, creation of an application is considered a new application rather than an update of the previous application. + creation_time: The creation time of the application. After an application has been shut down for 24 hours, SageMaker AI deletes all metadata for the application. To be considered an update and retain application metadata, applications must be restarted within 24 hours after the previous application has been shut down. After this time window, creation of an application is considered a new application rather than an update of the previous application. failure_reason: The failure reason. resource_spec: The instance type and the Amazon Resource Name (ARN) of the SageMaker AI image created on the instance. built_in_lifecycle_config_arn: The lifecycle configuration that runs before the default lifecycle configuration - + """ - domain_id: str app_type: str app_name: str @@ -1002,23 +966,23 @@ class App(Base): failure_reason: Optional[str] = Unassigned() resource_spec: Optional[shapes.ResourceSpec] = Unassigned() built_in_lifecycle_config_arn: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "app_name" - resource_name_split = resource_name.split("_") + resource_name = 'app_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object app") return None - + @classmethod @Base.add_validate_call def create( @@ -1036,7 +1000,7 @@ def create( ) -> Optional["App"]: """ Create a App resource - + Parameters: domain_id: The domain ID. app_type: The type of app. @@ -1044,16 +1008,16 @@ def create( user_profile_name: The user profile name. If this value is not set, then SpaceName must be set. space_name: The name of the space. If this value is not set, then UserProfileName must be set. tags: Each tag consists of a key and an optional value. Tag keys must be unique per resource. - resource_spec: The instance type and the Amazon Resource Name (ARN) of the SageMaker AI image created on the instance. The value of InstanceType passed as part of the ResourceSpec in the CreateApp call overrides the value passed as part of the ResourceSpec configured for the user profile or the domain. If InstanceType is not specified in any of those three ResourceSpec values for a KernelGateway app, the CreateApp call fails with a request validation error. - recovery_mode: Indicates whether the application is launched in recovery mode. + resource_spec: The instance type and the Amazon Resource Name (ARN) of the SageMaker AI image created on the instance. The value of InstanceType passed as part of the ResourceSpec in the CreateApp call overrides the value passed as part of the ResourceSpec configured for the user profile or the domain. If InstanceType is not specified in any of those three ResourceSpec values for a KernelGateway app, the CreateApp call fails with a request validation error. + recovery_mode: Indicates whether the application is launched in recovery mode. session: Boto3 session. region: Region name. - + Returns: The App resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1068,44 +1032,34 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating app resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "DomainId": domain_id, - "UserProfileName": user_profile_name, - "SpaceName": space_name, - "AppType": app_type, - "AppName": app_name, - "Tags": tags, - "ResourceSpec": resource_spec, - "RecoveryMode": recovery_mode, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="App", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'DomainId': domain_id, + 'UserProfileName': user_profile_name, + 'SpaceName': space_name, + 'AppType': app_type, + 'AppName': app_name, + 'Tags': tags, + 'ResourceSpec': resource_spec, + 'RecoveryMode': recovery_mode, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='App', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_app(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - domain_id=domain_id, - app_type=app_type, - app_name=app_name, - session=session, - region=region, - ) - + + return cls.get(domain_id=domain_id, app_type=app_type, app_name=app_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -1120,7 +1074,7 @@ def get( ) -> Optional["App"]: """ Get a App resource - + Parameters: domain_id: The domain ID. app_type: The type of app. @@ -1129,12 +1083,12 @@ def get( space_name: The name of the space. session: Boto3 session. region: Region name. - + Returns: The App resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1145,42 +1099,41 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": domain_id, - "UserProfileName": user_profile_name, - "SpaceName": space_name, - "AppType": app_type, - "AppName": app_name, + 'DomainId': domain_id, + 'UserProfileName': user_profile_name, + 'SpaceName': space_name, + 'AppType': app_type, + 'AppName': app_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_app(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeAppResponse") + transformed_response = transform(response, 'DescribeAppResponse') app = cls(**transformed_response) return app - + @Base.add_validate_call def refresh( self, - ) -> Optional["App"]: + + ) -> Optional["App"]: """ Refresh a App resource - + Returns: The App resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1191,34 +1144,35 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": self.domain_id, - "UserProfileName": self.user_profile_name, - "SpaceName": self.space_name, - "AppType": self.app_type, - "AppName": self.app_name, + 'DomainId': self.domain_id, + 'UserProfileName': self.user_profile_name, + 'SpaceName': self.space_name, + 'AppType': self.app_type, + 'AppName': self.app_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_app(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeAppResponse", self) + transform(response, 'DescribeAppResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a App resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1230,80 +1184,78 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "DomainId": self.domain_id, - "UserProfileName": self.user_profile_name, - "SpaceName": self.space_name, - "AppType": self.app_type, - "AppName": self.app_name, + 'DomainId': self.domain_id, + 'UserProfileName': self.user_profile_name, + 'SpaceName': self.space_name, + 'AppType': self.app_type, + 'AppName': self.app_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_app(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Deleted", "Deleting", "Failed", "InService", "Pending"], + target_status: Literal['Deleted', 'Deleting', 'Failed', 'InService', 'Pending'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a App resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for App to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="App", status=current_status, reason=self.failure_reason - ) - + raise FailedStatusError(resource_type="App", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="App", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -1312,13 +1264,13 @@ def wait_for_delete( ) -> None: """ Wait for a App resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1332,43 +1284,38 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for App to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + + if current_status.lower() == "deleted": print("Resource was deleted.") return - + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="App", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -1383,7 +1330,7 @@ def get_all( ) -> ResourceIterator["App"]: """ Get all App resources - + Parameters: next_token: If the previous response was truncated, you will receive this token. Use it in your next request to receive the next set of results. max_results: This parameter defines the maximum number of results that can be return in a single response. The MaxResults parameter is an upper bound, not a target. If there are more results available than the value specified, a NextToken is provided in the response. The NextToken indicates that the user should get the next set of results by providing this token as a part of a subsequent call. The default value for MaxResults is 10. @@ -1394,12 +1341,12 @@ def get_all( space_name_equals: A parameter to search by space name. If UserProfileNameEquals is set, then this value cannot be set. session: Boto3 session. region: Region name. - + Returns: Iterator for listed App resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1409,37 +1356,36 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortOrder": sort_order, - "SortBy": sort_by, - "DomainIdEquals": domain_id_equals, - "UserProfileNameEquals": user_profile_name_equals, - "SpaceNameEquals": space_name_equals, + 'SortOrder': sort_order, + 'SortBy': sort_by, + 'DomainIdEquals': domain_id_equals, + 'UserProfileNameEquals': user_profile_name_equals, + 'SpaceNameEquals': space_name_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_apps", - summaries_key="Apps", - summary_name="AppDetails", + list_method='list_apps', + summaries_key='Apps', + summary_name='AppDetails', resource_cls=App, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class AppImageConfig(Base): """ Class representing resource AppImageConfig - + Attributes: app_image_config_arn: The ARN of the AppImageConfig. app_image_config_name: The name of the AppImageConfig. @@ -1448,9 +1394,8 @@ class AppImageConfig(Base): kernel_gateway_image_config: The configuration of a KernelGateway app. jupyter_lab_app_image_config: The configuration of the JupyterLab app. code_editor_app_image_config: The configuration of the Code Editor app. - + """ - app_image_config_name: str app_image_config_arn: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() @@ -1458,23 +1403,23 @@ class AppImageConfig(Base): kernel_gateway_image_config: Optional[shapes.KernelGatewayImageConfig] = Unassigned() jupyter_lab_app_image_config: Optional[shapes.JupyterLabAppImageConfig] = Unassigned() code_editor_app_image_config: Optional[shapes.CodeEditorAppImageConfig] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "app_image_config_name" - resource_name_split = resource_name.split("_") + resource_name = 'app_image_config_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object app_image_config") return None - + @classmethod @Base.add_validate_call def create( @@ -1489,7 +1434,7 @@ def create( ) -> Optional["AppImageConfig"]: """ Create a AppImageConfig resource - + Parameters: app_image_config_name: The name of the AppImageConfig. Must be unique to your account. tags: A list of tags to apply to the AppImageConfig. @@ -1498,12 +1443,12 @@ def create( code_editor_app_image_config: The CodeEditorAppImageConfig. You can only specify one image kernel in the AppImageConfig API. This kernel is shown to users before the image starts. After the image runs, all kernels are visible in Code Editor. session: Boto3 session. region: Region name. - + Returns: The AppImageConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1517,35 +1462,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating app_image_config resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "AppImageConfigName": app_image_config_name, - "Tags": tags, - "KernelGatewayImageConfig": kernel_gateway_image_config, - "JupyterLabAppImageConfig": jupyter_lab_app_image_config, - "CodeEditorAppImageConfig": code_editor_app_image_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="AppImageConfig", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'AppImageConfigName': app_image_config_name, + 'Tags': tags, + 'KernelGatewayImageConfig': kernel_gateway_image_config, + 'JupyterLabAppImageConfig': jupyter_lab_app_image_config, + 'CodeEditorAppImageConfig': code_editor_app_image_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='AppImageConfig', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_app_image_config(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(app_image_config_name=app_image_config_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -1556,17 +1497,17 @@ def get( ) -> Optional["AppImageConfig"]: """ Get a AppImageConfig resource - + Parameters: app_image_config_name: The name of the AppImageConfig to describe. session: Boto3 session. region: Region name. - + Returns: The AppImageConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1577,38 +1518,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "AppImageConfigName": app_image_config_name, + 'AppImageConfigName': app_image_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_app_image_config(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeAppImageConfigResponse") + transformed_response = transform(response, 'DescribeAppImageConfigResponse') app_image_config = cls(**transformed_response) return app_image_config - + @Base.add_validate_call def refresh( self, - ) -> Optional["AppImageConfig"]: + + ) -> Optional["AppImageConfig"]: """ Refresh a AppImageConfig resource - + Returns: The AppImageConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1619,21 +1559,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "AppImageConfigName": self.app_image_config_name, + 'AppImageConfigName': self.app_image_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_app_image_config(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeAppImageConfigResponse", self) + transform(response, 'DescribeAppImageConfigResponse', self) return self - + @Base.add_validate_call def update( self, @@ -1643,12 +1583,12 @@ def update( ) -> Optional["AppImageConfig"]: """ Update a AppImageConfig resource - + Returns: The AppImageConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1659,37 +1599,38 @@ def update( ``` ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating app_image_config resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "AppImageConfigName": self.app_image_config_name, - "KernelGatewayImageConfig": kernel_gateway_image_config, - "JupyterLabAppImageConfig": jupyter_lab_app_image_config, - "CodeEditorAppImageConfig": code_editor_app_image_config, + 'AppImageConfigName': self.app_image_config_name, + 'KernelGatewayImageConfig': kernel_gateway_image_config, + 'JupyterLabAppImageConfig': jupyter_lab_app_image_config, + 'CodeEditorAppImageConfig': code_editor_app_image_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_app_image_config(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a AppImageConfig resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1700,20 +1641,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "AppImageConfigName": self.app_image_config_name, + 'AppImageConfigName': self.app_image_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_app_image_config(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -1730,7 +1671,7 @@ def get_all( ) -> ResourceIterator["AppImageConfig"]: """ Get all AppImageConfig resources - + Parameters: max_results: The total number of items to return in the response. If the total number of items available is more than the value specified, a NextToken is provided in the response. To resume pagination, provide the NextToken value in the as part of a subsequent call. The default value is 10. next_token: If the previous call to ListImages didn't return the full set of AppImageConfigs, the call returns a token for getting the next set of AppImageConfigs. @@ -1743,12 +1684,12 @@ def get_all( sort_order: The sort order. The default value is Descending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed AppImageConfig resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1758,39 +1699,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "ModifiedTimeBefore": modified_time_before, - "ModifiedTimeAfter": modified_time_after, - "SortBy": sort_by, - "SortOrder": sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'ModifiedTimeBefore': modified_time_before, + 'ModifiedTimeAfter': modified_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_app_image_configs", - summaries_key="AppImageConfigs", - summary_name="AppImageConfigDetails", + list_method='list_app_image_configs', + summaries_key='AppImageConfigs', + summary_name='AppImageConfigDetails', resource_cls=AppImageConfig, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Artifact(Base): """ Class representing resource Artifact - + Attributes: artifact_name: The name of the artifact. artifact_arn: The Amazon Resource Name (ARN) of the artifact. @@ -1798,14 +1738,13 @@ class Artifact(Base): artifact_type: The type of the artifact. properties: A list of the artifact's properties. creation_time: When the artifact was created. - created_by: + created_by: last_modified_time: When the artifact was last modified. - last_modified_by: - metadata_properties: + last_modified_by: + metadata_properties: lineage_group_arn: The Amazon Resource Name (ARN) of the lineage group. - + """ - artifact_arn: str artifact_name: Optional[str] = Unassigned() source: Optional[shapes.ArtifactSource] = Unassigned() @@ -1817,23 +1756,23 @@ class Artifact(Base): last_modified_by: Optional[shapes.UserContext] = Unassigned() metadata_properties: Optional[shapes.MetadataProperties] = Unassigned() lineage_group_arn: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "artifact_name" - resource_name_split = resource_name.split("_") + resource_name = 'artifact_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object artifact") return None - + @classmethod @Base.add_validate_call def create( @@ -1849,22 +1788,22 @@ def create( ) -> Optional["Artifact"]: """ Create a Artifact resource - + Parameters: source: The ID, ID type, and URI of the source. artifact_type: The artifact type. artifact_name: The name of the artifact. Must be unique to your account in an Amazon Web Services Region. properties: A list of properties to add to the artifact. - metadata_properties: + metadata_properties: tags: A list of tags to apply to the artifact. session: Boto3 session. region: Region name. - + Returns: The Artifact resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1878,36 +1817,32 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating artifact resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ArtifactName": artifact_name, - "Source": source, - "ArtifactType": artifact_type, - "Properties": properties, - "MetadataProperties": metadata_properties, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Artifact", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ArtifactName': artifact_name, + 'Source': source, + 'ArtifactType': artifact_type, + 'Properties': properties, + 'MetadataProperties': metadata_properties, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Artifact', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_artifact(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get(artifact_arn=response["ArtifactArn"], session=session, region=region) - + + return cls.get(artifact_arn=response['ArtifactArn'], session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -1918,17 +1853,17 @@ def get( ) -> Optional["Artifact"]: """ Get a Artifact resource - + Parameters: artifact_arn: The Amazon Resource Name (ARN) of the artifact to describe. session: Boto3 session. region: Region name. - + Returns: The Artifact resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1939,38 +1874,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ArtifactArn": artifact_arn, + 'ArtifactArn': artifact_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_artifact(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeArtifactResponse") + transformed_response = transform(response, 'DescribeArtifactResponse') artifact = cls(**transformed_response) return artifact - + @Base.add_validate_call def refresh( self, - ) -> Optional["Artifact"]: + + ) -> Optional["Artifact"]: """ Refresh a Artifact resource - + Returns: The Artifact resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -1981,21 +1915,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ArtifactArn": self.artifact_arn, + 'ArtifactArn': self.artifact_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_artifact(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeArtifactResponse", self) + transform(response, 'DescribeArtifactResponse', self) return self - + @Base.add_validate_call def update( self, @@ -2005,15 +1939,15 @@ def update( ) -> Optional["Artifact"]: """ Update a Artifact resource - + Parameters: properties_to_remove: A list of properties to remove. - + Returns: The Artifact resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2025,37 +1959,38 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating artifact resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ArtifactArn": self.artifact_arn, - "ArtifactName": artifact_name, - "Properties": properties, - "PropertiesToRemove": properties_to_remove, + 'ArtifactArn': self.artifact_arn, + 'ArtifactName': artifact_name, + 'Properties': properties, + 'PropertiesToRemove': properties_to_remove, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_artifact(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Artifact resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2066,21 +2001,21 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ArtifactArn": self.artifact_arn, - "Source": self.source, + 'ArtifactArn': self.artifact_arn, + 'Source': self.source, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_artifact(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -2096,7 +2031,7 @@ def get_all( ) -> ResourceIterator["Artifact"]: """ Get all Artifact resources - + Parameters: source_uri: A filter that returns only artifacts with the specified source URI. artifact_type: A filter that returns only artifacts of the specified type. @@ -2108,12 +2043,12 @@ def get_all( max_results: The maximum number of artifacts to return in the response. The default value is 10. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Artifact resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2124,38 +2059,37 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SourceUri": source_uri, - "ArtifactType": artifact_type, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'SourceUri': source_uri, + 'ArtifactType': artifact_type, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_artifacts", - summaries_key="ArtifactSummaries", - summary_name="ArtifactSummary", + list_method='list_artifacts', + summaries_key='ArtifactSummaries', + summary_name='ArtifactSummary', resource_cls=Artifact, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Association(Base): """ Class representing resource Association - + Attributes: source_arn: The ARN of the source. destination_arn: The Amazon Resource Name (ARN) of the destination. @@ -2165,10 +2099,9 @@ class Association(Base): source_name: The name of the source. destination_name: The name of the destination. creation_time: When the association was created. - created_by: - + created_by: + """ - source_arn: Optional[str] = Unassigned() destination_arn: Optional[str] = Unassigned() source_type: Optional[str] = Unassigned() @@ -2178,32 +2111,33 @@ class Association(Base): destination_name: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() created_by: Optional[shapes.UserContext] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "association_name" - resource_name_split = resource_name.split("_") + resource_name = 'association_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object association") return None - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Association resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2214,21 +2148,21 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "SourceArn": self.source_arn, - "DestinationArn": self.destination_arn, + 'SourceArn': self.source_arn, + 'DestinationArn': self.destination_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_association(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -2247,7 +2181,7 @@ def get_all( ) -> ResourceIterator["Association"]: """ Get all Association resources - + Parameters: source_arn: A filter that returns only associations with the specified source ARN. destination_arn: A filter that returns only associations with the specified destination Amazon Resource Name (ARN). @@ -2262,12 +2196,12 @@ def get_all( max_results: The maximum number of associations to return in the response. The default value is 10. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Association resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2278,58 +2212,56 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SourceArn": source_arn, - "DestinationArn": destination_arn, - "SourceType": source_type, - "DestinationType": destination_type, - "AssociationType": association_type, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'SourceArn': source_arn, + 'DestinationArn': destination_arn, + 'SourceType': source_type, + 'DestinationType': destination_type, + 'AssociationType': association_type, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_associations", - summaries_key="AssociationSummaries", - summary_name="AssociationSummary", + list_method='list_associations', + summaries_key='AssociationSummaries', + summary_name='AssociationSummary', resource_cls=Association, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + @classmethod @Base.add_validate_call def add( cls, source_arn: str, destination_arn: str, - association_type: Optional[str] = Unassigned(), - session: Optional[Session] = None, + association_type: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> None: """ Creates an association between the source and the destination. - + Parameters: source_arn: The ARN of the source. destination_arn: The Amazon Resource Name (ARN) of the destination. - association_type: The type of association. The following are suggested uses for each type. Amazon SageMaker places no restrictions on their use. ContributedTo - The source contributed to the destination or had a part in enabling the destination. For example, the training data contributed to the training job. AssociatedWith - The source is connected to the destination. For example, an approval workflow is associated with a model deployment. DerivedFrom - The destination is a modification of the source. For example, a digest output of a channel input for a processing job is derived from the original inputs. Produced - The source generated the destination. For example, a training job produced a model artifact. + association_type: The type of association. The following are suggested uses for each type. Amazon SageMaker places no restrictions on their use. ContributedTo - The source contributed to the destination or had a part in enabling the destination. For example, the training data contributed to the training job. AssociatedWith - The source is connected to the destination. For example, an approval workflow is associated with a model deployment. DerivedFrom - The destination is a modification of the source. For example, a digest output of a channel input for a processing job is derived from the original inputs. Produced - The source generated the destination. For example, a training job produced a model artifact. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2341,29 +2273,29 @@ def add( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "SourceArn": source_arn, - "DestinationArn": destination_arn, - "AssociationType": association_type, + 'SourceArn': source_arn, + 'DestinationArn': destination_arn, + 'AssociationType': association_type, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling add_association API") response = client.add_association(**operation_input_args) logger.debug(f"Response: {response}") + class AutoMLJob(Base): """ Class representing resource AutoMLJob - + Attributes: auto_ml_job_name: Returns the name of the AutoML job. auto_ml_job_arn: Returns the ARN of the AutoML job. @@ -2386,9 +2318,8 @@ class AutoMLJob(Base): resolved_attributes: Contains ProblemType, AutoMLJobObjective, and CompletionCriteria. If you do not provide these values, they are inferred. model_deploy_config: Indicates whether the model was deployed automatically to an endpoint and the name of that endpoint if deployed automatically. model_deploy_result: Provides information about endpoint for the model deployment. - + """ - auto_ml_job_name: str auto_ml_job_arn: Optional[str] = Unassigned() input_data_config: Optional[List[shapes.AutoMLChannel]] = Unassigned() @@ -2410,54 +2341,70 @@ class AutoMLJob(Base): resolved_attributes: Optional[shapes.ResolvedAttributes] = Unassigned() model_deploy_config: Optional[shapes.ModelDeployConfig] = Unassigned() model_deploy_result: Optional[shapes.ModelDeployResult] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "auto_ml_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'auto_ml_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object auto_ml_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "output_data_config": { - "s3_output_path": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "role_arn": {"type": "string"}, - "auto_ml_job_config": { - "security_config": { - "volume_kms_key_id": {"type": "string"}, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, - }, - "candidate_generation_config": { - "feature_specification_s3_uri": {"type": "string"} - }, + config_schema_for_resource = \ + { + "output_data_config": { + "s3_output_path": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + }, + "role_arn": { + "type": "string" + }, + "auto_ml_job_config": { + "security_config": { + "volume_kms_key_id": { + "type": "string" + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "candidate_generation_config": { + "feature_specification_s3_uri": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "AutoMLJob", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "AutoMLJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -2478,7 +2425,7 @@ def create( ) -> Optional["AutoMLJob"]: """ Create a AutoMLJob resource - + Parameters: auto_ml_job_name: Identifies an Autopilot job. The name must be unique to your account and is case insensitive. input_data_config: An array of channel objects that describes the input data and its location. Each channel is a named input source. Similar to InputDataConfig supported by HyperParameterTrainingJobDefinition. Format(s) supported: CSV, Parquet. A minimum of 500 rows is required for the training dataset. There is not a minimum number of rows required for the validation dataset. @@ -2492,12 +2439,12 @@ def create( model_deploy_config: Specifies how to generate the endpoint name for an automatic one-click Autopilot model deployment. session: Boto3 session. region: Region name. - + Returns: The AutoMLJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2512,40 +2459,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating auto_ml_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "AutoMLJobName": auto_ml_job_name, - "InputDataConfig": input_data_config, - "OutputDataConfig": output_data_config, - "ProblemType": problem_type, - "AutoMLJobObjective": auto_ml_job_objective, - "AutoMLJobConfig": auto_ml_job_config, - "RoleArn": role_arn, - "GenerateCandidateDefinitionsOnly": generate_candidate_definitions_only, - "Tags": tags, - "ModelDeployConfig": model_deploy_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="AutoMLJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'AutoMLJobName': auto_ml_job_name, + 'InputDataConfig': input_data_config, + 'OutputDataConfig': output_data_config, + 'ProblemType': problem_type, + 'AutoMLJobObjective': auto_ml_job_objective, + 'AutoMLJobConfig': auto_ml_job_config, + 'RoleArn': role_arn, + 'GenerateCandidateDefinitionsOnly': generate_candidate_definitions_only, + 'Tags': tags, + 'ModelDeployConfig': model_deploy_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='AutoMLJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_auto_ml_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(auto_ml_job_name=auto_ml_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -2556,17 +2499,17 @@ def get( ) -> Optional["AutoMLJob"]: """ Get a AutoMLJob resource - + Parameters: auto_ml_job_name: Requests information about an AutoML job using its unique name. session: Boto3 session. region: Region name. - + Returns: The AutoMLJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2577,38 +2520,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "AutoMLJobName": auto_ml_job_name, + 'AutoMLJobName': auto_ml_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_auto_ml_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeAutoMLJobResponse") + transformed_response = transform(response, 'DescribeAutoMLJobResponse') auto_ml_job = cls(**transformed_response) return auto_ml_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["AutoMLJob"]: + + ) -> Optional["AutoMLJob"]: """ Refresh a AutoMLJob resource - + Returns: The AutoMLJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2619,28 +2561,28 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "AutoMLJobName": self.auto_ml_job_name, + 'AutoMLJobName': self.auto_ml_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_auto_ml_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeAutoMLJobResponse", self) + transform(response, 'DescribeAutoMLJobResponse', self) return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a AutoMLJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2651,79 +2593,77 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "AutoMLJobName": self.auto_ml_job_name, + 'AutoMLJobName': self.auto_ml_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_auto_ml_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a AutoMLJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed", "Stopped"] + terminal_states = ['Completed', 'Failed', 'Stopped'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for AutoMLJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.auto_ml_job_status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="AutoMLJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="AutoMLJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="AutoMLJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -2741,7 +2681,7 @@ def get_all( ) -> ResourceIterator["AutoMLJob"]: """ Get all AutoMLJob resources - + Parameters: creation_time_after: Request a list of jobs, using a filter for time. creation_time_before: Request a list of jobs, using a filter for time. @@ -2755,12 +2695,12 @@ def get_all( next_token: If the previous response was truncated, you receive this token. Use it in your next request to receive the next set of results. session: Boto3 session. region: Region name. - + Returns: Iterator for listed AutoMLJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2770,48 +2710,47 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "StatusEquals": status_equals, - "SortOrder": sort_order, - "SortBy": sort_by, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'StatusEquals': status_equals, + 'SortOrder': sort_order, + 'SortBy': sort_by, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_auto_ml_jobs", - summaries_key="AutoMLJobSummaries", - summary_name="AutoMLJobSummary", + list_method='list_auto_ml_jobs', + summaries_key='AutoMLJobSummaries', + summary_name='AutoMLJobSummary', resource_cls=AutoMLJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_candidates( self, status_equals: Optional[str] = Unassigned(), candidate_name_equals: Optional[str] = Unassigned(), sort_order: Optional[str] = Unassigned(), - sort_by: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_by: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.AutoMLCandidate]: """ List the candidates created for the job. - + Parameters: status_equals: List the candidates for the job and filter by status. candidate_name_equals: List the candidates for the job and filter by candidate name. @@ -2821,12 +2760,12 @@ def get_all_candidates( next_token: If the previous response was truncated, you receive this token. Use it in your next request to receive the next set of results. session: Boto3 session. region: Region name. - + Returns: Iterator for listed AutoMLCandidate. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -2837,36 +2776,36 @@ def get_all_candidates( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "AutoMLJobName": self.auto_ml_job_name, - "StatusEquals": status_equals, - "CandidateNameEquals": candidate_name_equals, - "SortOrder": sort_order, - "SortBy": sort_by, + 'AutoMLJobName': self.auto_ml_job_name, + 'StatusEquals': status_equals, + 'CandidateNameEquals': candidate_name_equals, + 'SortOrder': sort_order, + 'SortBy': sort_by, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_candidates_for_auto_ml_job", - summaries_key="Candidates", - summary_name="AutoMLCandidate", + list_method='list_candidates_for_auto_ml_job', + summaries_key='Candidates', + summary_name='AutoMLCandidate', resource_cls=shapes.AutoMLCandidate, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class AutoMLJobV2(Base): """ Class representing resource AutoMLJobV2 - + Attributes: auto_ml_job_name: Returns the name of the AutoML job V2. auto_ml_job_arn: Returns the Amazon Resource Name (ARN) of the AutoML job V2. @@ -2884,16 +2823,15 @@ class AutoMLJobV2(Base): failure_reason: Returns the reason for the failure of the AutoML job V2, when applicable. partial_failure_reasons: Returns a list of reasons for partial failures within an AutoML job V2. best_candidate: Information about the candidate produced by an AutoML training job V2, including its status, steps, and other properties. - auto_ml_job_artifacts: + auto_ml_job_artifacts: resolved_attributes: Returns the resolved attributes used by the AutoML job V2. model_deploy_config: Indicates whether the model was deployed automatically to an endpoint and the name of that endpoint if deployed automatically. model_deploy_result: Provides information about endpoint for the model deployment. data_split_config: Returns the configuration settings of how the data are split into train and validation datasets. security_config: Returns the security configuration for traffic encryption or Amazon VPC settings. auto_ml_compute_config: The compute configuration used for the AutoML job V2. - + """ - auto_ml_job_name: str auto_ml_job_arn: Optional[str] = Unassigned() auto_ml_job_input_data_config: Optional[List[shapes.AutoMLJobChannel]] = Unassigned() @@ -2917,58 +2855,82 @@ class AutoMLJobV2(Base): data_split_config: Optional[shapes.AutoMLDataSplitConfig] = Unassigned() security_config: Optional[shapes.AutoMLSecurityConfig] = Unassigned() auto_ml_compute_config: Optional[shapes.AutoMLComputeConfig] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "auto_ml_job_v2_name" - resource_name_split = resource_name.split("_") + resource_name = 'auto_ml_job_v2_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object auto_ml_job_v2") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "output_data_config": { - "s3_output_path": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "role_arn": {"type": "string"}, - "auto_ml_problem_type_config": { - "time_series_forecasting_job_config": { - "feature_specification_s3_uri": {"type": "string"} - }, - "tabular_job_config": {"feature_specification_s3_uri": {"type": "string"}}, - }, - "security_config": { - "volume_kms_key_id": {"type": "string"}, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, - }, - "auto_ml_compute_config": { - "emr_serverless_compute_config": {"execution_role_arn": {"type": "string"}} - }, + config_schema_for_resource = \ + { + "output_data_config": { + "s3_output_path": { + "type": "string" + }, + "kms_key_id": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "AutoMLJobV2", **kwargs - ), - ) - + }, + "role_arn": { + "type": "string" + }, + "auto_ml_problem_type_config": { + "time_series_forecasting_job_config": { + "feature_specification_s3_uri": { + "type": "string" + } + }, + "tabular_job_config": { + "feature_specification_s3_uri": { + "type": "string" + } + } + }, + "security_config": { + "volume_kms_key_id": { + "type": "string" + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "auto_ml_compute_config": { + "emr_serverless_compute_config": { + "execution_role_arn": { + "type": "string" + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "AutoMLJobV2", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -2990,27 +2952,27 @@ def create( ) -> Optional["AutoMLJobV2"]: """ Create a AutoMLJobV2 resource - + Parameters: auto_ml_job_name: Identifies an Autopilot job. The name must be unique to your account and is case insensitive. - auto_ml_job_input_data_config: An array of channel objects describing the input data and their location. Each channel is a named input source. Similar to the InputDataConfig attribute in the CreateAutoMLJob input parameters. The supported formats depend on the problem type: For tabular problem types: S3Prefix, ManifestFile. For image classification: S3Prefix, ManifestFile, AugmentedManifestFile. For text classification: S3Prefix. For time-series forecasting: S3Prefix. For text generation (LLMs fine-tuning): S3Prefix. + auto_ml_job_input_data_config: An array of channel objects describing the input data and their location. Each channel is a named input source. Similar to the InputDataConfig attribute in the CreateAutoMLJob input parameters. The supported formats depend on the problem type: For tabular problem types: S3Prefix, ManifestFile. For image classification: S3Prefix, ManifestFile, AugmentedManifestFile. For text classification: S3Prefix. For time-series forecasting: S3Prefix. For text generation (LLMs fine-tuning): S3Prefix. output_data_config: Provides information about encryption and the Amazon S3 output path needed to store artifacts from an AutoML job. auto_ml_problem_type_config: Defines the configuration settings of one of the supported problem types. role_arn: The ARN of the role that is used to access the data. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, such as by purpose, owner, or environment. For more information, see Tagging Amazon Web ServicesResources. Tag keys must be unique per resource. security_config: The security configuration for traffic encryption or Amazon VPC settings. - auto_ml_job_objective: Specifies a metric to minimize or maximize as the objective of a job. If not specified, the default objective metric depends on the problem type. For the list of default values per problem type, see AutoMLJobObjective. For tabular problem types: You must either provide both the AutoMLJobObjective and indicate the type of supervised learning problem in AutoMLProblemTypeConfig (TabularJobConfig.ProblemType), or none at all. For text generation problem types (LLMs fine-tuning): Fine-tuning language models in Autopilot does not require setting the AutoMLJobObjective field. Autopilot fine-tunes LLMs without requiring multiple candidates to be trained and evaluated. Instead, using your dataset, Autopilot directly fine-tunes your target model to enhance a default objective metric, the cross-entropy loss. After fine-tuning a language model, you can evaluate the quality of its generated text using different metrics. For a list of the available metrics, see Metrics for fine-tuning LLMs in Autopilot. + auto_ml_job_objective: Specifies a metric to minimize or maximize as the objective of a job. If not specified, the default objective metric depends on the problem type. For the list of default values per problem type, see AutoMLJobObjective. For tabular problem types: You must either provide both the AutoMLJobObjective and indicate the type of supervised learning problem in AutoMLProblemTypeConfig (TabularJobConfig.ProblemType), or none at all. For text generation problem types (LLMs fine-tuning): Fine-tuning language models in Autopilot does not require setting the AutoMLJobObjective field. Autopilot fine-tunes LLMs without requiring multiple candidates to be trained and evaluated. Instead, using your dataset, Autopilot directly fine-tunes your target model to enhance a default objective metric, the cross-entropy loss. After fine-tuning a language model, you can evaluate the quality of its generated text using different metrics. For a list of the available metrics, see Metrics for fine-tuning LLMs in Autopilot. model_deploy_config: Specifies how to generate the endpoint name for an automatic one-click Autopilot model deployment. - data_split_config: This structure specifies how to split the data into train and validation datasets. The validation and training datasets must contain the same headers. For jobs created by calling CreateAutoMLJob, the validation dataset must be less than 2 GB in size. This attribute must not be set for the time-series forecasting problem type, as Autopilot automatically splits the input dataset into training and validation sets. + data_split_config: This structure specifies how to split the data into train and validation datasets. The validation and training datasets must contain the same headers. For jobs created by calling CreateAutoMLJob, the validation dataset must be less than 2 GB in size. This attribute must not be set for the time-series forecasting problem type, as Autopilot automatically splits the input dataset into training and validation sets. auto_ml_compute_config: Specifies the compute configuration for the AutoML job V2. session: Boto3 session. region: Region name. - + Returns: The AutoMLJobV2 resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3025,41 +2987,37 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating auto_ml_job_v2 resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "AutoMLJobName": auto_ml_job_name, - "AutoMLJobInputDataConfig": auto_ml_job_input_data_config, - "OutputDataConfig": output_data_config, - "AutoMLProblemTypeConfig": auto_ml_problem_type_config, - "RoleArn": role_arn, - "Tags": tags, - "SecurityConfig": security_config, - "AutoMLJobObjective": auto_ml_job_objective, - "ModelDeployConfig": model_deploy_config, - "DataSplitConfig": data_split_config, - "AutoMLComputeConfig": auto_ml_compute_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="AutoMLJobV2", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'AutoMLJobName': auto_ml_job_name, + 'AutoMLJobInputDataConfig': auto_ml_job_input_data_config, + 'OutputDataConfig': output_data_config, + 'AutoMLProblemTypeConfig': auto_ml_problem_type_config, + 'RoleArn': role_arn, + 'Tags': tags, + 'SecurityConfig': security_config, + 'AutoMLJobObjective': auto_ml_job_objective, + 'ModelDeployConfig': model_deploy_config, + 'DataSplitConfig': data_split_config, + 'AutoMLComputeConfig': auto_ml_compute_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='AutoMLJobV2', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_auto_ml_job_v2(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(auto_ml_job_name=auto_ml_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -3070,17 +3028,17 @@ def get( ) -> Optional["AutoMLJobV2"]: """ Get a AutoMLJobV2 resource - + Parameters: auto_ml_job_name: Requests information about an AutoML job V2 using its unique name. session: Boto3 session. region: Region name. - + Returns: The AutoMLJobV2 resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3091,38 +3049,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "AutoMLJobName": auto_ml_job_name, + 'AutoMLJobName': auto_ml_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_auto_ml_job_v2(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeAutoMLJobV2Response") + transformed_response = transform(response, 'DescribeAutoMLJobV2Response') auto_ml_job_v2 = cls(**transformed_response) return auto_ml_job_v2 - + @Base.add_validate_call def refresh( self, - ) -> Optional["AutoMLJobV2"]: + + ) -> Optional["AutoMLJobV2"]: """ Refresh a AutoMLJobV2 resource - + Returns: The AutoMLJobV2 resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3133,76 +3090,74 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "AutoMLJobName": self.auto_ml_job_name, + 'AutoMLJobName': self.auto_ml_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_auto_ml_job_v2(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeAutoMLJobV2Response", self) + transform(response, 'DescribeAutoMLJobV2Response', self) return self - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a AutoMLJobV2 resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed", "Stopped"] + terminal_states = ['Completed', 'Failed', 'Stopped'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for AutoMLJobV2...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.auto_ml_job_status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="AutoMLJobV2", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="AutoMLJobV2", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="AutoMLJobV2", status=current_status) time.sleep(poll) @@ -3211,7 +3166,7 @@ def wait( class Cluster(Base): """ Class representing resource Cluster - + Attributes: cluster_arn: The Amazon Resource Name (ARN) of the SageMaker HyperPod cluster. cluster_status: The status of the SageMaker HyperPod cluster. @@ -3220,59 +3175,62 @@ class Cluster(Base): creation_time: The time when the SageMaker Cluster is created. failure_message: The failure message of the SageMaker HyperPod cluster. restricted_instance_groups: The specialized instance groups for training models like Amazon Nova to be created in the SageMaker HyperPod cluster. - vpc_config: - orchestrator: The type of orchestrator used for the SageMaker HyperPod cluster. + vpc_config: + orchestrator: The type of orchestrator used for the SageMaker HyperPod cluster. node_recovery: The node recovery mode configured for the SageMaker HyperPod cluster. - + """ - cluster_name: str cluster_arn: Optional[str] = Unassigned() cluster_status: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() failure_message: Optional[str] = Unassigned() instance_groups: Optional[List[shapes.ClusterInstanceGroupDetails]] = Unassigned() - restricted_instance_groups: Optional[List[shapes.ClusterRestrictedInstanceGroupDetails]] = ( - Unassigned() - ) + restricted_instance_groups: Optional[List[shapes.ClusterRestrictedInstanceGroupDetails]] = Unassigned() vpc_config: Optional[shapes.VpcConfig] = Unassigned() orchestrator: Optional[shapes.ClusterOrchestrator] = Unassigned() node_recovery: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "cluster_name" - resource_name_split = resource_name.split("_") + resource_name = 'cluster_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object cluster") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - } + config_schema_for_resource = \ + { + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Cluster", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Cluster", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -3280,9 +3238,7 @@ def create( cls, cluster_name: str, instance_groups: Optional[List[shapes.ClusterInstanceGroupSpecification]] = Unassigned(), - restricted_instance_groups: Optional[ - List[shapes.ClusterRestrictedInstanceGroupSpecification] - ] = Unassigned(), + restricted_instance_groups: Optional[List[shapes.ClusterRestrictedInstanceGroupSpecification]] = Unassigned(), vpc_config: Optional[shapes.VpcConfig] = Unassigned(), tags: Optional[List[shapes.Tag]] = Unassigned(), orchestrator: Optional[shapes.ClusterOrchestrator] = Unassigned(), @@ -3292,23 +3248,23 @@ def create( ) -> Optional["Cluster"]: """ Create a Cluster resource - + Parameters: cluster_name: The name for the new SageMaker HyperPod cluster. instance_groups: The instance groups to be created in the SageMaker HyperPod cluster. restricted_instance_groups: The specialized instance groups for training models like Amazon Nova to be created in the SageMaker HyperPod cluster. - vpc_config: Specifies the Amazon Virtual Private Cloud (VPC) that is associated with the Amazon SageMaker HyperPod cluster. You can control access to and from your resources by configuring your VPC. For more information, see Give SageMaker access to resources in your Amazon VPC. When your Amazon VPC and subnets support IPv6, network communications differ based on the cluster orchestration platform: Slurm-orchestrated clusters automatically configure nodes with dual IPv6 and IPv4 addresses, allowing immediate IPv6 network communications. In Amazon EKS-orchestrated clusters, nodes receive dual-stack addressing, but pods can only use IPv6 when the Amazon EKS cluster is explicitly IPv6-enabled. For information about deploying an IPv6 Amazon EKS cluster, see Amazon EKS IPv6 Cluster Deployment. Additional resources for IPv6 configuration: For information about adding IPv6 support to your VPC, see to IPv6 Support for VPC. For information about creating a new IPv6-compatible VPC, see Amazon VPC Creation Guide. To configure SageMaker HyperPod with a custom Amazon VPC, see Custom Amazon VPC Setup for SageMaker HyperPod. + vpc_config: Specifies the Amazon Virtual Private Cloud (VPC) that is associated with the Amazon SageMaker HyperPod cluster. You can control access to and from your resources by configuring your VPC. For more information, see Give SageMaker access to resources in your Amazon VPC. When your Amazon VPC and subnets support IPv6, network communications differ based on the cluster orchestration platform: Slurm-orchestrated clusters automatically configure nodes with dual IPv6 and IPv4 addresses, allowing immediate IPv6 network communications. In Amazon EKS-orchestrated clusters, nodes receive dual-stack addressing, but pods can only use IPv6 when the Amazon EKS cluster is explicitly IPv6-enabled. For information about deploying an IPv6 Amazon EKS cluster, see Amazon EKS IPv6 Cluster Deployment. Additional resources for IPv6 configuration: For information about adding IPv6 support to your VPC, see to IPv6 Support for VPC. For information about creating a new IPv6-compatible VPC, see Amazon VPC Creation Guide. To configure SageMaker HyperPod with a custom Amazon VPC, see Custom Amazon VPC Setup for SageMaker HyperPod. tags: Custom tags for managing the SageMaker HyperPod cluster as an Amazon Web Services resource. You can add tags to your cluster in the same way you add them in other Amazon Web Services services that support tagging. To learn more about tagging Amazon Web Services resources in general, see Tagging Amazon Web Services Resources User Guide. orchestrator: The type of orchestrator to use for the SageMaker HyperPod cluster. Currently, the only supported value is "eks", which is to use an Amazon Elastic Kubernetes Service (EKS) cluster as the orchestrator. node_recovery: The node recovery mode for the SageMaker HyperPod cluster. When set to Automatic, SageMaker HyperPod will automatically reboot or replace faulty nodes when issues are detected. When set to None, cluster administrators will need to manually manage any faulty cluster instances. session: Boto3 session. region: Region name. - + Returns: The Cluster resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3323,37 +3279,33 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating cluster resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ClusterName": cluster_name, - "InstanceGroups": instance_groups, - "RestrictedInstanceGroups": restricted_instance_groups, - "VpcConfig": vpc_config, - "Tags": tags, - "Orchestrator": orchestrator, - "NodeRecovery": node_recovery, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Cluster", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ClusterName': cluster_name, + 'InstanceGroups': instance_groups, + 'RestrictedInstanceGroups': restricted_instance_groups, + 'VpcConfig': vpc_config, + 'Tags': tags, + 'Orchestrator': orchestrator, + 'NodeRecovery': node_recovery, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Cluster', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_cluster(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(cluster_name=cluster_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -3364,17 +3316,17 @@ def get( ) -> Optional["Cluster"]: """ Get a Cluster resource - + Parameters: cluster_name: The string name or the Amazon Resource Name (ARN) of the SageMaker HyperPod cluster. session: Boto3 session. region: Region name. - + Returns: The Cluster resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3385,38 +3337,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ClusterName": cluster_name, + 'ClusterName': cluster_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_cluster(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeClusterResponse") + transformed_response = transform(response, 'DescribeClusterResponse') cluster = cls(**transformed_response) return cluster - + @Base.add_validate_call def refresh( self, - ) -> Optional["Cluster"]: + + ) -> Optional["Cluster"]: """ Refresh a Cluster resource - + Returns: The Cluster resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3427,43 +3378,41 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ClusterName": self.cluster_name, + 'ClusterName': self.cluster_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_cluster(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeClusterResponse", self) + transform(response, 'DescribeClusterResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( self, instance_groups: Optional[List[shapes.ClusterInstanceGroupSpecification]] = Unassigned(), - restricted_instance_groups: Optional[ - List[shapes.ClusterRestrictedInstanceGroupSpecification] - ] = Unassigned(), + restricted_instance_groups: Optional[List[shapes.ClusterRestrictedInstanceGroupSpecification]] = Unassigned(), node_recovery: Optional[str] = Unassigned(), instance_groups_to_delete: Optional[List[str]] = Unassigned(), ) -> Optional["Cluster"]: """ Update a Cluster resource - + Parameters: instance_groups_to_delete: Specify the names of the instance groups to delete. Use a single , as the separator between multiple names. - + Returns: The Cluster resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3476,38 +3425,39 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating cluster resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ClusterName": self.cluster_name, - "InstanceGroups": instance_groups, - "RestrictedInstanceGroups": restricted_instance_groups, - "NodeRecovery": node_recovery, - "InstanceGroupsToDelete": instance_groups_to_delete, + 'ClusterName': self.cluster_name, + 'InstanceGroups': instance_groups, + 'RestrictedInstanceGroups': restricted_instance_groups, + 'NodeRecovery': node_recovery, + 'InstanceGroupsToDelete': instance_groups_to_delete, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_cluster(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Cluster resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3519,84 +3469,74 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ClusterName": self.cluster_name, + 'ClusterName': self.cluster_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_cluster(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Creating", - "Deleting", - "Failed", - "InService", - "RollingBack", - "SystemUpdating", - "Updating", - ], + target_status: Literal['Creating', 'Deleting', 'Failed', 'InService', 'RollingBack', 'SystemUpdating', 'Updating'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Cluster resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Cluster to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.cluster_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Cluster", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="Cluster", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Cluster", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -3605,13 +3545,13 @@ def wait_for_delete( ) -> None: """ Wait for a Cluster resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3625,39 +3565,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Cluster to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.cluster_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Cluster", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -3673,7 +3608,7 @@ def get_all( ) -> ResourceIterator["Cluster"]: """ Get all Cluster resources - + Parameters: creation_time_after: Set a start time for the time range during which you want to list SageMaker HyperPod clusters. Timestamps are formatted according to the ISO 8601 standard. Acceptable formats include: YYYY-MM-DDThh:mm:ss.sssTZD (UTC), for example, 2014-10-01T20:30:00.000Z YYYY-MM-DDThh:mm:ss.sssTZD (with offset), for example, 2014-10-01T12:30:00.000-08:00 YYYY-MM-DD, for example, 2014-10-01 Unix time in seconds, for example, 1412195400. This is also referred to as Unix Epoch time and represents the number of seconds since midnight, January 1, 1970 UTC. For more information about the timestamp format, see Timestamp in the Amazon Web Services Command Line Interface User Guide. creation_time_before: Set an end time for the time range during which you want to list SageMaker HyperPod clusters. A filter that returns nodes in a SageMaker HyperPod cluster created before the specified time. The acceptable formats are the same as the timestamp formats for CreationTimeAfter. For more information about the timestamp format, see Timestamp in the Amazon Web Services Command Line Interface User Guide. @@ -3685,12 +3620,12 @@ def get_all( training_plan_arn: The Amazon Resource Name (ARN); of the training plan to filter clusters by. For more information about reserving GPU capacity for your SageMaker HyperPod clusters using Amazon SageMaker Training Plan, see CreateTrainingPlan . session: Boto3 session. region: Region name. - + Returns: Iterator for listed Cluster resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3700,33 +3635,33 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, - "TrainingPlanArn": training_plan_arn, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'TrainingPlanArn': training_plan_arn, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_clusters", - summaries_key="ClusterSummaries", - summary_name="ClusterSummary", + list_method='list_clusters', + summaries_key='ClusterSummaries', + summary_name='ClusterSummary', resource_cls=Cluster, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_node( self, @@ -3736,17 +3671,17 @@ def get_node( ) -> Optional[shapes.ClusterNodeDetails]: """ Retrieves information of a node (also called a instance interchangeably) of a SageMaker HyperPod cluster. - + Parameters: node_id: The ID of the SageMaker HyperPod cluster node. session: Boto3 session. region: Region name. - + Returns: shapes.ClusterNodeDetails - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3757,26 +3692,26 @@ def get_node( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "ClusterName": self.cluster_name, - "NodeId": node_id, + 'ClusterName': self.cluster_name, + 'NodeId': node_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling describe_cluster_node API") response = client.describe_cluster_node(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "DescribeClusterNodeResponse") + + transformed_response = transform(response, 'DescribeClusterNodeResponse') return shapes.ClusterNodeDetails(**transformed_response) - + + @Base.add_validate_call def get_all_nodes( self, @@ -3784,13 +3719,12 @@ def get_all_nodes( creation_time_before: Optional[datetime.datetime] = Unassigned(), instance_group_name_contains: Optional[str] = Unassigned(), sort_by: Optional[str] = Unassigned(), - sort_order: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_order: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.ClusterNodeDetails]: """ Retrieves the list of instances (also called nodes interchangeably) in a SageMaker HyperPod cluster. - + Parameters: creation_time_after: A filter that returns nodes in a SageMaker HyperPod cluster created after the specified time. Timestamps are formatted according to the ISO 8601 standard. Acceptable formats include: YYYY-MM-DDThh:mm:ss.sssTZD (UTC), for example, 2014-10-01T20:30:00.000Z YYYY-MM-DDThh:mm:ss.sssTZD (with offset), for example, 2014-10-01T12:30:00.000-08:00 YYYY-MM-DD, for example, 2014-10-01 Unix time in seconds, for example, 1412195400. This is also referred to as Unix Epoch time and represents the number of seconds since midnight, January 1, 1970 UTC. For more information about the timestamp format, see Timestamp in the Amazon Web Services Command Line Interface User Guide. creation_time_before: A filter that returns nodes in a SageMaker HyperPod cluster created before the specified time. The acceptable formats are the same as the timestamp formats for CreationTimeAfter. For more information about the timestamp format, see Timestamp in the Amazon Web Services Command Line Interface User Guide. @@ -3801,12 +3735,12 @@ def get_all_nodes( sort_order: The sort order for results. The default value is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ClusterNodeDetails. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3817,32 +3751,33 @@ def get_all_nodes( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "ClusterName": self.cluster_name, - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "InstanceGroupNameContains": instance_group_name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'ClusterName': self.cluster_name, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'InstanceGroupNameContains': instance_group_name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_cluster_nodes", - summaries_key="ClusterNodeSummaries", - summary_name="ClusterNodeSummary", + list_method='list_cluster_nodes', + summaries_key='ClusterNodeSummaries', + summary_name='ClusterNodeSummary', resource_cls=shapes.ClusterNodeDetails, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def update_software( self, @@ -3852,14 +3787,14 @@ def update_software( ) -> None: """ Updates the platform software of a SageMaker HyperPod cluster for security patching. - + Parameters: deployment_config: The configuration to use when updating the AMI versions. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3871,24 +3806,25 @@ def update_software( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "ClusterName": self.cluster_name, - "InstanceGroups": self.instance_groups, - "DeploymentConfig": deployment_config, + 'ClusterName': self.cluster_name, + 'InstanceGroups': self.instance_groups, + 'DeploymentConfig': deployment_config, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling update_cluster_software API") response = client.update_cluster_software(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def batch_delete_nodes( self, @@ -3898,17 +3834,17 @@ def batch_delete_nodes( ) -> Optional[shapes.BatchDeleteClusterNodesResponse]: """ Deletes specific nodes within a SageMaker HyperPod cluster. - + Parameters: - node_ids: A list of node IDs to be deleted from the specified cluster. For SageMaker HyperPod clusters using the Slurm workload manager, you cannot remove instances that are configured as Slurm controller nodes. If you need to delete more than 99 instances, contact Support for assistance. + node_ids: A list of node IDs to be deleted from the specified cluster. For SageMaker HyperPod clusters using the Slurm workload manager, you cannot remove instances that are configured as Slurm controller nodes. If you need to delete more than 99 instances, contact Support for assistance. session: Boto3 session. region: Region name. - + Returns: shapes.BatchDeleteClusterNodesResponse - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -3919,31 +3855,30 @@ def batch_delete_nodes( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "ClusterName": self.cluster_name, - "NodeIds": node_ids, + 'ClusterName': self.cluster_name, + 'NodeIds': node_ids, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling batch_delete_cluster_nodes API") response = client.batch_delete_cluster_nodes(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "BatchDeleteClusterNodesResponse") + + transformed_response = transform(response, 'BatchDeleteClusterNodesResponse') return shapes.BatchDeleteClusterNodesResponse(**transformed_response) class ClusterSchedulerConfig(Base): """ Class representing resource ClusterSchedulerConfig - + Attributes: cluster_scheduler_config_arn: ARN of the cluster policy. cluster_scheduler_config_id: ID of the cluster policy. @@ -3955,12 +3890,11 @@ class ClusterSchedulerConfig(Base): cluster_arn: ARN of the cluster where the cluster policy is applied. scheduler_config: Cluster policy configuration. This policy is used for task prioritization and fair-share allocation. This helps prioritize critical workloads and distributes idle compute across entities. description: Description of the cluster policy. - created_by: + created_by: last_modified_time: Last modified time of the cluster policy. - last_modified_by: - + last_modified_by: + """ - cluster_scheduler_config_id: str cluster_scheduler_config_arn: Optional[str] = Unassigned() name: Optional[str] = Unassigned() @@ -3974,23 +3908,23 @@ class ClusterSchedulerConfig(Base): created_by: Optional[shapes.UserContext] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "cluster_scheduler_config_name" - resource_name_split = resource_name.split("_") + resource_name = 'cluster_scheduler_config_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object cluster_scheduler_config") return None - + @classmethod @Base.add_validate_call def create( @@ -4005,7 +3939,7 @@ def create( ) -> Optional["ClusterSchedulerConfig"]: """ Create a ClusterSchedulerConfig resource - + Parameters: name: Name for the cluster policy. cluster_arn: ARN of the cluster. @@ -4014,12 +3948,12 @@ def create( tags: Tags of the cluster policy. session: Boto3 session. region: Region name. - + Returns: The ClusterSchedulerConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4034,39 +3968,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating cluster_scheduler_config resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "Name": name, - "ClusterArn": cluster_arn, - "SchedulerConfig": scheduler_config, - "Description": description, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ClusterSchedulerConfig", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'Name': name, + 'ClusterArn': cluster_arn, + 'SchedulerConfig': scheduler_config, + 'Description': description, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ClusterSchedulerConfig', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_cluster_scheduler_config(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - cluster_scheduler_config_id=response["ClusterSchedulerConfigId"], - session=session, - region=region, - ) - + + return cls.get(cluster_scheduler_config_id=response['ClusterSchedulerConfigId'], session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -4078,18 +4004,18 @@ def get( ) -> Optional["ClusterSchedulerConfig"]: """ Get a ClusterSchedulerConfig resource - + Parameters: cluster_scheduler_config_id: ID of the cluster policy. cluster_scheduler_config_version: Version of the cluster policy. session: Boto3 session. region: Region name. - + Returns: The ClusterSchedulerConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4100,39 +4026,38 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ClusterSchedulerConfigId": cluster_scheduler_config_id, - "ClusterSchedulerConfigVersion": cluster_scheduler_config_version, + 'ClusterSchedulerConfigId': cluster_scheduler_config_id, + 'ClusterSchedulerConfigVersion': cluster_scheduler_config_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_cluster_scheduler_config(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeClusterSchedulerConfigResponse") + transformed_response = transform(response, 'DescribeClusterSchedulerConfigResponse') cluster_scheduler_config = cls(**transformed_response) return cluster_scheduler_config - + @Base.add_validate_call def refresh( self, - ) -> Optional["ClusterSchedulerConfig"]: + + ) -> Optional["ClusterSchedulerConfig"]: """ Refresh a ClusterSchedulerConfig resource - + Returns: The ClusterSchedulerConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4143,22 +4068,22 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ClusterSchedulerConfigId": self.cluster_scheduler_config_id, - "ClusterSchedulerConfigVersion": self.cluster_scheduler_config_version, + 'ClusterSchedulerConfigId': self.cluster_scheduler_config_id, + 'ClusterSchedulerConfigVersion': self.cluster_scheduler_config_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_cluster_scheduler_config(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeClusterSchedulerConfigResponse", self) + transform(response, 'DescribeClusterSchedulerConfigResponse', self) return self - + @Base.add_validate_call def update( self, @@ -4168,15 +4093,15 @@ def update( ) -> Optional["ClusterSchedulerConfig"]: """ Update a ClusterSchedulerConfig resource - + Parameters: target_version: Target version. - + Returns: The ClusterSchedulerConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4189,37 +4114,38 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating cluster_scheduler_config resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ClusterSchedulerConfigId": self.cluster_scheduler_config_id, - "TargetVersion": target_version, - "SchedulerConfig": scheduler_config, - "Description": description, + 'ClusterSchedulerConfigId': self.cluster_scheduler_config_id, + 'TargetVersion': target_version, + 'SchedulerConfig': scheduler_config, + 'Description': description, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_cluster_scheduler_config(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ClusterSchedulerConfig resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4230,95 +4156,74 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ClusterSchedulerConfigId": self.cluster_scheduler_config_id, + 'ClusterSchedulerConfigId': self.cluster_scheduler_config_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_cluster_scheduler_config(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Creating", - "CreateFailed", - "CreateRollbackFailed", - "Created", - "Updating", - "UpdateFailed", - "UpdateRollbackFailed", - "Updated", - "Deleting", - "DeleteFailed", - "DeleteRollbackFailed", - "Deleted", - ], + target_status: Literal['Creating', 'CreateFailed', 'CreateRollbackFailed', 'Created', 'Updating', 'UpdateFailed', 'UpdateRollbackFailed', 'Updated', 'Deleting', 'DeleteFailed', 'DeleteRollbackFailed', 'Deleted'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a ClusterSchedulerConfig resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) - progress.add_task( - f"Waiting for ClusterSchedulerConfig to reach [bold]{target_status} status..." - ) + progress.add_task(f"Waiting for ClusterSchedulerConfig to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="ClusterSchedulerConfig", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="ClusterSchedulerConfig", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ClusterSchedulerConfig", status=current_status - ) + raise TimeoutExceededError(resouce_type="ClusterSchedulerConfig", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -4327,13 +4232,13 @@ def wait_for_delete( ) -> None: """ Wait for a ClusterSchedulerConfig resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4347,45 +4252,38 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for ClusterSchedulerConfig to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + + if current_status.lower() == "deleted": print("Resource was deleted.") return - + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ClusterSchedulerConfig", status=current_status - ) + raise TimeoutExceededError(resouce_type="ClusterSchedulerConfig", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -4402,7 +4300,7 @@ def get_all( ) -> ResourceIterator["ClusterSchedulerConfig"]: """ Get all ClusterSchedulerConfig resources - + Parameters: created_after: Filter for after this creation time. The input for this parameter is a Unix timestamp. To convert a date and time into a Unix timestamp, see EpochConverter. created_before: Filter for before this creation time. The input for this parameter is a Unix timestamp. To convert a date and time into a Unix timestamp, see EpochConverter. @@ -4415,12 +4313,12 @@ def get_all( max_results: The maximum number of cluster policies to list. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ClusterSchedulerConfig resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4430,70 +4328,68 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "NameContains": name_contains, - "ClusterArn": cluster_arn, - "Status": status, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'NameContains': name_contains, + 'ClusterArn': cluster_arn, + 'Status': status, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_cluster_scheduler_configs", - summaries_key="ClusterSchedulerConfigSummaries", - summary_name="ClusterSchedulerConfigSummary", + list_method='list_cluster_scheduler_configs', + summaries_key='ClusterSchedulerConfigSummaries', + summary_name='ClusterSchedulerConfigSummary', resource_cls=ClusterSchedulerConfig, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class CodeRepository(Base): """ Class representing resource CodeRepository - + Attributes: code_repository_name: The name of the Git repository. code_repository_arn: The Amazon Resource Name (ARN) of the Git repository. creation_time: The date and time that the repository was created. last_modified_time: The date and time that the repository was last changed. git_config: Configuration details about the repository, including the URL where the repository is located, the default branch, and the Amazon Resource Name (ARN) of the Amazon Web Services Secrets Manager secret that contains the credentials used to access the repository. - + """ - code_repository_name: str code_repository_arn: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() git_config: Optional[shapes.GitConfig] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "code_repository_name" - resource_name_split = resource_name.split("_") + resource_name = 'code_repository_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object code_repository") return None - + @classmethod @Base.add_validate_call def create( @@ -4506,19 +4402,19 @@ def create( ) -> Optional["CodeRepository"]: """ Create a CodeRepository resource - + Parameters: code_repository_name: The name of the Git repository. The name must have 1 to 63 characters. Valid characters are a-z, A-Z, 0-9, and - (hyphen). git_config: Specifies details about the repository, including the URL where the repository is located, the default branch, and credentials to use to access the repository. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. session: Boto3 session. region: Region name. - + Returns: The CodeRepository resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4531,33 +4427,29 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating code_repository resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "CodeRepositoryName": code_repository_name, - "GitConfig": git_config, - "Tags": tags, + 'CodeRepositoryName': code_repository_name, + 'GitConfig': git_config, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="CodeRepository", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='CodeRepository', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_code_repository(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(code_repository_name=code_repository_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -4568,17 +4460,17 @@ def get( ) -> Optional["CodeRepository"]: """ Get a CodeRepository resource - + Parameters: code_repository_name: The name of the Git repository to describe. session: Boto3 session. region: Region name. - + Returns: The CodeRepository resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4588,38 +4480,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "CodeRepositoryName": code_repository_name, + 'CodeRepositoryName': code_repository_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_code_repository(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeCodeRepositoryOutput") + transformed_response = transform(response, 'DescribeCodeRepositoryOutput') code_repository = cls(**transformed_response) return code_repository - + @Base.add_validate_call def refresh( self, - ) -> Optional["CodeRepository"]: + + ) -> Optional["CodeRepository"]: """ Refresh a CodeRepository resource - + Returns: The CodeRepository resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4629,21 +4520,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "CodeRepositoryName": self.code_repository_name, + 'CodeRepositoryName': self.code_repository_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_code_repository(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeCodeRepositoryOutput", self) + transform(response, 'DescribeCodeRepositoryOutput', self) return self - + @Base.add_validate_call def update( self, @@ -4651,12 +4542,12 @@ def update( ) -> Optional["CodeRepository"]: """ Update a CodeRepository resource - + Returns: The CodeRepository resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4667,35 +4558,36 @@ def update( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + logger.info("Updating code_repository resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "CodeRepositoryName": self.code_repository_name, - "GitConfig": git_config, + 'CodeRepositoryName': self.code_repository_name, + 'GitConfig': git_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_code_repository(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a CodeRepository resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4705,20 +4597,20 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "CodeRepositoryName": self.code_repository_name, + 'CodeRepositoryName': self.code_repository_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_code_repository(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -4729,13 +4621,12 @@ def get_all( last_modified_time_before: Optional[datetime.datetime] = Unassigned(), name_contains: Optional[str] = Unassigned(), sort_by: Optional[str] = Unassigned(), - sort_order: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_order: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator["CodeRepository"]: """ Gets a list of the Git repositories in your account. - + Parameters: creation_time_after: A filter that returns only Git repositories that were created after the specified time. creation_time_before: A filter that returns only Git repositories that were created before the specified time. @@ -4748,12 +4639,12 @@ def get_all( sort_order: The sort order for results. The default is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed CodeRepository. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4763,38 +4654,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_code_repositories", - summaries_key="CodeRepositorySummaryList", - summary_name="CodeRepositorySummary", + list_method='list_code_repositories', + summaries_key='CodeRepositorySummaryList', + summary_name='CodeRepositorySummary', resource_cls=CodeRepository, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class CompilationJob(Base): """ Class representing resource CompilationJob - + Attributes: compilation_job_name: The name of the model compilation job. compilation_job_arn: The Amazon Resource Name (ARN) of the model compilation job. @@ -4802,21 +4693,20 @@ class CompilationJob(Base): stopping_condition: Specifies a limit to how long a model compilation job can run. When the job reaches the time limit, Amazon SageMaker AI ends the compilation job. Use this API to cap model training costs. creation_time: The time that the model compilation job was created. last_modified_time: The time that the status of the model compilation job was last modified. - failure_reason: If a model compilation job failed, the reason it failed. + failure_reason: If a model compilation job failed, the reason it failed. model_artifacts: Information about the location in Amazon S3 that has been configured for storing the model artifacts used in the compilation job. role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI assumes to perform the model compilation job. input_config: Information about the location in Amazon S3 of the input model artifacts, the name and shape of the expected data inputs, and the framework in which the model was trained. output_config: Information about the output location for the compiled model and the target device that the model runs on. - compilation_start_time: The time when the model compilation job started the CompilationJob instances. You are billed for the time between this timestamp and the timestamp in the CompilationEndTime field. In Amazon CloudWatch Logs, the start time might be later than this time. That's because it takes time to download the compilation job, which depends on the size of the compilation job container. - compilation_end_time: The time when the model compilation job on a compilation job instance ended. For a successful or stopped job, this is when the job's model artifacts have finished uploading. For a failed job, this is when Amazon SageMaker AI detected that the job failed. + compilation_start_time: The time when the model compilation job started the CompilationJob instances. You are billed for the time between this timestamp and the timestamp in the CompilationEndTime field. In Amazon CloudWatch Logs, the start time might be later than this time. That's because it takes time to download the compilation job, which depends on the size of the compilation job container. + compilation_end_time: The time when the model compilation job on a compilation job instance ended. For a successful or stopped job, this is when the job's model artifacts have finished uploading. For a failed job, this is when Amazon SageMaker AI detected that the job failed. inference_image: The inference image to use when compiling a model. Specify an image only if the target device is a cloud instance. model_package_version_arn: The Amazon Resource Name (ARN) of the versioned model package that was provided to SageMaker Neo when you initiated a compilation job. model_digests: Provides a BLAKE2 hash value that identifies the compiled model artifacts in Amazon S3. vpc_config: A VpcConfig object that specifies the VPC that you want your compilation job to connect to. Control access to your models by configuring the VPC. For more information, see Protect Compilation Jobs by Using an Amazon Virtual Private Cloud. derived_information: Information that SageMaker Neo automatically derived about the model. - + """ - compilation_job_name: str compilation_job_arn: Optional[str] = Unassigned() compilation_job_status: Optional[str] = Unassigned() @@ -4835,48 +4725,68 @@ class CompilationJob(Base): output_config: Optional[shapes.OutputConfig] = Unassigned() vpc_config: Optional[shapes.NeoVpcConfig] = Unassigned() derived_information: Optional[shapes.DerivedInformation] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "compilation_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'compilation_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object compilation_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "model_artifacts": {"s3_model_artifacts": {"type": "string"}}, - "role_arn": {"type": "string"}, - "input_config": {"s3_uri": {"type": "string"}}, - "output_config": { - "s3_output_location": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, + config_schema_for_resource = \ + { + "model_artifacts": { + "s3_model_artifacts": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "CompilationJob", **kwargs - ), - ) - + }, + "role_arn": { + "type": "string" + }, + "input_config": { + "s3_uri": { + "type": "string" + } + }, + "output_config": { + "s3_output_location": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "CompilationJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -4895,10 +4805,10 @@ def create( ) -> Optional["CompilationJob"]: """ Create a CompilationJob resource - + Parameters: - compilation_job_name: A name for the model compilation job. The name must be unique within the Amazon Web Services Region and within your Amazon Web Services account. - role_arn: The Amazon Resource Name (ARN) of an IAM role that enables Amazon SageMaker AI to perform tasks on your behalf. During model compilation, Amazon SageMaker AI needs your permission to: Read input data from an S3 bucket Write model artifacts to an S3 bucket Write logs to Amazon CloudWatch Logs Publish metrics to Amazon CloudWatch You grant permissions for all of these tasks to an IAM role. To pass this role to Amazon SageMaker AI, the caller of this API must have the iam:PassRole permission. For more information, see Amazon SageMaker AI Roles. + compilation_job_name: A name for the model compilation job. The name must be unique within the Amazon Web Services Region and within your Amazon Web Services account. + role_arn: The Amazon Resource Name (ARN) of an IAM role that enables Amazon SageMaker AI to perform tasks on your behalf. During model compilation, Amazon SageMaker AI needs your permission to: Read input data from an S3 bucket Write model artifacts to an S3 bucket Write logs to Amazon CloudWatch Logs Publish metrics to Amazon CloudWatch You grant permissions for all of these tasks to an IAM role. To pass this role to Amazon SageMaker AI, the caller of this API must have the iam:PassRole permission. For more information, see Amazon SageMaker AI Roles. output_config: Provides information about the output location for the compiled model and the target device the model runs on. stopping_condition: Specifies a limit to how long a model compilation job can run. When the job reaches the time limit, Amazon SageMaker AI ends the compilation job. Use this API to cap model training costs. model_package_version_arn: The Amazon Resource Name (ARN) of a versioned model package. Provide either a ModelPackageVersionArn or an InputConfig object in the request syntax. The presence of both objects in the CreateCompilationJob request will return an exception. @@ -4907,12 +4817,12 @@ def create( tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. session: Boto3 session. region: Region name. - + Returns: The CompilationJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4927,38 +4837,34 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating compilation_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "CompilationJobName": compilation_job_name, - "RoleArn": role_arn, - "ModelPackageVersionArn": model_package_version_arn, - "InputConfig": input_config, - "OutputConfig": output_config, - "VpcConfig": vpc_config, - "StoppingCondition": stopping_condition, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="CompilationJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'CompilationJobName': compilation_job_name, + 'RoleArn': role_arn, + 'ModelPackageVersionArn': model_package_version_arn, + 'InputConfig': input_config, + 'OutputConfig': output_config, + 'VpcConfig': vpc_config, + 'StoppingCondition': stopping_condition, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='CompilationJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_compilation_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(compilation_job_name=compilation_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -4969,17 +4875,17 @@ def get( ) -> Optional["CompilationJob"]: """ Get a CompilationJob resource - + Parameters: compilation_job_name: The name of the model compilation job that you want information about. session: Boto3 session. region: Region name. - + Returns: The CompilationJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -4990,38 +4896,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "CompilationJobName": compilation_job_name, + 'CompilationJobName': compilation_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_compilation_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeCompilationJobResponse") + transformed_response = transform(response, 'DescribeCompilationJobResponse') compilation_job = cls(**transformed_response) return compilation_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["CompilationJob"]: + + ) -> Optional["CompilationJob"]: """ Refresh a CompilationJob resource - + Returns: The CompilationJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5032,30 +4937,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "CompilationJobName": self.compilation_job_name, + 'CompilationJobName': self.compilation_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_compilation_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeCompilationJobResponse", self) + transform(response, 'DescribeCompilationJobResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a CompilationJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5066,27 +4972,27 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "CompilationJobName": self.compilation_job_name, + 'CompilationJobName': self.compilation_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_compilation_job(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def stop(self) -> None: """ Stop a CompilationJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5097,79 +5003,77 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "CompilationJobName": self.compilation_job_name, + 'CompilationJobName': self.compilation_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_compilation_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a CompilationJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["COMPLETED", "FAILED", "STOPPED"] + terminal_states = ['COMPLETED', 'FAILED', 'STOPPED'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for CompilationJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.compilation_job_status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="CompilationJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="CompilationJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="CompilationJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -5187,11 +5091,11 @@ def get_all( ) -> ResourceIterator["CompilationJob"]: """ Get all CompilationJob resources - + Parameters: next_token: If the result of the previous ListCompilationJobs request was truncated, the response includes a NextToken. To retrieve the next set of model compilation jobs, use the token in the next request. max_results: The maximum number of model compilation jobs to return in the response. - creation_time_after: A filter that returns the model compilation jobs that were created after a specified time. + creation_time_after: A filter that returns the model compilation jobs that were created after a specified time. creation_time_before: A filter that returns the model compilation jobs that were created before a specified time. last_modified_time_after: A filter that returns the model compilation jobs that were modified after a specified time. last_modified_time_before: A filter that returns the model compilation jobs that were modified before a specified time. @@ -5201,12 +5105,12 @@ def get_all( sort_order: The sort order for results. The default is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed CompilationJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5216,40 +5120,39 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_compilation_jobs", - summaries_key="CompilationJobSummaries", - summary_name="CompilationJobSummary", + list_method='list_compilation_jobs', + summaries_key='CompilationJobSummaries', + summary_name='CompilationJobSummary', resource_cls=CompilationJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ComputeQuota(Base): """ Class representing resource ComputeQuota - + Attributes: compute_quota_arn: ARN of the compute allocation definition. compute_quota_id: ID of the compute allocation definition. @@ -5263,12 +5166,11 @@ class ComputeQuota(Base): cluster_arn: ARN of the cluster. compute_quota_config: Configuration of the compute allocation definition. This includes the resource sharing option, and the setting to preempt low priority tasks. activation_state: The state of the compute allocation being described. Use to enable or disable compute allocation. Default is Enabled. - created_by: + created_by: last_modified_time: Last modified time of the compute allocation configuration. - last_modified_by: - + last_modified_by: + """ - compute_quota_id: str compute_quota_arn: Optional[str] = Unassigned() name: Optional[str] = Unassigned() @@ -5284,23 +5186,23 @@ class ComputeQuota(Base): created_by: Optional[shapes.UserContext] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "compute_quota_name" - resource_name_split = resource_name.split("_") + resource_name = 'compute_quota_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object compute_quota") return None - + @classmethod @Base.add_validate_call def create( @@ -5317,7 +5219,7 @@ def create( ) -> Optional["ComputeQuota"]: """ Create a ComputeQuota resource - + Parameters: name: Name to the compute allocation definition. cluster_arn: ARN of the cluster. @@ -5328,12 +5230,12 @@ def create( tags: Tags of the compute allocation definition. session: Boto3 session. region: Region name. - + Returns: The ComputeQuota resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5348,37 +5250,33 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating compute_quota resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "Name": name, - "Description": description, - "ClusterArn": cluster_arn, - "ComputeQuotaConfig": compute_quota_config, - "ComputeQuotaTarget": compute_quota_target, - "ActivationState": activation_state, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ComputeQuota", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'Name': name, + 'Description': description, + 'ClusterArn': cluster_arn, + 'ComputeQuotaConfig': compute_quota_config, + 'ComputeQuotaTarget': compute_quota_target, + 'ActivationState': activation_state, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ComputeQuota', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_compute_quota(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get(compute_quota_id=response["ComputeQuotaId"], session=session, region=region) - + + return cls.get(compute_quota_id=response['ComputeQuotaId'], session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -5390,18 +5288,18 @@ def get( ) -> Optional["ComputeQuota"]: """ Get a ComputeQuota resource - + Parameters: compute_quota_id: ID of the compute allocation definition. compute_quota_version: Version of the compute allocation definition. session: Boto3 session. region: Region name. - + Returns: The ComputeQuota resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5412,39 +5310,38 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ComputeQuotaId": compute_quota_id, - "ComputeQuotaVersion": compute_quota_version, + 'ComputeQuotaId': compute_quota_id, + 'ComputeQuotaVersion': compute_quota_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_compute_quota(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeComputeQuotaResponse") + transformed_response = transform(response, 'DescribeComputeQuotaResponse') compute_quota = cls(**transformed_response) return compute_quota - + @Base.add_validate_call def refresh( self, - ) -> Optional["ComputeQuota"]: + + ) -> Optional["ComputeQuota"]: """ Refresh a ComputeQuota resource - + Returns: The ComputeQuota resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5455,22 +5352,22 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ComputeQuotaId": self.compute_quota_id, - "ComputeQuotaVersion": self.compute_quota_version, + 'ComputeQuotaId': self.compute_quota_id, + 'ComputeQuotaVersion': self.compute_quota_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_compute_quota(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeComputeQuotaResponse", self) + transform(response, 'DescribeComputeQuotaResponse', self) return self - + @Base.add_validate_call def update( self, @@ -5482,15 +5379,15 @@ def update( ) -> Optional["ComputeQuota"]: """ Update a ComputeQuota resource - + Parameters: target_version: Target version. - + Returns: The ComputeQuota resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5503,39 +5400,40 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating compute_quota resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ComputeQuotaId": self.compute_quota_id, - "TargetVersion": target_version, - "ComputeQuotaConfig": compute_quota_config, - "ComputeQuotaTarget": compute_quota_target, - "ActivationState": activation_state, - "Description": description, + 'ComputeQuotaId': self.compute_quota_id, + 'TargetVersion': target_version, + 'ComputeQuotaConfig': compute_quota_config, + 'ComputeQuotaTarget': compute_quota_target, + 'ActivationState': activation_state, + 'Description': description, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_compute_quota(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ComputeQuota resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5546,91 +5444,74 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ComputeQuotaId": self.compute_quota_id, + 'ComputeQuotaId': self.compute_quota_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_compute_quota(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Creating", - "CreateFailed", - "CreateRollbackFailed", - "Created", - "Updating", - "UpdateFailed", - "UpdateRollbackFailed", - "Updated", - "Deleting", - "DeleteFailed", - "DeleteRollbackFailed", - "Deleted", - ], + target_status: Literal['Creating', 'CreateFailed', 'CreateRollbackFailed', 'Created', 'Updating', 'UpdateFailed', 'UpdateRollbackFailed', 'Updated', 'Deleting', 'DeleteFailed', 'DeleteRollbackFailed', 'Deleted'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a ComputeQuota resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for ComputeQuota to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="ComputeQuota", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="ComputeQuota", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="ComputeQuota", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -5639,13 +5520,13 @@ def wait_for_delete( ) -> None: """ Wait for a ComputeQuota resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5659,45 +5540,38 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for ComputeQuota to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + + if current_status.lower() == "deleted": print("Resource was deleted.") return - + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ComputeQuota", status=current_status - ) + raise TimeoutExceededError(resouce_type="ComputeQuota", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -5714,7 +5588,7 @@ def get_all( ) -> ResourceIterator["ComputeQuota"]: """ Get all ComputeQuota resources - + Parameters: created_after: Filter for after this creation time. The input for this parameter is a Unix timestamp. To convert a date and time into a Unix timestamp, see EpochConverter. created_before: Filter for before this creation time. The input for this parameter is a Unix timestamp. To convert a date and time into a Unix timestamp, see EpochConverter. @@ -5727,12 +5601,12 @@ def get_all( max_results: The maximum number of compute allocation definitions to list. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ComputeQuota resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5742,39 +5616,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "NameContains": name_contains, - "Status": status, - "ClusterArn": cluster_arn, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'NameContains': name_contains, + 'Status': status, + 'ClusterArn': cluster_arn, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_compute_quotas", - summaries_key="ComputeQuotaSummaries", - summary_name="ComputeQuotaSummary", + list_method='list_compute_quotas', + summaries_key='ComputeQuotaSummaries', + summary_name='ComputeQuotaSummary', resource_cls=ComputeQuota, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Context(Base): """ Class representing resource Context - + Attributes: context_name: The name of the context. context_arn: The Amazon Resource Name (ARN) of the context. @@ -5783,13 +5656,12 @@ class Context(Base): description: The description of the context. properties: A list of the context's properties. creation_time: When the context was created. - created_by: + created_by: last_modified_time: When the context was last modified. - last_modified_by: + last_modified_by: lineage_group_arn: The Amazon Resource Name (ARN) of the lineage group. - + """ - context_name: str context_arn: Optional[str] = Unassigned() source: Optional[shapes.ContextSource] = Unassigned() @@ -5801,23 +5673,23 @@ class Context(Base): last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() lineage_group_arn: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "context_name" - resource_name_split = resource_name.split("_") + resource_name = 'context_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object context") return None - + @classmethod @Base.add_validate_call def create( @@ -5833,7 +5705,7 @@ def create( ) -> Optional["Context"]: """ Create a Context resource - + Parameters: context_name: The name of the context. Must be unique to your account in an Amazon Web Services Region. source: The source type, ID, and URI. @@ -5843,12 +5715,12 @@ def create( tags: A list of tags to apply to the context. session: Boto3 session. region: Region name. - + Returns: The Context resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5862,36 +5734,32 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating context resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ContextName": context_name, - "Source": source, - "ContextType": context_type, - "Description": description, - "Properties": properties, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Context", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ContextName': context_name, + 'Source': source, + 'ContextType': context_type, + 'Description': description, + 'Properties': properties, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Context', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_context(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(context_name=context_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -5902,17 +5770,17 @@ def get( ) -> Optional["Context"]: """ Get a Context resource - + Parameters: context_name: The name of the context to describe. session: Boto3 session. region: Region name. - + Returns: The Context resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5923,38 +5791,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ContextName": context_name, + 'ContextName': context_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_context(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeContextResponse") + transformed_response = transform(response, 'DescribeContextResponse') context = cls(**transformed_response) return context - + @Base.add_validate_call def refresh( self, - ) -> Optional["Context"]: + + ) -> Optional["Context"]: """ Refresh a Context resource - + Returns: The Context resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -5965,21 +5832,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ContextName": self.context_name, + 'ContextName': self.context_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_context(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeContextResponse", self) + transform(response, 'DescribeContextResponse', self) return self - + @Base.add_validate_call def update( self, @@ -5989,15 +5856,15 @@ def update( ) -> Optional["Context"]: """ Update a Context resource - + Parameters: properties_to_remove: A list of properties to remove. - + Returns: The Context resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6009,37 +5876,38 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating context resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ContextName": self.context_name, - "Description": description, - "Properties": properties, - "PropertiesToRemove": properties_to_remove, + 'ContextName': self.context_name, + 'Description': description, + 'Properties': properties, + 'PropertiesToRemove': properties_to_remove, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_context(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Context resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6050,20 +5918,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ContextName": self.context_name, + 'ContextName': self.context_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_context(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -6079,7 +5947,7 @@ def get_all( ) -> ResourceIterator["Context"]: """ Get all Context resources - + Parameters: source_uri: A filter that returns only contexts with the specified source URI. context_type: A filter that returns only contexts of the specified type. @@ -6091,12 +5959,12 @@ def get_all( max_results: The maximum number of contexts to return in the response. The default value is 10. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Context resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6107,53 +5975,51 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SourceUri": source_uri, - "ContextType": context_type, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'SourceUri': source_uri, + 'ContextType': context_type, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_contexts", - summaries_key="ContextSummaries", - summary_name="ContextSummary", + list_method='list_contexts', + summaries_key='ContextSummaries', + summary_name='ContextSummary', resource_cls=Context, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class DataQualityJobDefinition(Base): """ Class representing resource DataQualityJobDefinition - + Attributes: job_definition_arn: The Amazon Resource Name (ARN) of the data quality monitoring job definition. job_definition_name: The name of the data quality monitoring job definition. creation_time: The time that the data quality monitoring job definition was created. data_quality_app_specification: Information about the container that runs the data quality monitoring job. data_quality_job_input: The list of inputs for the data quality monitoring job. Currently endpoints are supported. - data_quality_job_output_config: - job_resources: + data_quality_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform tasks on your behalf. data_quality_baseline_config: The constraints and baselines for the data quality monitoring job definition. network_config: The networking configuration for the data quality monitoring job. - stopping_condition: - + stopping_condition: + """ - job_definition_name: str job_definition_arn: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() @@ -6165,61 +6031,97 @@ class DataQualityJobDefinition(Base): network_config: Optional[shapes.MonitoringNetworkConfig] = Unassigned() role_arn: Optional[str] = Unassigned() stopping_condition: Optional[shapes.MonitoringStoppingCondition] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "data_quality_job_definition_name" - resource_name_split = resource_name.split("_") + resource_name = 'data_quality_job_definition_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object data_quality_job_definition") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "data_quality_job_input": { - "endpoint_input": { - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - "batch_transform_input": { - "data_captured_destination_s3_uri": {"type": "string"}, - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - }, - "data_quality_job_output_config": {"kms_key_id": {"type": "string"}}, - "job_resources": {"cluster_config": {"volume_kms_key_id": {"type": "string"}}}, - "role_arn": {"type": "string"}, - "data_quality_baseline_config": { - "constraints_resource": {"s3_uri": {"type": "string"}}, - "statistics_resource": {"s3_uri": {"type": "string"}}, - }, - "network_config": { - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - } - }, + config_schema_for_resource = \ + { + "data_quality_job_input": { + "endpoint_input": { + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } + }, + "batch_transform_input": { + "data_captured_destination_s3_uri": { + "type": "string" + }, + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "DataQualityJobDefinition", **kwargs - ), - ) - + }, + "data_quality_job_output_config": { + "kms_key_id": { + "type": "string" + } + }, + "job_resources": { + "cluster_config": { + "volume_kms_key_id": { + "type": "string" + } + } + }, + "role_arn": { + "type": "string" + }, + "data_quality_baseline_config": { + "constraints_resource": { + "s3_uri": { + "type": "string" + } + }, + "statistics_resource": { + "s3_uri": { + "type": "string" + } + } + }, + "network_config": { + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "DataQualityJobDefinition", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -6240,26 +6142,26 @@ def create( ) -> Optional["DataQualityJobDefinition"]: """ Create a DataQualityJobDefinition resource - + Parameters: job_definition_name: The name for the monitoring job definition. data_quality_app_specification: Specifies the container that runs the monitoring job. data_quality_job_input: A list of inputs for the monitoring job. Currently endpoints are supported as monitoring inputs. - data_quality_job_output_config: - job_resources: + data_quality_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform tasks on your behalf. data_quality_baseline_config: Configures the constraints and baselines for the monitoring job. network_config: Specifies networking configuration for the monitoring job. - stopping_condition: + stopping_condition: tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. session: Boto3 session. region: Region name. - + Returns: The DataQualityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6274,40 +6176,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating data_quality_job_definition resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "JobDefinitionName": job_definition_name, - "DataQualityBaselineConfig": data_quality_baseline_config, - "DataQualityAppSpecification": data_quality_app_specification, - "DataQualityJobInput": data_quality_job_input, - "DataQualityJobOutputConfig": data_quality_job_output_config, - "JobResources": job_resources, - "NetworkConfig": network_config, - "RoleArn": role_arn, - "StoppingCondition": stopping_condition, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="DataQualityJobDefinition", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'JobDefinitionName': job_definition_name, + 'DataQualityBaselineConfig': data_quality_baseline_config, + 'DataQualityAppSpecification': data_quality_app_specification, + 'DataQualityJobInput': data_quality_job_input, + 'DataQualityJobOutputConfig': data_quality_job_output_config, + 'JobResources': job_resources, + 'NetworkConfig': network_config, + 'RoleArn': role_arn, + 'StoppingCondition': stopping_condition, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='DataQualityJobDefinition', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_data_quality_job_definition(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(job_definition_name=job_definition_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -6318,17 +6216,17 @@ def get( ) -> Optional["DataQualityJobDefinition"]: """ Get a DataQualityJobDefinition resource - + Parameters: job_definition_name: The name of the data quality monitoring job definition to describe. session: Boto3 session. region: Region name. - + Returns: The DataQualityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6339,38 +6237,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": job_definition_name, + 'JobDefinitionName': job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_data_quality_job_definition(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeDataQualityJobDefinitionResponse") + transformed_response = transform(response, 'DescribeDataQualityJobDefinitionResponse') data_quality_job_definition = cls(**transformed_response) return data_quality_job_definition - + @Base.add_validate_call def refresh( self, - ) -> Optional["DataQualityJobDefinition"]: + + ) -> Optional["DataQualityJobDefinition"]: """ Refresh a DataQualityJobDefinition resource - + Returns: The DataQualityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6381,30 +6278,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_data_quality_job_definition(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeDataQualityJobDefinitionResponse", self) + transform(response, 'DescribeDataQualityJobDefinitionResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a DataQualityJobDefinition resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6415,20 +6313,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_data_quality_job_definition(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -6444,7 +6342,7 @@ def get_all( ) -> ResourceIterator["DataQualityJobDefinition"]: """ Get all DataQualityJobDefinition resources - + Parameters: endpoint_name: A filter that lists the data quality job definitions associated with the specified endpoint. sort_by: The field to sort results by. The default is CreationTime. @@ -6456,12 +6354,12 @@ def get_all( creation_time_after: A filter that returns only data quality monitoring job definitions created after the specified time. session: Boto3 session. region: Region name. - + Returns: Iterator for listed DataQualityJobDefinition resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6471,43 +6369,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "EndpointName": endpoint_name, - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - } - - custom_key_mapping = { - "monitoring_job_definition_name": "job_definition_name", - "monitoring_job_definition_arn": "job_definition_arn", + 'EndpointName': endpoint_name, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, } + + custom_key_mapping = {"monitoring_job_definition_name": "job_definition_name", "monitoring_job_definition_arn": "job_definition_arn"} # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_data_quality_job_definitions", - summaries_key="JobDefinitionSummaries", - summary_name="MonitoringJobDefinitionSummary", + list_method='list_data_quality_job_definitions', + summaries_key='JobDefinitionSummaries', + summary_name='MonitoringJobDefinitionSummary', resource_cls=DataQualityJobDefinition, custom_key_mapping=custom_key_mapping, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Device(Base): """ Class representing resource Device - + Attributes: device_name: The unique identifier of the device. device_fleet_name: The name of the fleet the device belongs to. @@ -6520,9 +6413,8 @@ class Device(Base): max_models: The maximum number of models. next_token: The response from the last list when returning a list large enough to need tokening. agent_version: Edge Manager agent version. - + """ - device_name: str device_fleet_name: str device_arn: Optional[str] = Unassigned() @@ -6534,23 +6426,23 @@ class Device(Base): max_models: Optional[int] = Unassigned() next_token: Optional[str] = Unassigned() agent_version: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "device_name" - resource_name_split = resource_name.split("_") + resource_name = 'device_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object device") return None - + @classmethod @Base.add_validate_call def get( @@ -6563,19 +6455,19 @@ def get( ) -> Optional["Device"]: """ Get a Device resource - + Parameters: device_name: The unique ID of the device. device_fleet_name: The name of the fleet the devices belong to. next_token: Next token of device description. session: Boto3 session. region: Region name. - + Returns: The Device resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6586,40 +6478,39 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "NextToken": next_token, - "DeviceName": device_name, - "DeviceFleetName": device_fleet_name, + 'NextToken': next_token, + 'DeviceName': device_name, + 'DeviceFleetName': device_fleet_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_device(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeDeviceResponse") + transformed_response = transform(response, 'DescribeDeviceResponse') device = cls(**transformed_response) return device - + @Base.add_validate_call def refresh( self, - ) -> Optional["Device"]: + + ) -> Optional["Device"]: """ Refresh a Device resource - + Returns: The Device resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6630,23 +6521,23 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "NextToken": self.next_token, - "DeviceName": self.device_name, - "DeviceFleetName": self.device_fleet_name, + 'NextToken': self.next_token, + 'DeviceName': self.device_name, + 'DeviceFleetName': self.device_fleet_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_device(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeDeviceResponse", self) + transform(response, 'DescribeDeviceResponse', self) return self - + @classmethod @Base.add_validate_call def get_all( @@ -6659,7 +6550,7 @@ def get_all( ) -> ResourceIterator["Device"]: """ Get all Device resources - + Parameters: next_token: The response from the last list when returning a list large enough to need tokening. max_results: Maximum number of results to select. @@ -6668,12 +6559,12 @@ def get_all( device_fleet_name: Filter for fleets containing this name in their device fleet name. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Device resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6683,35 +6574,34 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "LatestHeartbeatAfter": latest_heartbeat_after, - "ModelName": model_name, - "DeviceFleetName": device_fleet_name, + 'LatestHeartbeatAfter': latest_heartbeat_after, + 'ModelName': model_name, + 'DeviceFleetName': device_fleet_name, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_devices", - summaries_key="DeviceSummaries", - summary_name="DeviceSummary", + list_method='list_devices', + summaries_key='DeviceSummaries', + summary_name='DeviceSummary', resource_cls=Device, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class DeviceFleet(Base): """ Class representing resource DeviceFleet - + Attributes: device_fleet_name: The name of the fleet. device_fleet_arn: The The Amazon Resource Name (ARN) of the fleet. @@ -6721,9 +6611,8 @@ class DeviceFleet(Base): description: A description of the fleet. role_arn: The Amazon Resource Name (ARN) that has access to Amazon Web Services Internet of Things (IoT). iot_role_alias: The Amazon Resource Name (ARN) alias created in Amazon Web Services Internet of Things (IoT). - + """ - device_fleet_name: str device_fleet_arn: Optional[str] = Unassigned() output_config: Optional[shapes.EdgeOutputConfig] = Unassigned() @@ -6732,43 +6621,47 @@ class DeviceFleet(Base): last_modified_time: Optional[datetime.datetime] = Unassigned() role_arn: Optional[str] = Unassigned() iot_role_alias: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "device_fleet_name" - resource_name_split = resource_name.split("_") + resource_name = 'device_fleet_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object device_fleet") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "output_config": { - "s3_output_location": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "role_arn": {"type": "string"}, - "iot_role_alias": {"type": "string"}, + config_schema_for_resource = \ + { + "output_config": { + "s3_output_location": { + "type": "string" + }, + "kms_key_id": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "DeviceFleet", **kwargs - ), - ) - + }, + "role_arn": { + "type": "string" + }, + "iot_role_alias": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "DeviceFleet", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -6785,7 +6678,7 @@ def create( ) -> Optional["DeviceFleet"]: """ Create a DeviceFleet resource - + Parameters: device_fleet_name: The name of the fleet that the device belongs to. output_config: The output configuration for storing sample data collected by the fleet. @@ -6795,12 +6688,12 @@ def create( enable_iot_role_alias: Whether to create an Amazon Web Services IoT Role Alias during device fleet creation. The name of the role alias generated will match this pattern: "SageMakerEdge-{DeviceFleetName}". For example, if your device fleet is called "demo-fleet", the name of the role alias will be "SageMakerEdge-demo-fleet". session: Boto3 session. region: Region name. - + Returns: The DeviceFleet resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6815,36 +6708,32 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating device_fleet resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "DeviceFleetName": device_fleet_name, - "RoleArn": role_arn, - "Description": description, - "OutputConfig": output_config, - "Tags": tags, - "EnableIotRoleAlias": enable_iot_role_alias, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="DeviceFleet", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'DeviceFleetName': device_fleet_name, + 'RoleArn': role_arn, + 'Description': description, + 'OutputConfig': output_config, + 'Tags': tags, + 'EnableIotRoleAlias': enable_iot_role_alias, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='DeviceFleet', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_device_fleet(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(device_fleet_name=device_fleet_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -6855,17 +6744,17 @@ def get( ) -> Optional["DeviceFleet"]: """ Get a DeviceFleet resource - + Parameters: device_fleet_name: The name of the fleet. session: Boto3 session. region: Region name. - + Returns: The DeviceFleet resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6876,38 +6765,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DeviceFleetName": device_fleet_name, + 'DeviceFleetName': device_fleet_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_device_fleet(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeDeviceFleetResponse") + transformed_response = transform(response, 'DescribeDeviceFleetResponse') device_fleet = cls(**transformed_response) return device_fleet - + @Base.add_validate_call def refresh( self, - ) -> Optional["DeviceFleet"]: + + ) -> Optional["DeviceFleet"]: """ Refresh a DeviceFleet resource - + Returns: The DeviceFleet resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6918,21 +6806,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DeviceFleetName": self.device_fleet_name, + 'DeviceFleetName': self.device_fleet_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_device_fleet(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeDeviceFleetResponse", self) + transform(response, 'DescribeDeviceFleetResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -6944,15 +6832,15 @@ def update( ) -> Optional["DeviceFleet"]: """ Update a DeviceFleet resource - + Parameters: enable_iot_role_alias: Whether to create an Amazon Web Services IoT Role Alias during device fleet creation. The name of the role alias generated will match this pattern: "SageMakerEdge-{DeviceFleetName}". For example, if your device fleet is called "demo-fleet", the name of the role alias will be "SageMakerEdge-demo-fleet". - + Returns: The DeviceFleet resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -6963,38 +6851,39 @@ def update( ``` ResourceInUse: Resource being accessed is in use. """ - + logger.info("Updating device_fleet resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "DeviceFleetName": self.device_fleet_name, - "RoleArn": role_arn, - "Description": description, - "OutputConfig": output_config, - "EnableIotRoleAlias": enable_iot_role_alias, + 'DeviceFleetName': self.device_fleet_name, + 'RoleArn': role_arn, + 'Description': description, + 'OutputConfig': output_config, + 'EnableIotRoleAlias': enable_iot_role_alias, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_device_fleet(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a DeviceFleet resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7005,20 +6894,20 @@ def delete( ``` ResourceInUse: Resource being accessed is in use. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "DeviceFleetName": self.device_fleet_name, + 'DeviceFleetName': self.device_fleet_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_device_fleet(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -7035,7 +6924,7 @@ def get_all( ) -> ResourceIterator["DeviceFleet"]: """ Get all DeviceFleet resources - + Parameters: next_token: The response from the last list when returning a list large enough to need tokening. max_results: The maximum number of results to select. @@ -7048,12 +6937,12 @@ def get_all( sort_order: What direction to sort in. session: Boto3 session. region: Region name. - + Returns: Iterator for listed DeviceFleet resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7063,34 +6952,34 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_device_fleets", - summaries_key="DeviceFleetSummaries", - summary_name="DeviceFleetSummary", + list_method='list_device_fleets', + summaries_key='DeviceFleetSummaries', + summary_name='DeviceFleetSummary', resource_cls=DeviceFleet, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def deregister_devices( self, @@ -7100,14 +6989,14 @@ def deregister_devices( ) -> None: """ Deregisters the specified devices. - + Parameters: device_names: The unique IDs of the devices. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7117,41 +7006,43 @@ def deregister_devices( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "DeviceFleetName": self.device_fleet_name, - "DeviceNames": device_names, + 'DeviceFleetName': self.device_fleet_name, + 'DeviceNames': device_names, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling deregister_devices API") response = client.deregister_devices(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def get_report( self, + session: Optional[Session] = None, region: Optional[str] = None, ) -> Optional[shapes.GetDeviceFleetReportResponse]: """ Describes a fleet. - + Parameters: session: Boto3 session. region: Region name. - + Returns: shapes.GetDeviceFleetReportResponse - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7161,25 +7052,25 @@ def get_report( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "DeviceFleetName": self.device_fleet_name, + 'DeviceFleetName': self.device_fleet_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling get_device_fleet_report API") response = client.get_device_fleet_report(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "GetDeviceFleetReportResponse") + + transformed_response = transform(response, 'GetDeviceFleetReportResponse') return shapes.GetDeviceFleetReportResponse(**transformed_response) - + + @Base.add_validate_call def register_devices( self, @@ -7190,15 +7081,15 @@ def register_devices( ) -> None: """ Register devices. - + Parameters: devices: A list of devices to register with SageMaker Edge Manager. tags: The tags associated with devices. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7209,24 +7100,25 @@ def register_devices( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + + operation_input_args = { - "DeviceFleetName": self.device_fleet_name, - "Devices": devices, - "Tags": tags, + 'DeviceFleetName': self.device_fleet_name, + 'Devices': devices, + 'Tags': tags, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling register_devices API") response = client.register_devices(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def update_devices( self, @@ -7236,14 +7128,14 @@ def update_devices( ) -> None: """ Updates one or more devices in a fleet. - + Parameters: devices: List of devices to register with Edge Manager agent. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7253,28 +7145,28 @@ def update_devices( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "DeviceFleetName": self.device_fleet_name, - "Devices": devices, + 'DeviceFleetName': self.device_fleet_name, + 'Devices': devices, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling update_devices API") response = client.update_devices(**operation_input_args) logger.debug(f"Response: {response}") + class Domain(Base): """ Class representing resource Domain - + Attributes: domain_arn: The domain's Amazon Resource Name (ARN). domain_id: The domain ID. @@ -7288,9 +7180,9 @@ class Domain(Base): failure_reason: The failure reason. security_group_id_for_domain_boundary: The ID of the security group that authorizes traffic between the RSessionGateway apps and the RStudioServerPro app. auth_mode: The domain's authentication mode. - default_user_settings: Settings which are applied to UserProfiles in this domain if settings are not explicitly specified in a given UserProfile. + default_user_settings: Settings which are applied to UserProfiles in this domain if settings are not explicitly specified in a given UserProfile. domain_settings: A collection of Domain settings. - app_network_access_type: Specifies the VPC used for non-EFS traffic. The default value is PublicInternetOnly. PublicInternetOnly - Non-EFS traffic is through a VPC managed by Amazon SageMaker AI, which allows direct internet access VpcOnly - All traffic is through the specified VPC and subnets + app_network_access_type: Specifies the VPC used for non-EFS traffic. The default value is PublicInternetOnly. PublicInternetOnly - Non-EFS traffic is through a VPC managed by Amazon SageMaker AI, which allows direct internet access VpcOnly - All traffic is through the specified VPC and subnets home_efs_file_system_kms_key_id: Use KmsKeyId. subnet_ids: The VPC subnets that the domain uses for communication. url: The domain's URL. @@ -7299,9 +7191,8 @@ class Domain(Base): app_security_group_management: The entity that creates and manages the required security groups for inter-app communication in VPCOnly mode. Required when CreateDomain.AppNetworkAccessType is VPCOnly and DomainSettings.RStudioServerProDomainSettings.DomainExecutionRoleArn is provided. tag_propagation: Indicates whether custom tag propagation is supported for the domain. default_space_settings: The default settings for shared spaces that users create in the domain. - + """ - domain_id: str domain_arn: Optional[str] = Unassigned() domain_name: Optional[str] = Unassigned() @@ -7325,88 +7216,164 @@ class Domain(Base): app_security_group_management: Optional[str] = Unassigned() tag_propagation: Optional[str] = Unassigned() default_space_settings: Optional[shapes.DefaultSpaceSettings] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "domain_name" - resource_name_split = resource_name.split("_") + resource_name = 'domain_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object domain") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "security_group_id_for_domain_boundary": {"type": "string"}, - "default_user_settings": { - "execution_role": {"type": "string"}, - "security_groups": {"type": "array", "items": {"type": "string"}}, - "sharing_settings": { - "s3_output_path": {"type": "string"}, - "s3_kms_key_id": {"type": "string"}, - }, - "canvas_app_settings": { - "time_series_forecasting_settings": { - "amazon_forecast_role_arn": {"type": "string"} - }, - "model_register_settings": { - "cross_account_model_register_role_arn": {"type": "string"} - }, - "workspace_settings": { - "s3_artifact_path": {"type": "string"}, - "s3_kms_key_id": {"type": "string"}, - }, - "generative_ai_settings": {"amazon_bedrock_role_arn": {"type": "string"}}, - "emr_serverless_settings": {"execution_role_arn": {"type": "string"}}, - }, - "jupyter_lab_app_settings": { - "emr_settings": { - "assumable_role_arns": {"type": "array", "items": {"type": "string"}}, - "execution_role_arns": {"type": "array", "items": {"type": "string"}}, - } - }, + config_schema_for_resource = \ + { + "security_group_id_for_domain_boundary": { + "type": "string" + }, + "default_user_settings": { + "execution_role": { + "type": "string" + }, + "security_groups": { + "type": "array", + "items": { + "type": "string" + } + }, + "sharing_settings": { + "s3_output_path": { + "type": "string" + }, + "s3_kms_key_id": { + "type": "string" + } + }, + "canvas_app_settings": { + "time_series_forecasting_settings": { + "amazon_forecast_role_arn": { + "type": "string" + } + }, + "model_register_settings": { + "cross_account_model_register_role_arn": { + "type": "string" + } + }, + "workspace_settings": { + "s3_artifact_path": { + "type": "string" }, - "domain_settings": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "r_studio_server_pro_domain_settings": { - "domain_execution_role_arn": {"type": "string"} - }, - "execution_role_identity_config": {"type": "string"}, - "unified_studio_settings": {"project_s3_path": {"type": "string"}}, + "s3_kms_key_id": { + "type": "string" + } + }, + "generative_ai_settings": { + "amazon_bedrock_role_arn": { + "type": "string" + } + }, + "emr_serverless_settings": { + "execution_role_arn": { + "type": "string" + } + } + }, + "jupyter_lab_app_settings": { + "emr_settings": { + "assumable_role_arns": { + "type": "array", + "items": { + "type": "string" + } }, - "home_efs_file_system_kms_key_id": {"type": "string"}, - "subnet_ids": {"type": "array", "items": {"type": "string"}}, - "kms_key_id": {"type": "string"}, - "app_security_group_management": {"type": "string"}, - "default_space_settings": { - "execution_role": {"type": "string"}, - "security_groups": {"type": "array", "items": {"type": "string"}}, - "jupyter_lab_app_settings": { - "emr_settings": { - "assumable_role_arns": {"type": "array", "items": {"type": "string"}}, - "execution_role_arns": {"type": "array", "items": {"type": "string"}}, - } - }, + "execution_role_arns": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "domain_settings": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "r_studio_server_pro_domain_settings": { + "domain_execution_role_arn": { + "type": "string" + } + }, + "execution_role_identity_config": { + "type": "string" + }, + "unified_studio_settings": { + "project_s3_path": { + "type": "string" + } + } + }, + "home_efs_file_system_kms_key_id": { + "type": "string" + }, + "subnet_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "kms_key_id": { + "type": "string" + }, + "app_security_group_management": { + "type": "string" + }, + "default_space_settings": { + "execution_role": { + "type": "string" + }, + "security_groups": { + "type": "array", + "items": { + "type": "string" + } + }, + "jupyter_lab_app_settings": { + "emr_settings": { + "assumable_role_arns": { + "type": "array", + "items": { + "type": "string" + } }, + "execution_role_arns": { + "type": "array", + "items": { + "type": "string" + } + } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Domain", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Domain", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -7430,7 +7397,7 @@ def create( ) -> Optional["Domain"]: """ Create a Domain resource - + Parameters: domain_name: A name for the domain. auth_mode: The mode of authentication that members use to access the domain. @@ -7439,7 +7406,7 @@ def create( subnet_ids: The VPC subnets that the domain uses for communication. vpc_id: The ID of the Amazon Virtual Private Cloud (VPC) that the domain uses for communication. tags: Tags to associated with the Domain. Each tag consists of a key and an optional value. Tag keys must be unique per resource. Tags are searchable using the Search API. Tags that you specify for the Domain are also added to all Apps that the Domain launches. - app_network_access_type: Specifies the VPC used for non-EFS traffic. The default value is PublicInternetOnly. PublicInternetOnly - Non-EFS traffic is through a VPC managed by Amazon SageMaker AI, which allows direct internet access VpcOnly - All traffic is through the specified VPC and subnets + app_network_access_type: Specifies the VPC used for non-EFS traffic. The default value is PublicInternetOnly. PublicInternetOnly - Non-EFS traffic is through a VPC managed by Amazon SageMaker AI, which allows direct internet access VpcOnly - All traffic is through the specified VPC and subnets home_efs_file_system_kms_key_id: Use KmsKeyId. kms_key_id: SageMaker AI uses Amazon Web Services KMS to encrypt EFS and EBS volumes attached to the domain with an Amazon Web Services managed key by default. For more control, specify a customer managed key. app_security_group_management: The entity that creates and manages the required security groups for inter-app communication in VPCOnly mode. Required when CreateDomain.AppNetworkAccessType is VPCOnly and DomainSettings.RStudioServerProDomainSettings.DomainExecutionRoleArn is provided. If setting up the domain for use with RStudio, this value must be set to Service. @@ -7447,12 +7414,12 @@ def create( default_space_settings: The default settings for shared spaces that users create in the domain. session: Boto3 session. region: Region name. - + Returns: The Domain resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7467,43 +7434,39 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating domain resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "DomainName": domain_name, - "AuthMode": auth_mode, - "DefaultUserSettings": default_user_settings, - "DomainSettings": domain_settings, - "SubnetIds": subnet_ids, - "VpcId": vpc_id, - "Tags": tags, - "AppNetworkAccessType": app_network_access_type, - "HomeEfsFileSystemKmsKeyId": home_efs_file_system_kms_key_id, - "KmsKeyId": kms_key_id, - "AppSecurityGroupManagement": app_security_group_management, - "TagPropagation": tag_propagation, - "DefaultSpaceSettings": default_space_settings, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Domain", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'DomainName': domain_name, + 'AuthMode': auth_mode, + 'DefaultUserSettings': default_user_settings, + 'DomainSettings': domain_settings, + 'SubnetIds': subnet_ids, + 'VpcId': vpc_id, + 'Tags': tags, + 'AppNetworkAccessType': app_network_access_type, + 'HomeEfsFileSystemKmsKeyId': home_efs_file_system_kms_key_id, + 'KmsKeyId': kms_key_id, + 'AppSecurityGroupManagement': app_security_group_management, + 'TagPropagation': tag_propagation, + 'DefaultSpaceSettings': default_space_settings, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Domain', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_domain(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get(domain_id=response["DomainId"], session=session, region=region) - + + return cls.get(domain_id=response['DomainId'], session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -7514,17 +7477,17 @@ def get( ) -> Optional["Domain"]: """ Get a Domain resource - + Parameters: domain_id: The domain ID. session: Boto3 session. region: Region name. - + Returns: The Domain resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7535,38 +7498,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": domain_id, + 'DomainId': domain_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_domain(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeDomainResponse") + transformed_response = transform(response, 'DescribeDomainResponse') domain = cls(**transformed_response) return domain - + @Base.add_validate_call def refresh( self, - ) -> Optional["Domain"]: + + ) -> Optional["Domain"]: """ Refresh a Domain resource - + Returns: The Domain resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7577,21 +7539,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": self.domain_id, + 'DomainId': self.domain_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_domain(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeDomainResponse", self) + transform(response, 'DescribeDomainResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -7606,15 +7568,15 @@ def update( ) -> Optional["Domain"]: """ Update a Domain resource - + Parameters: domain_settings_for_update: A collection of DomainSettings configuration values to update. - + Returns: The Domain resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7627,42 +7589,42 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating domain resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "DomainId": self.domain_id, - "DefaultUserSettings": default_user_settings, - "DomainSettingsForUpdate": domain_settings_for_update, - "AppSecurityGroupManagement": app_security_group_management, - "DefaultSpaceSettings": default_space_settings, - "SubnetIds": subnet_ids, - "AppNetworkAccessType": app_network_access_type, - "TagPropagation": tag_propagation, + 'DomainId': self.domain_id, + 'DefaultUserSettings': default_user_settings, + 'DomainSettingsForUpdate': domain_settings_for_update, + 'AppSecurityGroupManagement': app_security_group_management, + 'DefaultSpaceSettings': default_space_settings, + 'SubnetIds': subnet_ids, + 'AppNetworkAccessType': app_network_access_type, + 'TagPropagation': tag_propagation, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_domain(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, retention_policy: Optional[shapes.RetentionPolicy] = Unassigned(), - ) -> None: + ) -> None: """ Delete a Domain resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7674,85 +7636,75 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "DomainId": self.domain_id, - "RetentionPolicy": retention_policy, + 'DomainId': self.domain_id, + 'RetentionPolicy': retention_policy, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_domain(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Deleting", - "Failed", - "InService", - "Pending", - "Updating", - "Update_Failed", - "Delete_Failed", - ], + target_status: Literal['Deleting', 'Failed', 'InService', 'Pending', 'Updating', 'Update_Failed', 'Delete_Failed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Domain resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Domain to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Domain", status=current_status, reason=self.failure_reason - ) - + raise FailedStatusError(resource_type="Domain", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Domain", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -7761,13 +7713,13 @@ def wait_for_delete( ) -> None: """ Wait for a Domain resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7781,47 +7733,37 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Domain to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - - if ( - "delete_failed" in current_status.lower() - or "deletefailed" in current_status.lower() - ): - raise DeleteFailedStatusError( - resource_type="Domain", reason=self.failure_reason - ) - + + if "delete_failed" in current_status.lower() or "deletefailed" in current_status.lower(): + raise DeleteFailedStatusError(resource_type="Domain", reason=self.failure_reason) + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Domain", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -7831,32 +7773,31 @@ def get_all( ) -> ResourceIterator["Domain"]: """ Get all Domain resources. - + Parameters: session: Boto3 session. region: Region name. - + Returns: Iterator for listed Domain resources. - + """ - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + + return ResourceIterator( client=client, - list_method="list_domains", - summaries_key="Domains", - summary_name="DomainDetails", - resource_cls=Domain, + list_method='list_domains', + summaries_key='Domains', + summary_name='DomainDetails', + resource_cls=Domain ) class EdgeDeploymentPlan(Base): """ Class representing resource EdgeDeploymentPlan - + Attributes: edge_deployment_plan_arn: The ARN of edge deployment plan. edge_deployment_plan_name: The name of the edge deployment plan. @@ -7869,9 +7810,8 @@ class EdgeDeploymentPlan(Base): next_token: Token to use when calling the next set of stages in the edge deployment plan. creation_time: The time when the edge deployment plan was created. last_modified_time: The time when the edge deployment plan was last updated. - + """ - edge_deployment_plan_name: str edge_deployment_plan_arn: Optional[str] = Unassigned() model_configs: Optional[List[shapes.EdgeDeploymentModelConfig]] = Unassigned() @@ -7883,23 +7823,23 @@ class EdgeDeploymentPlan(Base): next_token: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "edge_deployment_plan_name" - resource_name_split = resource_name.split("_") + resource_name = 'edge_deployment_plan_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object edge_deployment_plan") return None - + @classmethod @Base.add_validate_call def create( @@ -7914,7 +7854,7 @@ def create( ) -> Optional["EdgeDeploymentPlan"]: """ Create a EdgeDeploymentPlan resource - + Parameters: edge_deployment_plan_name: The name of the edge deployment plan. model_configs: List of models associated with the edge deployment plan. @@ -7923,12 +7863,12 @@ def create( tags: List of tags with which to tag the edge deployment plan. session: Boto3 session. region: Region name. - + Returns: The EdgeDeploymentPlan resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -7942,37 +7882,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating edge_deployment_plan resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "EdgeDeploymentPlanName": edge_deployment_plan_name, - "ModelConfigs": model_configs, - "DeviceFleetName": device_fleet_name, - "Stages": stages, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="EdgeDeploymentPlan", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'EdgeDeploymentPlanName': edge_deployment_plan_name, + 'ModelConfigs': model_configs, + 'DeviceFleetName': device_fleet_name, + 'Stages': stages, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='EdgeDeploymentPlan', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_edge_deployment_plan(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - edge_deployment_plan_name=edge_deployment_plan_name, session=session, region=region - ) - + + return cls.get(edge_deployment_plan_name=edge_deployment_plan_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -7985,19 +7919,19 @@ def get( ) -> Optional["EdgeDeploymentPlan"]: """ Get a EdgeDeploymentPlan resource - + Parameters: edge_deployment_plan_name: The name of the deployment plan to describe. next_token: If the edge deployment plan has enough stages to require tokening, then this is the response from the last list of stages returned. max_results: The maximum number of results to select (50 by default). session: Boto3 session. region: Region name. - + Returns: The EdgeDeploymentPlan resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8008,41 +7942,39 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "EdgeDeploymentPlanName": edge_deployment_plan_name, - "NextToken": next_token, - "MaxResults": max_results, + 'EdgeDeploymentPlanName': edge_deployment_plan_name, + 'NextToken': next_token, + 'MaxResults': max_results, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_edge_deployment_plan(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeEdgeDeploymentPlanResponse") + transformed_response = transform(response, 'DescribeEdgeDeploymentPlanResponse') edge_deployment_plan = cls(**transformed_response) return edge_deployment_plan - + @Base.add_validate_call def refresh( self, - max_results: Optional[int] = Unassigned(), - ) -> Optional["EdgeDeploymentPlan"]: + max_results: Optional[int] = Unassigned(), + ) -> Optional["EdgeDeploymentPlan"]: """ Refresh a EdgeDeploymentPlan resource - + Returns: The EdgeDeploymentPlan resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8053,32 +7985,33 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "EdgeDeploymentPlanName": self.edge_deployment_plan_name, - "NextToken": self.next_token, - "MaxResults": max_results, + 'EdgeDeploymentPlanName': self.edge_deployment_plan_name, + 'NextToken': self.next_token, + 'MaxResults': max_results, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_edge_deployment_plan(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeEdgeDeploymentPlanResponse", self) + transform(response, 'DescribeEdgeDeploymentPlanResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a EdgeDeploymentPlan resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8089,20 +8022,20 @@ def delete( ``` ResourceInUse: Resource being accessed is in use. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "EdgeDeploymentPlanName": self.edge_deployment_plan_name, + 'EdgeDeploymentPlanName': self.edge_deployment_plan_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_edge_deployment_plan(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -8120,7 +8053,7 @@ def get_all( ) -> ResourceIterator["EdgeDeploymentPlan"]: """ Get all EdgeDeploymentPlan resources - + Parameters: next_token: The response from the last list when returning a list large enough to need tokening. max_results: The maximum number of results to select (50 by default). @@ -8134,12 +8067,12 @@ def get_all( sort_order: The direction of the sorting (ascending or descending). session: Boto3 session. region: Region name. - + Returns: Iterator for listed EdgeDeploymentPlan resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8149,50 +8082,51 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "DeviceFleetNameContains": device_fleet_name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'DeviceFleetNameContains': device_fleet_name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_edge_deployment_plans", - summaries_key="EdgeDeploymentPlanSummaries", - summary_name="EdgeDeploymentPlanSummary", + list_method='list_edge_deployment_plans', + summaries_key='EdgeDeploymentPlanSummaries', + summary_name='EdgeDeploymentPlanSummary', resource_cls=EdgeDeploymentPlan, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def create_stage( self, + session: Optional[Session] = None, region: Optional[str] = None, ) -> None: """ Creates a new stage in an existing edge deployment plan. - + Parameters: session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8203,23 +8137,24 @@ def create_stage( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + + operation_input_args = { - "EdgeDeploymentPlanName": self.edge_deployment_plan_name, - "Stages": self.stages, + 'EdgeDeploymentPlanName': self.edge_deployment_plan_name, + 'Stages': self.stages, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling create_edge_deployment_stage API") response = client.create_edge_deployment_stage(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def delete_stage( self, @@ -8229,14 +8164,14 @@ def delete_stage( ) -> None: """ Delete a stage in an edge deployment plan if (and only if) the stage is inactive. - + Parameters: stage_name: The name of the stage. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8247,23 +8182,24 @@ def delete_stage( ``` ResourceInUse: Resource being accessed is in use. """ - + + operation_input_args = { - "EdgeDeploymentPlanName": self.edge_deployment_plan_name, - "StageName": stage_name, + 'EdgeDeploymentPlanName': self.edge_deployment_plan_name, + 'StageName': stage_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling delete_edge_deployment_stage API") response = client.delete_edge_deployment_stage(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def start_stage( self, @@ -8273,14 +8209,14 @@ def start_stage( ) -> None: """ Starts a stage in an edge deployment plan. - + Parameters: stage_name: The name of the stage to start. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8290,23 +8226,24 @@ def start_stage( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "EdgeDeploymentPlanName": self.edge_deployment_plan_name, - "StageName": stage_name, + 'EdgeDeploymentPlanName': self.edge_deployment_plan_name, + 'StageName': stage_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling start_edge_deployment_stage API") response = client.start_edge_deployment_stage(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def stop_stage( self, @@ -8316,14 +8253,14 @@ def stop_stage( ) -> None: """ Stops a stage in an edge deployment plan. - + Parameters: stage_name: The name of the stage to stop. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8333,46 +8270,46 @@ def stop_stage( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "EdgeDeploymentPlanName": self.edge_deployment_plan_name, - "StageName": stage_name, + 'EdgeDeploymentPlanName': self.edge_deployment_plan_name, + 'StageName': stage_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling stop_edge_deployment_stage API") response = client.stop_edge_deployment_stage(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def get_all_stage_devices( self, stage_name: str, - exclude_devices_deployed_in_other_stage: Optional[bool] = Unassigned(), - session: Optional[Session] = None, + exclude_devices_deployed_in_other_stage: Optional[bool] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.DeviceDeploymentSummary]: """ Lists devices allocated to the stage, containing detailed device information and deployment status. - + Parameters: stage_name: The name of the stage in the deployment. max_results: The maximum number of requests to select. exclude_devices_deployed_in_other_stage: Toggle for excluding devices deployed in other stages. session: Boto3 session. region: Region name. - + Returns: Iterator for listed DeviceDeploymentSummary. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8382,34 +8319,34 @@ def get_all_stage_devices( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "EdgeDeploymentPlanName": self.edge_deployment_plan_name, - "ExcludeDevicesDeployedInOtherStage": exclude_devices_deployed_in_other_stage, - "StageName": stage_name, + 'EdgeDeploymentPlanName': self.edge_deployment_plan_name, + 'ExcludeDevicesDeployedInOtherStage': exclude_devices_deployed_in_other_stage, + 'StageName': stage_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_stage_devices", - summaries_key="DeviceDeploymentSummaries", - summary_name="DeviceDeploymentSummary", + list_method='list_stage_devices', + summaries_key='DeviceDeploymentSummaries', + summary_name='DeviceDeploymentSummary', resource_cls=shapes.DeviceDeploymentSummary, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class EdgePackagingJob(Base): """ Class representing resource EdgePackagingJob - + Attributes: edge_packaging_job_arn: The Amazon Resource Name (ARN) of the edge packaging job. edge_packaging_job_name: The name of the edge packaging job. @@ -8426,9 +8363,8 @@ class EdgePackagingJob(Base): model_artifact: The Amazon Simple Storage (S3) URI where model artifacts ares stored. model_signature: The signature document of files in the model artifact. preset_deployment_output: The output of a SageMaker Edge Manager deployable resource. - + """ - edge_packaging_job_name: str edge_packaging_job_arn: Optional[str] = Unassigned() compilation_job_name: Optional[str] = Unassigned() @@ -8444,42 +8380,44 @@ class EdgePackagingJob(Base): model_artifact: Optional[str] = Unassigned() model_signature: Optional[str] = Unassigned() preset_deployment_output: Optional[shapes.EdgePresetDeploymentOutput] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "edge_packaging_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'edge_packaging_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object edge_packaging_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "role_arn": {"type": "string"}, - "output_config": { - "s3_output_location": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, + config_schema_for_resource = \ + { + "role_arn": { + "type": "string" + }, + "output_config": { + "s3_output_location": { + "type": "string" + }, + "kms_key_id": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "EdgePackagingJob", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "EdgePackagingJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -8498,7 +8436,7 @@ def create( ) -> Optional["EdgePackagingJob"]: """ Create a EdgePackagingJob resource - + Parameters: edge_packaging_job_name: The name of the edge packaging job. compilation_job_name: The name of the SageMaker Neo compilation job that will be used to locate model artifacts for packaging. @@ -8510,12 +8448,12 @@ def create( tags: Creates tags for the packaging job. session: Boto3 session. region: Region name. - + Returns: The EdgePackagingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8529,40 +8467,34 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating edge_packaging_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "EdgePackagingJobName": edge_packaging_job_name, - "CompilationJobName": compilation_job_name, - "ModelName": model_name, - "ModelVersion": model_version, - "RoleArn": role_arn, - "OutputConfig": output_config, - "ResourceKey": resource_key, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="EdgePackagingJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'EdgePackagingJobName': edge_packaging_job_name, + 'CompilationJobName': compilation_job_name, + 'ModelName': model_name, + 'ModelVersion': model_version, + 'RoleArn': role_arn, + 'OutputConfig': output_config, + 'ResourceKey': resource_key, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='EdgePackagingJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_edge_packaging_job(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - edge_packaging_job_name=edge_packaging_job_name, session=session, region=region - ) - + + return cls.get(edge_packaging_job_name=edge_packaging_job_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -8573,17 +8505,17 @@ def get( ) -> Optional["EdgePackagingJob"]: """ Get a EdgePackagingJob resource - + Parameters: edge_packaging_job_name: The name of the edge packaging job. session: Boto3 session. region: Region name. - + Returns: The EdgePackagingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8594,38 +8526,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "EdgePackagingJobName": edge_packaging_job_name, + 'EdgePackagingJobName': edge_packaging_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_edge_packaging_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeEdgePackagingJobResponse") + transformed_response = transform(response, 'DescribeEdgePackagingJobResponse') edge_packaging_job = cls(**transformed_response) return edge_packaging_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["EdgePackagingJob"]: + + ) -> Optional["EdgePackagingJob"]: """ Refresh a EdgePackagingJob resource - + Returns: The EdgePackagingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8636,28 +8567,28 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "EdgePackagingJobName": self.edge_packaging_job_name, + 'EdgePackagingJobName': self.edge_packaging_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_edge_packaging_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeEdgePackagingJobResponse", self) + transform(response, 'DescribeEdgePackagingJobResponse', self) return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a EdgePackagingJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8667,81 +8598,77 @@ def stop(self) -> None: error_code = e.response['Error']['Code'] ``` """ - + client = SageMakerClient().client - + operation_input_args = { - "EdgePackagingJobName": self.edge_packaging_job_name, + 'EdgePackagingJobName': self.edge_packaging_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_edge_packaging_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a EdgePackagingJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["COMPLETED", "FAILED", "STOPPED"] + terminal_states = ['COMPLETED', 'FAILED', 'STOPPED'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for EdgePackagingJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.edge_packaging_job_status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="EdgePackagingJob", - status=current_status, - reason=self.edge_packaging_job_status_message, - ) - + raise FailedStatusError(resource_type="EdgePackagingJob", status=current_status, reason=self.edge_packaging_job_status_message) + return - + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="EdgePackagingJob", status=current_status - ) + raise TimeoutExceededError(resouce_type="EdgePackagingJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -8760,7 +8687,7 @@ def get_all( ) -> ResourceIterator["EdgePackagingJob"]: """ Get all EdgePackagingJob resources - + Parameters: next_token: The response from the last list when returning a list large enough to need tokening. max_results: Maximum number of results to select. @@ -8775,12 +8702,12 @@ def get_all( sort_order: What direction to sort by. session: Boto3 session. region: Region name. - + Returns: Iterator for listed EdgePackagingJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8790,59 +8717,57 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "ModelNameContains": model_name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'ModelNameContains': model_name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_edge_packaging_jobs", - summaries_key="EdgePackagingJobSummaries", - summary_name="EdgePackagingJobSummary", + list_method='list_edge_packaging_jobs', + summaries_key='EdgePackagingJobSummaries', + summary_name='EdgePackagingJobSummary', resource_cls=EdgePackagingJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Endpoint(Base): """ Class representing resource Endpoint - + Attributes: endpoint_name: Name of the endpoint. endpoint_arn: The Amazon Resource Name (ARN) of the endpoint. - endpoint_status: The status of the endpoint. OutOfService: Endpoint is not available to take incoming requests. Creating: CreateEndpoint is executing. Updating: UpdateEndpoint or UpdateEndpointWeightsAndCapacities is executing. SystemUpdating: Endpoint is undergoing maintenance and cannot be updated or deleted or re-scaled until it has completed. This maintenance operation does not change any customer-specified values such as VPC config, KMS encryption, model, instance type, or instance count. RollingBack: Endpoint fails to scale up or down or change its variant weight and is in the process of rolling back to its previous configuration. Once the rollback completes, endpoint returns to an InService status. This transitional status only applies to an endpoint that has autoscaling enabled and is undergoing variant weight or capacity changes as part of an UpdateEndpointWeightsAndCapacities call or when the UpdateEndpointWeightsAndCapacities operation is called explicitly. InService: Endpoint is available to process incoming requests. Deleting: DeleteEndpoint is executing. Failed: Endpoint could not be created, updated, or re-scaled. Use the FailureReason value returned by DescribeEndpoint for information about the failure. DeleteEndpoint is the only operation that can be performed on a failed endpoint. UpdateRollbackFailed: Both the rolling deployment and auto-rollback failed. Your endpoint is in service with a mix of the old and new endpoint configurations. For information about how to remedy this issue and restore the endpoint's status to InService, see Rolling Deployments. + endpoint_status: The status of the endpoint. OutOfService: Endpoint is not available to take incoming requests. Creating: CreateEndpoint is executing. Updating: UpdateEndpoint or UpdateEndpointWeightsAndCapacities is executing. SystemUpdating: Endpoint is undergoing maintenance and cannot be updated or deleted or re-scaled until it has completed. This maintenance operation does not change any customer-specified values such as VPC config, KMS encryption, model, instance type, or instance count. RollingBack: Endpoint fails to scale up or down or change its variant weight and is in the process of rolling back to its previous configuration. Once the rollback completes, endpoint returns to an InService status. This transitional status only applies to an endpoint that has autoscaling enabled and is undergoing variant weight or capacity changes as part of an UpdateEndpointWeightsAndCapacities call or when the UpdateEndpointWeightsAndCapacities operation is called explicitly. InService: Endpoint is available to process incoming requests. Deleting: DeleteEndpoint is executing. Failed: Endpoint could not be created, updated, or re-scaled. Use the FailureReason value returned by DescribeEndpoint for information about the failure. DeleteEndpoint is the only operation that can be performed on a failed endpoint. UpdateRollbackFailed: Both the rolling deployment and auto-rollback failed. Your endpoint is in service with a mix of the old and new endpoint configurations. For information about how to remedy this issue and restore the endpoint's status to InService, see Rolling Deployments. creation_time: A timestamp that shows when the endpoint was created. last_modified_time: A timestamp that shows when the endpoint was last modified. endpoint_config_name: The name of the endpoint configuration associated with this endpoint. production_variants: An array of ProductionVariantSummary objects, one for each model hosted behind this endpoint. - data_capture_config: - failure_reason: If the status of the endpoint is Failed, the reason why it failed. + data_capture_config: + failure_reason: If the status of the endpoint is Failed, the reason why it failed. last_deployment_config: The most recent deployment configuration for the endpoint. async_inference_config: Returns the description of an endpoint configuration created using the CreateEndpointConfig API. pending_deployment_summary: Returns the summary of an in-progress deployment. This field is only returned when the endpoint is creating or updating with a new endpoint configuration. explainer_config: The configuration parameters for an explainer. shadow_production_variants: An array of ProductionVariantSummary objects, one for each model that you want to host at this endpoint in shadow mode with production traffic replicated from the model specified on ProductionVariants. - + """ - endpoint_name: str endpoint_arn: Optional[str] = Unassigned() endpoint_config_name: Optional[str] = Unassigned() @@ -8857,48 +8782,54 @@ class Endpoint(Base): pending_deployment_summary: Optional[shapes.PendingDeploymentSummary] = Unassigned() explainer_config: Optional[shapes.ExplainerConfig] = Unassigned() shadow_production_variants: Optional[List[shapes.ProductionVariantSummary]] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "endpoint_name" - resource_name_split = resource_name.split("_") + resource_name = 'endpoint_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object endpoint") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "data_capture_config": { - "destination_s3_uri": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "async_inference_config": { - "output_config": { - "kms_key_id": {"type": "string"}, - "s3_output_path": {"type": "string"}, - "s3_failure_path": {"type": "string"}, - } - }, + config_schema_for_resource = \ + { + "data_capture_config": { + "destination_s3_uri": { + "type": "string" + }, + "kms_key_id": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Endpoint", **kwargs - ), - ) - + }, + "async_inference_config": { + "output_config": { + "kms_key_id": { + "type": "string" + }, + "s3_output_path": { + "type": "string" + }, + "s3_failure_path": { + "type": "string" + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Endpoint", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -8913,20 +8844,20 @@ def create( ) -> Optional["Endpoint"]: """ Create a Endpoint resource - + Parameters: endpoint_name: The name of the endpoint.The name must be unique within an Amazon Web Services Region in your Amazon Web Services account. The name is case-insensitive in CreateEndpoint, but the case is preserved and must be matched in InvokeEndpoint. - endpoint_config_name: The name of an endpoint configuration. For more information, see CreateEndpointConfig. - deployment_config: + endpoint_config_name: The name of an endpoint configuration. For more information, see CreateEndpointConfig. + deployment_config: tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. session: Boto3 session. region: Region name. - + Returns: The Endpoint resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8940,34 +8871,30 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating endpoint resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "EndpointName": endpoint_name, - "EndpointConfigName": endpoint_config_name, - "DeploymentConfig": deployment_config, - "Tags": tags, + 'EndpointName': endpoint_name, + 'EndpointConfigName': endpoint_config_name, + 'DeploymentConfig': deployment_config, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Endpoint", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='Endpoint', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_endpoint(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(endpoint_name=endpoint_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -8978,17 +8905,17 @@ def get( ) -> Optional["Endpoint"]: """ Get a Endpoint resource - + Parameters: endpoint_name: The name of the endpoint. session: Boto3 session. region: Region name. - + Returns: The Endpoint resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -8998,38 +8925,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "EndpointName": endpoint_name, + 'EndpointName': endpoint_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_endpoint(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeEndpointOutput") + transformed_response = transform(response, 'DescribeEndpointOutput') endpoint = cls(**transformed_response) return endpoint - + @Base.add_validate_call def refresh( self, - ) -> Optional["Endpoint"]: + + ) -> Optional["Endpoint"]: """ Refresh a Endpoint resource - + Returns: The Endpoint resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9039,21 +8965,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "EndpointName": self.endpoint_name, + 'EndpointName': self.endpoint_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_endpoint(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeEndpointOutput", self) + transform(response, 'DescribeEndpointOutput', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -9065,18 +8991,18 @@ def update( ) -> Optional["Endpoint"]: """ Update a Endpoint resource - + Parameters: retain_all_variant_properties: When updating endpoint resources, enables or disables the retention of variant properties, such as the instance count or the variant weight. To retain the variant properties of an endpoint when updating it, set RetainAllVariantProperties to true. To use the variant properties specified in a new EndpointConfig call when updating an endpoint, set RetainAllVariantProperties to false. The default is false. - exclude_retained_variant_properties: When you are updating endpoint resources with RetainAllVariantProperties, whose value is set to true, ExcludeRetainedVariantProperties specifies the list of type VariantProperty to override with the values provided by EndpointConfig. If you don't specify a value for ExcludeRetainedVariantProperties, no variant properties are overridden. + exclude_retained_variant_properties: When you are updating endpoint resources with RetainAllVariantProperties, whose value is set to true, ExcludeRetainedVariantProperties specifies the list of type VariantProperty to override with the values provided by EndpointConfig. If you don't specify a value for ExcludeRetainedVariantProperties, no variant properties are overridden. deployment_config: The deployment configuration for an endpoint, which contains the desired deployment strategy and rollback configurations. retain_deployment_config: Specifies whether to reuse the last deployment configuration. The default value is false (the configuration is not reused). - + Returns: The Endpoint resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9087,39 +9013,40 @@ def update( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + logger.info("Updating endpoint resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "EndpointName": self.endpoint_name, - "EndpointConfigName": self.endpoint_config_name, - "RetainAllVariantProperties": retain_all_variant_properties, - "ExcludeRetainedVariantProperties": exclude_retained_variant_properties, - "DeploymentConfig": deployment_config, - "RetainDeploymentConfig": retain_deployment_config, + 'EndpointName': self.endpoint_name, + 'EndpointConfigName': self.endpoint_config_name, + 'RetainAllVariantProperties': retain_all_variant_properties, + 'ExcludeRetainedVariantProperties': exclude_retained_variant_properties, + 'DeploymentConfig': deployment_config, + 'RetainDeploymentConfig': retain_deployment_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_endpoint(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Endpoint resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9129,86 +9056,74 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "EndpointName": self.endpoint_name, + 'EndpointName': self.endpoint_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_endpoint(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "OutOfService", - "Creating", - "Updating", - "SystemUpdating", - "RollingBack", - "InService", - "Deleting", - "Failed", - "UpdateRollbackFailed", - ], + target_status: Literal['OutOfService', 'Creating', 'Updating', 'SystemUpdating', 'RollingBack', 'InService', 'Deleting', 'Failed', 'UpdateRollbackFailed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Endpoint resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Endpoint to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.endpoint_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Endpoint", status=current_status, reason=self.failure_reason - ) - + raise FailedStatusError(resource_type="Endpoint", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Endpoint", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -9217,13 +9132,13 @@ def wait_for_delete( ) -> None: """ Wait for a Endpoint resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9237,39 +9152,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Endpoint to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.endpoint_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Endpoint", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -9287,7 +9197,7 @@ def get_all( ) -> ResourceIterator["Endpoint"]: """ Get all Endpoint resources - + Parameters: sort_by: Sorts the list of results. The default is CreationTime. sort_order: The sort order for results. The default is Descending. @@ -9296,17 +9206,17 @@ def get_all( name_contains: A string in endpoint names. This filter returns only endpoints whose name contains the specified string. creation_time_before: A filter that returns only endpoints that were created before the specified time (timestamp). creation_time_after: A filter that returns only endpoints with a creation time greater than or equal to the specified time (timestamp). - last_modified_time_before: A filter that returns only endpoints that were modified before the specified timestamp. - last_modified_time_after: A filter that returns only endpoints that were modified after the specified timestamp. + last_modified_time_before: A filter that returns only endpoints that were modified before the specified timestamp. + last_modified_time_after: A filter that returns only endpoints that were modified after the specified timestamp. status_equals: A filter that returns only endpoints with the specified status. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Endpoint resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9316,35 +9226,35 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "StatusEquals": status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'StatusEquals': status_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_endpoints", - summaries_key="Endpoints", - summary_name="EndpointSummary", + list_method='list_endpoints', + summaries_key='Endpoints', + summary_name='EndpointSummary', resource_cls=Endpoint, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def update_weights_and_capacities( self, @@ -9354,14 +9264,14 @@ def update_weights_and_capacities( ) -> None: """ Updates variant weight of one or more variants associated with an existing endpoint, or capacity of one variant associated with an existing endpoint. - + Parameters: desired_weights_and_capacities: An object that provides new capacity and weight values for a variant. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9372,23 +9282,24 @@ def update_weights_and_capacities( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + + operation_input_args = { - "EndpointName": self.endpoint_name, - "DesiredWeightsAndCapacities": desired_weights_and_capacities, + 'EndpointName': self.endpoint_name, + 'DesiredWeightsAndCapacities': desired_weights_and_capacities, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling update_endpoint_weights_and_capacities API") response = client.update_endpoint_weights_and_capacities(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def invoke( self, @@ -9408,27 +9319,27 @@ def invoke( ) -> Optional[shapes.InvokeEndpointOutput]: """ After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint. - + Parameters: body: Provides input data, in the format specified in the ContentType request header. Amazon SageMaker passes all of the data in the body to the model. For information about the format of the request body, see Common Data Formats-Inference. content_type: The MIME type of the input data in the request body. accept: The desired MIME type of the inference response from the model container. - custom_attributes: Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with Trace ID: in your post-processing function. This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK. + custom_attributes: Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with Trace ID: in your post-processing function. This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK. target_model: The model to request for inference when invoking a multi-model endpoint. - target_variant: Specify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights. For information about how to use variant targeting to perform a/b testing, see Test models in production + target_variant: Specify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights. For information about how to use variant targeting to perform a/b testing, see Test models in production target_container_hostname: If the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke. inference_id: If you provide a value, it is added to the captured data when you enable data capture on the endpoint. For information about data capture, see Capture Data. - enable_explanations: An optional JMESPath expression used to override the EnableExplanations parameter of the ClarifyExplainerConfig API. See the EnableExplanations section in the developer guide for more information. + enable_explanations: An optional JMESPath expression used to override the EnableExplanations parameter of the ClarifyExplainerConfig API. See the EnableExplanations section in the developer guide for more information. inference_component_name: If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke. session_id: Creates a stateful session or identifies an existing one. You can do one of the following: Create a stateful session by specifying the value NEW_SESSION. Send your request to an existing stateful session by specifying the ID of that session. With a stateful session, you can send multiple requests to a stateful model. When you create a session with a stateful model, the model must create the session ID and set the expiration time. The model must also provide that information in the response to your request. You can get the ID and timestamp from the NewSessionId response parameter. For any subsequent request where you specify that session ID, SageMaker routes the request to the same instance that supports the session. session: Boto3 session. region: Region name. - + Returns: shapes.InvokeEndpointOutput - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9444,36 +9355,36 @@ def invoke( ServiceUnavailable: The service is currently unavailable. ValidationError: There was an error validating your request. """ - + + operation_input_args = { - "EndpointName": self.endpoint_name, - "Body": body, - "ContentType": content_type, - "Accept": accept, - "CustomAttributes": custom_attributes, - "TargetModel": target_model, - "TargetVariant": target_variant, - "TargetContainerHostname": target_container_hostname, - "InferenceId": inference_id, - "EnableExplanations": enable_explanations, - "InferenceComponentName": inference_component_name, - "SessionId": session_id, + 'EndpointName': self.endpoint_name, + 'Body': body, + 'ContentType': content_type, + 'Accept': accept, + 'CustomAttributes': custom_attributes, + 'TargetModel': target_model, + 'TargetVariant': target_variant, + 'TargetContainerHostname': target_container_hostname, + 'InferenceId': inference_id, + 'EnableExplanations': enable_explanations, + 'InferenceComponentName': inference_component_name, + 'SessionId': session_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-runtime" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-runtime') + logger.debug(f"Calling invoke_endpoint API") response = client.invoke_endpoint(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "InvokeEndpointOutput") + + transformed_response = transform(response, 'InvokeEndpointOutput') return shapes.InvokeEndpointOutput(**transformed_response) - + + @Base.add_validate_call def invoke_async( self, @@ -9489,23 +9400,23 @@ def invoke_async( ) -> Optional[shapes.InvokeEndpointAsyncOutput]: """ After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner. - + Parameters: input_location: The Amazon S3 URI where the inference request payload is stored. content_type: The MIME type of the input data in the request body. accept: The desired MIME type of the inference response from the model container. - custom_attributes: Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with Trace ID: in your post-processing function. This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK. - inference_id: The identifier for the inference request. Amazon SageMaker will generate an identifier for you if none is specified. + custom_attributes: Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with Trace ID: in your post-processing function. This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK. + inference_id: The identifier for the inference request. Amazon SageMaker will generate an identifier for you if none is specified. request_ttl_seconds: Maximum age in seconds a request can be in the queue before it is marked as expired. The default is 6 hours, or 21,600 seconds. invocation_timeout_seconds: Maximum amount of time in seconds a request can be processed before it is marked as expired. The default is 15 minutes, or 900 seconds. session: Boto3 session. region: Region name. - + Returns: shapes.InvokeEndpointAsyncOutput - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9518,32 +9429,32 @@ def invoke_async( ServiceUnavailable: The service is currently unavailable. ValidationError: There was an error validating your request. """ - + + operation_input_args = { - "EndpointName": self.endpoint_name, - "ContentType": content_type, - "Accept": accept, - "CustomAttributes": custom_attributes, - "InferenceId": inference_id, - "InputLocation": input_location, - "RequestTTLSeconds": request_ttl_seconds, - "InvocationTimeoutSeconds": invocation_timeout_seconds, + 'EndpointName': self.endpoint_name, + 'ContentType': content_type, + 'Accept': accept, + 'CustomAttributes': custom_attributes, + 'InferenceId': inference_id, + 'InputLocation': input_location, + 'RequestTTLSeconds': request_ttl_seconds, + 'InvocationTimeoutSeconds': invocation_timeout_seconds, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-runtime" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-runtime') + logger.debug(f"Calling invoke_endpoint_async API") response = client.invoke_endpoint_async(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "InvokeEndpointAsyncOutput") + + transformed_response = transform(response, 'InvokeEndpointAsyncOutput') return shapes.InvokeEndpointAsyncOutput(**transformed_response) - + + @Base.add_validate_call def invoke_with_response_stream( self, @@ -9561,25 +9472,25 @@ def invoke_with_response_stream( ) -> Optional[shapes.InvokeEndpointWithResponseStreamOutput]: """ Invokes a model at the specified endpoint to return the inference response as a stream. - + Parameters: body: Provides input data, in the format specified in the ContentType request header. Amazon SageMaker passes all of the data in the body to the model. For information about the format of the request body, see Common Data Formats-Inference. content_type: The MIME type of the input data in the request body. accept: The desired MIME type of the inference response from the model container. - custom_attributes: Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with Trace ID: in your post-processing function. This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK. - target_variant: Specify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights. For information about how to use variant targeting to perform a/b testing, see Test models in production + custom_attributes: Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1). The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with Trace ID: in your post-processing function. This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker Python SDK. + target_variant: Specify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights. For information about how to use variant targeting to perform a/b testing, see Test models in production target_container_hostname: If the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke. inference_id: An identifier that you assign to your request. inference_component_name: If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke for a streaming response. session_id: The ID of a stateful session to handle your request. You can't create a stateful session by using the InvokeEndpointWithResponseStream action. Instead, you can create one by using the InvokeEndpoint action. In your request, you specify NEW_SESSION for the SessionId request parameter. The response to that request provides the session ID for the NewSessionId response parameter. session: Boto3 session. region: Region name. - + Returns: shapes.InvokeEndpointWithResponseStreamOutput - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9595,55 +9506,53 @@ def invoke_with_response_stream( ServiceUnavailable: The service is currently unavailable. ValidationError: There was an error validating your request. """ - + + operation_input_args = { - "EndpointName": self.endpoint_name, - "Body": body, - "ContentType": content_type, - "Accept": accept, - "CustomAttributes": custom_attributes, - "TargetVariant": target_variant, - "TargetContainerHostname": target_container_hostname, - "InferenceId": inference_id, - "InferenceComponentName": inference_component_name, - "SessionId": session_id, + 'EndpointName': self.endpoint_name, + 'Body': body, + 'ContentType': content_type, + 'Accept': accept, + 'CustomAttributes': custom_attributes, + 'TargetVariant': target_variant, + 'TargetContainerHostname': target_container_hostname, + 'InferenceId': inference_id, + 'InferenceComponentName': inference_component_name, + 'SessionId': session_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-runtime" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-runtime') + logger.debug(f"Calling invoke_endpoint_with_response_stream API") response = client.invoke_endpoint_with_response_stream(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "InvokeEndpointWithResponseStreamOutput") + + transformed_response = transform(response, 'InvokeEndpointWithResponseStreamOutput') return shapes.InvokeEndpointWithResponseStreamOutput(**transformed_response) class EndpointConfig(Base): """ Class representing resource EndpointConfig - + Attributes: endpoint_config_name: Name of the SageMaker endpoint configuration. endpoint_config_arn: The Amazon Resource Name (ARN) of the endpoint configuration. production_variants: An array of ProductionVariant objects, one for each model that you want to host at this endpoint. creation_time: A timestamp that shows when the endpoint configuration was created. - data_capture_config: + data_capture_config: kms_key_id: Amazon Web Services KMS key ID Amazon SageMaker uses to encrypt data when storing it on the ML storage volume attached to the instance. async_inference_config: Returns the description of an endpoint configuration created using the CreateEndpointConfig API. explainer_config: The configuration parameters for an explainer. shadow_production_variants: An array of ProductionVariant objects, one for each model that you want to host at this endpoint in shadow mode with production traffic replicated from the model specified on ProductionVariants. execution_role_arn: The Amazon Resource Name (ARN) of the IAM role that you assigned to the endpoint configuration. - vpc_config: + vpc_config: enable_network_isolation: Indicates whether all model containers deployed to the endpoint are isolated. If they are, no inbound or outbound network calls can be made to or from the model containers. - + """ - endpoint_config_name: str endpoint_config_arn: Optional[str] = Unassigned() production_variants: Optional[List[shapes.ProductionVariant]] = Unassigned() @@ -9656,54 +9565,74 @@ class EndpointConfig(Base): execution_role_arn: Optional[str] = Unassigned() vpc_config: Optional[shapes.VpcConfig] = Unassigned() enable_network_isolation: Optional[bool] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "endpoint_config_name" - resource_name_split = resource_name.split("_") + resource_name = 'endpoint_config_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object endpoint_config") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "data_capture_config": { - "destination_s3_uri": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "kms_key_id": {"type": "string"}, - "async_inference_config": { - "output_config": { - "kms_key_id": {"type": "string"}, - "s3_output_path": {"type": "string"}, - "s3_failure_path": {"type": "string"}, - } - }, - "execution_role_arn": {"type": "string"}, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, + config_schema_for_resource = \ + { + "data_capture_config": { + "destination_s3_uri": { + "type": "string" + }, + "kms_key_id": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "EndpointConfig", **kwargs - ), - ) - + }, + "kms_key_id": { + "type": "string" + }, + "async_inference_config": { + "output_config": { + "kms_key_id": { + "type": "string" + }, + "s3_output_path": { + "type": "string" + }, + "s3_failure_path": { + "type": "string" + } + } + }, + "execution_role_arn": { + "type": "string" + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "EndpointConfig", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -9725,27 +9654,27 @@ def create( ) -> Optional["EndpointConfig"]: """ Create a EndpointConfig resource - + Parameters: - endpoint_config_name: The name of the endpoint configuration. You specify this name in a CreateEndpoint request. + endpoint_config_name: The name of the endpoint configuration. You specify this name in a CreateEndpoint request. production_variants: An array of ProductionVariant objects, one for each model that you want to host at this endpoint. - data_capture_config: + data_capture_config: tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. - kms_key_id: The Amazon Resource Name (ARN) of a Amazon Web Services Key Management Service key that SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. The KmsKeyId can be any of the following formats: Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab Key ARN: arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab Alias name: alias/ExampleAlias Alias name ARN: arn:aws:kms:us-west-2:111122223333:alias/ExampleAlias The KMS key policy must grant permission to the IAM role that you specify in your CreateEndpoint, UpdateEndpoint requests. For more information, refer to the Amazon Web Services Key Management Service section Using Key Policies in Amazon Web Services KMS Certain Nitro-based instances include local storage, dependent on the instance type. Local storage volumes are encrypted using a hardware module on the instance. You can't request a KmsKeyId when using an instance type with local storage. If any of the models that you specify in the ProductionVariants parameter use nitro-based instances with local storage, do not specify a value for the KmsKeyId parameter. If you specify a value for KmsKeyId when using any nitro-based instances with local storage, the call to CreateEndpointConfig fails. For a list of instance types that support local instance storage, see Instance Store Volumes. For more information about local instance storage encryption, see SSD Instance Store Volumes. + kms_key_id: The Amazon Resource Name (ARN) of a Amazon Web Services Key Management Service key that SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. The KmsKeyId can be any of the following formats: Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab Key ARN: arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab Alias name: alias/ExampleAlias Alias name ARN: arn:aws:kms:us-west-2:111122223333:alias/ExampleAlias The KMS key policy must grant permission to the IAM role that you specify in your CreateEndpoint, UpdateEndpoint requests. For more information, refer to the Amazon Web Services Key Management Service section Using Key Policies in Amazon Web Services KMS Certain Nitro-based instances include local storage, dependent on the instance type. Local storage volumes are encrypted using a hardware module on the instance. You can't request a KmsKeyId when using an instance type with local storage. If any of the models that you specify in the ProductionVariants parameter use nitro-based instances with local storage, do not specify a value for the KmsKeyId parameter. If you specify a value for KmsKeyId when using any nitro-based instances with local storage, the call to CreateEndpointConfig fails. For a list of instance types that support local instance storage, see Instance Store Volumes. For more information about local instance storage encryption, see SSD Instance Store Volumes. async_inference_config: Specifies configuration for how an endpoint performs asynchronous inference. This is a required field in order for your Endpoint to be invoked using InvokeEndpointAsync. explainer_config: A member of CreateEndpointConfig that enables explainers. shadow_production_variants: An array of ProductionVariant objects, one for each model that you want to host at this endpoint in shadow mode with production traffic replicated from the model specified on ProductionVariants. If you use this field, you can only specify one variant for ProductionVariants and one variant for ShadowProductionVariants. - execution_role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform actions on your behalf. For more information, see SageMaker AI Roles. To be able to pass this role to Amazon SageMaker AI, the caller of this action must have the iam:PassRole permission. - vpc_config: + execution_role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform actions on your behalf. For more information, see SageMaker AI Roles. To be able to pass this role to Amazon SageMaker AI, the caller of this action must have the iam:PassRole permission. + vpc_config: enable_network_isolation: Sets whether all model containers deployed to the endpoint are isolated. If they are, no inbound or outbound network calls can be made to or from the model containers. session: Boto3 session. region: Region name. - + Returns: The EndpointConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9759,41 +9688,37 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating endpoint_config resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "EndpointConfigName": endpoint_config_name, - "ProductionVariants": production_variants, - "DataCaptureConfig": data_capture_config, - "Tags": tags, - "KmsKeyId": kms_key_id, - "AsyncInferenceConfig": async_inference_config, - "ExplainerConfig": explainer_config, - "ShadowProductionVariants": shadow_production_variants, - "ExecutionRoleArn": execution_role_arn, - "VpcConfig": vpc_config, - "EnableNetworkIsolation": enable_network_isolation, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="EndpointConfig", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'EndpointConfigName': endpoint_config_name, + 'ProductionVariants': production_variants, + 'DataCaptureConfig': data_capture_config, + 'Tags': tags, + 'KmsKeyId': kms_key_id, + 'AsyncInferenceConfig': async_inference_config, + 'ExplainerConfig': explainer_config, + 'ShadowProductionVariants': shadow_production_variants, + 'ExecutionRoleArn': execution_role_arn, + 'VpcConfig': vpc_config, + 'EnableNetworkIsolation': enable_network_isolation, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='EndpointConfig', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_endpoint_config(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(endpoint_config_name=endpoint_config_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -9804,17 +9729,17 @@ def get( ) -> Optional["EndpointConfig"]: """ Get a EndpointConfig resource - + Parameters: endpoint_config_name: The name of the endpoint configuration. session: Boto3 session. region: Region name. - + Returns: The EndpointConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9824,38 +9749,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "EndpointConfigName": endpoint_config_name, + 'EndpointConfigName': endpoint_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_endpoint_config(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeEndpointConfigOutput") + transformed_response = transform(response, 'DescribeEndpointConfigOutput') endpoint_config = cls(**transformed_response) return endpoint_config - + @Base.add_validate_call def refresh( self, - ) -> Optional["EndpointConfig"]: + + ) -> Optional["EndpointConfig"]: """ Refresh a EndpointConfig resource - + Returns: The EndpointConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9865,30 +9789,31 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "EndpointConfigName": self.endpoint_config_name, + 'EndpointConfigName': self.endpoint_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_endpoint_config(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeEndpointConfigOutput", self) + transform(response, 'DescribeEndpointConfigOutput', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a EndpointConfig resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9898,20 +9823,20 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "EndpointConfigName": self.endpoint_config_name, + 'EndpointConfigName': self.endpoint_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_endpoint_config(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -9926,23 +9851,23 @@ def get_all( ) -> ResourceIterator["EndpointConfig"]: """ Get all EndpointConfig resources - + Parameters: sort_by: The field to sort results by. The default is CreationTime. sort_order: The sort order for results. The default is Descending. - next_token: If the result of the previous ListEndpointConfig request was truncated, the response includes a NextToken. To retrieve the next set of endpoint configurations, use the token in the next request. + next_token: If the result of the previous ListEndpointConfig request was truncated, the response includes a NextToken. To retrieve the next set of endpoint configurations, use the token in the next request. max_results: The maximum number of training jobs to return in the response. - name_contains: A string in the endpoint configuration name. This filter returns only endpoint configurations whose name contains the specified string. + name_contains: A string in the endpoint configuration name. This filter returns only endpoint configurations whose name contains the specified string. creation_time_before: A filter that returns only endpoint configurations created before the specified time (timestamp). creation_time_after: A filter that returns only endpoint configurations with a creation time greater than or equal to the specified time (timestamp). session: Boto3 session. region: Region name. - + Returns: Iterator for listed EndpointConfig resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -9952,37 +9877,36 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_endpoint_configs", - summaries_key="EndpointConfigs", - summary_name="EndpointConfigSummary", + list_method='list_endpoint_configs', + summaries_key='EndpointConfigs', + summary_name='EndpointConfigSummary', resource_cls=EndpointConfig, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Experiment(Base): """ Class representing resource Experiment - + Attributes: experiment_name: The name of the experiment. experiment_arn: The Amazon Resource Name (ARN) of the experiment. @@ -9993,9 +9917,8 @@ class Experiment(Base): created_by: Who created the experiment. last_modified_time: When the experiment was last modified. last_modified_by: Who last modified the experiment. - + """ - experiment_name: str experiment_arn: Optional[str] = Unassigned() display_name: Optional[str] = Unassigned() @@ -10005,23 +9928,23 @@ class Experiment(Base): created_by: Optional[shapes.UserContext] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "experiment_name" - resource_name_split = resource_name.split("_") + resource_name = 'experiment_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object experiment") return None - + @classmethod @Base.add_validate_call def create( @@ -10035,7 +9958,7 @@ def create( ) -> Optional["Experiment"]: """ Create a Experiment resource - + Parameters: experiment_name: The name of the experiment. The name must be unique in your Amazon Web Services account and is not case-sensitive. display_name: The name of the experiment as displayed. The name doesn't need to be unique. If you don't specify DisplayName, the value in ExperimentName is displayed. @@ -10043,12 +9966,12 @@ def create( tags: A list of tags to associate with the experiment. You can use Search API to search on the tags. session: Boto3 session. region: Region name. - + Returns: The Experiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10062,34 +9985,30 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating experiment resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "ExperimentName": experiment_name, - "DisplayName": display_name, - "Description": description, - "Tags": tags, + 'ExperimentName': experiment_name, + 'DisplayName': display_name, + 'Description': description, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Experiment", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='Experiment', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_experiment(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(experiment_name=experiment_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -10100,17 +10019,17 @@ def get( ) -> Optional["Experiment"]: """ Get a Experiment resource - + Parameters: experiment_name: The name of the experiment to describe. session: Boto3 session. region: Region name. - + Returns: The Experiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10121,38 +10040,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ExperimentName": experiment_name, + 'ExperimentName': experiment_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_experiment(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeExperimentResponse") + transformed_response = transform(response, 'DescribeExperimentResponse') experiment = cls(**transformed_response) return experiment - + @Base.add_validate_call def refresh( self, - ) -> Optional["Experiment"]: + + ) -> Optional["Experiment"]: """ Refresh a Experiment resource - + Returns: The Experiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10163,21 +10081,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ExperimentName": self.experiment_name, + 'ExperimentName': self.experiment_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_experiment(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeExperimentResponse", self) + transform(response, 'DescribeExperimentResponse', self) return self - + @Base.add_validate_call def update( self, @@ -10186,12 +10104,12 @@ def update( ) -> Optional["Experiment"]: """ Update a Experiment resource - + Returns: The Experiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10203,36 +10121,37 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating experiment resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ExperimentName": self.experiment_name, - "DisplayName": display_name, - "Description": description, + 'ExperimentName': self.experiment_name, + 'DisplayName': display_name, + 'Description': description, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_experiment(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Experiment resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10243,20 +10162,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ExperimentName": self.experiment_name, + 'ExperimentName': self.experiment_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_experiment(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -10270,7 +10189,7 @@ def get_all( ) -> ResourceIterator["Experiment"]: """ Get all Experiment resources - + Parameters: created_after: A filter that returns only experiments created after the specified time. created_before: A filter that returns only experiments created before the specified time. @@ -10280,12 +10199,12 @@ def get_all( max_results: The maximum number of experiments to return in the response. The default value is 10. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Experiment resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10295,38 +10214,37 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_experiments", - summaries_key="ExperimentSummaries", - summary_name="ExperimentSummary", + list_method='list_experiments', + summaries_key='ExperimentSummaries', + summary_name='ExperimentSummary', resource_cls=Experiment, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class FeatureGroup(Base): """ Class representing resource FeatureGroup - + Attributes: - feature_group_arn: The Amazon Resource Name (ARN) of the FeatureGroup. + feature_group_arn: The Amazon Resource Name (ARN) of the FeatureGroup. feature_group_name: he name of the FeatureGroup. record_identifier_feature_name: The name of the Feature used for RecordIdentifier, whose value uniquely identifies a record stored in the feature store. event_time_feature_name: The name of the feature that stores the EventTime of a Record in a FeatureGroup. An EventTime is a point in time when a new event occurs that corresponds to the creation or update of a Record in a FeatureGroup. All Records in the FeatureGroup have a corresponding EventTime. @@ -10335,18 +10253,17 @@ class FeatureGroup(Base): next_token: A token to resume pagination of the list of Features (FeatureDefinitions). last_modified_time: A timestamp indicating when the feature group was last updated. online_store_config: The configuration for the OnlineStore. - offline_store_config: The configuration of the offline store. It includes the following configurations: Amazon S3 location of the offline store. Configuration of the Glue data catalog. Table format of the offline store. Option to disable the automatic creation of a Glue table for the offline store. Encryption configuration. - throughput_config: + offline_store_config: The configuration of the offline store. It includes the following configurations: Amazon S3 location of the offline store. Configuration of the Glue data catalog. Table format of the offline store. Option to disable the automatic creation of a Glue table for the offline store. Encryption configuration. + throughput_config: role_arn: The Amazon Resource Name (ARN) of the IAM execution role used to persist data into the OfflineStore if an OfflineStoreConfig is provided. feature_group_status: The status of the feature group. - offline_store_status: The status of the OfflineStore. Notifies you if replicating data into the OfflineStore has failed. Returns either: Active or Blocked + offline_store_status: The status of the OfflineStore. Notifies you if replicating data into the OfflineStore has failed. Returns either: Active or Blocked last_update_status: A value indicating whether the update made to the feature group was successful. - failure_reason: The reason that the FeatureGroup failed to be replicated in the OfflineStore. This is failure can occur because: The FeatureGroup could not be created in the OfflineStore. The FeatureGroup could not be deleted from the OfflineStore. + failure_reason: The reason that the FeatureGroup failed to be replicated in the OfflineStore. This is failure can occur because: The FeatureGroup could not be created in the OfflineStore. The FeatureGroup could not be deleted from the OfflineStore. description: A free form description of the feature group. online_store_total_size_bytes: The size of the OnlineStore in bytes. - + """ - feature_group_name: str feature_group_arn: Optional[str] = Unassigned() record_identifier_feature_name: Optional[str] = Unassigned() @@ -10365,46 +10282,56 @@ class FeatureGroup(Base): description: Optional[str] = Unassigned() next_token: Optional[str] = Unassigned() online_store_total_size_bytes: Optional[int] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "feature_group_name" - resource_name_split = resource_name.split("_") + resource_name = 'feature_group_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object feature_group") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "online_store_config": {"security_config": {"kms_key_id": {"type": "string"}}}, - "offline_store_config": { - "s3_storage_config": { - "s3_uri": {"type": "string"}, - "kms_key_id": {"type": "string"}, - "resolved_output_s3_uri": {"type": "string"}, - } - }, - "role_arn": {"type": "string"}, + config_schema_for_resource = \ + { + "online_store_config": { + "security_config": { + "kms_key_id": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "FeatureGroup", **kwargs - ), - ) - + }, + "offline_store_config": { + "s3_storage_config": { + "s3_uri": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + }, + "resolved_output_s3_uri": { + "type": "string" + } + } + }, + "role_arn": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "FeatureGroup", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -10425,26 +10352,26 @@ def create( ) -> Optional["FeatureGroup"]: """ Create a FeatureGroup resource - + Parameters: - feature_group_name: The name of the FeatureGroup. The name must be unique within an Amazon Web Services Region in an Amazon Web Services account. The name: Must start with an alphanumeric character. Can only include alphanumeric characters, underscores, and hyphens. Spaces are not allowed. - record_identifier_feature_name: The name of the Feature whose value uniquely identifies a Record defined in the FeatureStore. Only the latest record per identifier value will be stored in the OnlineStore. RecordIdentifierFeatureName must be one of feature definitions' names. You use the RecordIdentifierFeatureName to access data in a FeatureStore. This name: Must start with an alphanumeric character. Can only contains alphanumeric characters, hyphens, underscores. Spaces are not allowed. - event_time_feature_name: The name of the feature that stores the EventTime of a Record in a FeatureGroup. An EventTime is a point in time when a new event occurs that corresponds to the creation or update of a Record in a FeatureGroup. All Records in the FeatureGroup must have a corresponding EventTime. An EventTime can be a String or Fractional. Fractional: EventTime feature values must be a Unix timestamp in seconds. String: EventTime feature values must be an ISO-8601 string in the format. The following formats are supported yyyy-MM-dd'T'HH:mm:ssZ and yyyy-MM-dd'T'HH:mm:ss.SSSZ where yyyy, MM, and dd represent the year, month, and day respectively and HH, mm, ss, and if applicable, SSS represent the hour, month, second and milliseconds respsectively. 'T' and Z are constants. + feature_group_name: The name of the FeatureGroup. The name must be unique within an Amazon Web Services Region in an Amazon Web Services account. The name: Must start with an alphanumeric character. Can only include alphanumeric characters, underscores, and hyphens. Spaces are not allowed. + record_identifier_feature_name: The name of the Feature whose value uniquely identifies a Record defined in the FeatureStore. Only the latest record per identifier value will be stored in the OnlineStore. RecordIdentifierFeatureName must be one of feature definitions' names. You use the RecordIdentifierFeatureName to access data in a FeatureStore. This name: Must start with an alphanumeric character. Can only contains alphanumeric characters, hyphens, underscores. Spaces are not allowed. + event_time_feature_name: The name of the feature that stores the EventTime of a Record in a FeatureGroup. An EventTime is a point in time when a new event occurs that corresponds to the creation or update of a Record in a FeatureGroup. All Records in the FeatureGroup must have a corresponding EventTime. An EventTime can be a String or Fractional. Fractional: EventTime feature values must be a Unix timestamp in seconds. String: EventTime feature values must be an ISO-8601 string in the format. The following formats are supported yyyy-MM-dd'T'HH:mm:ssZ and yyyy-MM-dd'T'HH:mm:ss.SSSZ where yyyy, MM, and dd represent the year, month, and day respectively and HH, mm, ss, and if applicable, SSS represent the hour, month, second and milliseconds respsectively. 'T' and Z are constants. feature_definitions: A list of Feature names and types. Name and Type is compulsory per Feature. Valid feature FeatureTypes are Integral, Fractional and String. FeatureNames cannot be any of the following: is_deleted, write_time, api_invocation_time You can create up to 2,500 FeatureDefinitions per FeatureGroup. online_store_config: You can turn the OnlineStore on or off by specifying True for the EnableOnlineStore flag in OnlineStoreConfig. You can also include an Amazon Web Services KMS key ID (KMSKeyId) for at-rest encryption of the OnlineStore. The default value is False. offline_store_config: Use this to configure an OfflineFeatureStore. This parameter allows you to specify: The Amazon Simple Storage Service (Amazon S3) location of an OfflineStore. A configuration for an Amazon Web Services Glue or Amazon Web Services Hive data catalog. An KMS encryption key to encrypt the Amazon S3 location used for OfflineStore. If KMS encryption key is not specified, by default we encrypt all data at rest using Amazon Web Services KMS key. By defining your bucket-level key for SSE, you can reduce Amazon Web Services KMS requests costs by up to 99 percent. Format for the offline store table. Supported formats are Glue (Default) and Apache Iceberg. To learn more about this parameter, see OfflineStoreConfig. - throughput_config: + throughput_config: role_arn: The Amazon Resource Name (ARN) of the IAM execution role used to persist data into the OfflineStore if an OfflineStoreConfig is provided. description: A free-form description of a FeatureGroup. tags: Tags used to identify Features in each FeatureGroup. session: Boto3 session. region: Region name. - + Returns: The FeatureGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10459,40 +10386,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating feature_group resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "FeatureGroupName": feature_group_name, - "RecordIdentifierFeatureName": record_identifier_feature_name, - "EventTimeFeatureName": event_time_feature_name, - "FeatureDefinitions": feature_definitions, - "OnlineStoreConfig": online_store_config, - "OfflineStoreConfig": offline_store_config, - "ThroughputConfig": throughput_config, - "RoleArn": role_arn, - "Description": description, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="FeatureGroup", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'FeatureGroupName': feature_group_name, + 'RecordIdentifierFeatureName': record_identifier_feature_name, + 'EventTimeFeatureName': event_time_feature_name, + 'FeatureDefinitions': feature_definitions, + 'OnlineStoreConfig': online_store_config, + 'OfflineStoreConfig': offline_store_config, + 'ThroughputConfig': throughput_config, + 'RoleArn': role_arn, + 'Description': description, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='FeatureGroup', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_feature_group(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(feature_group_name=feature_group_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -10504,18 +10427,18 @@ def get( ) -> Optional["FeatureGroup"]: """ Get a FeatureGroup resource - + Parameters: - feature_group_name: The name or Amazon Resource Name (ARN) of the FeatureGroup you want described. + feature_group_name: The name or Amazon Resource Name (ARN) of the FeatureGroup you want described. next_token: A token to resume pagination of the list of Features (FeatureDefinitions). 2,500 Features are returned by default. session: Boto3 session. region: Region name. - + Returns: The FeatureGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10526,39 +10449,38 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "FeatureGroupName": feature_group_name, - "NextToken": next_token, + 'FeatureGroupName': feature_group_name, + 'NextToken': next_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_feature_group(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeFeatureGroupResponse") + transformed_response = transform(response, 'DescribeFeatureGroupResponse') feature_group = cls(**transformed_response) return feature_group - + @Base.add_validate_call def refresh( self, - ) -> Optional["FeatureGroup"]: + + ) -> Optional["FeatureGroup"]: """ Refresh a FeatureGroup resource - + Returns: The FeatureGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10569,22 +10491,22 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "FeatureGroupName": self.feature_group_name, - "NextToken": self.next_token, + 'FeatureGroupName': self.feature_group_name, + 'NextToken': self.next_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_feature_group(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeFeatureGroupResponse", self) + transform(response, 'DescribeFeatureGroupResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -10595,15 +10517,15 @@ def update( ) -> Optional["FeatureGroup"]: """ Update a FeatureGroup resource - + Parameters: feature_additions: Updates the feature group. Updating a feature group is an asynchronous operation. When you get an HTTP 200 response, you've made a valid request. It takes some time after you've made a valid request for Feature Store to update the feature group. - + Returns: The FeatureGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10615,37 +10537,38 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating feature_group resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "FeatureGroupName": self.feature_group_name, - "FeatureAdditions": feature_additions, - "OnlineStoreConfig": online_store_config, - "ThroughputConfig": throughput_config, + 'FeatureGroupName': self.feature_group_name, + 'FeatureAdditions': feature_additions, + 'OnlineStoreConfig': online_store_config, + 'ThroughputConfig': throughput_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_feature_group(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a FeatureGroup resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10656,78 +10579,74 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "FeatureGroupName": self.feature_group_name, + 'FeatureGroupName': self.feature_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_feature_group(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Creating", "Created", "CreateFailed", "Deleting", "DeleteFailed"], + target_status: Literal['Creating', 'Created', 'CreateFailed', 'Deleting', 'DeleteFailed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a FeatureGroup resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for FeatureGroup to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.feature_group_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="FeatureGroup", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="FeatureGroup", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="FeatureGroup", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -10736,13 +10655,13 @@ def wait_for_delete( ) -> None: """ Wait for a FeatureGroup resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10756,41 +10675,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for FeatureGroup to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.feature_group_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="FeatureGroup", status=current_status - ) + raise TimeoutExceededError(resouce_type="FeatureGroup", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -10807,11 +10719,11 @@ def get_all( ) -> ResourceIterator["FeatureGroup"]: """ Get all FeatureGroup resources - + Parameters: - name_contains: A string that partially matches one or more FeatureGroups names. Filters FeatureGroups by name. - feature_group_status_equals: A FeatureGroup status. Filters by FeatureGroup status. - offline_store_status_equals: An OfflineStore status. Filters by OfflineStore status. + name_contains: A string that partially matches one or more FeatureGroups names. Filters FeatureGroups by name. + feature_group_status_equals: A FeatureGroup status. Filters by FeatureGroup status. + offline_store_status_equals: An OfflineStore status. Filters by OfflineStore status. creation_time_after: Use this parameter to search for FeatureGroupss created after a specific date and time. creation_time_before: Use this parameter to search for FeatureGroupss created before a specific date and time. sort_order: The order in which feature groups are listed. @@ -10820,12 +10732,12 @@ def get_all( next_token: A token to resume pagination of ListFeatureGroups results. session: Boto3 session. region: Region name. - + Returns: Iterator for listed FeatureGroup resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10835,34 +10747,34 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "NameContains": name_contains, - "FeatureGroupStatusEquals": feature_group_status_equals, - "OfflineStoreStatusEquals": offline_store_status_equals, - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "SortOrder": sort_order, - "SortBy": sort_by, + 'NameContains': name_contains, + 'FeatureGroupStatusEquals': feature_group_status_equals, + 'OfflineStoreStatusEquals': offline_store_status_equals, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'SortOrder': sort_order, + 'SortBy': sort_by, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_feature_groups", - summaries_key="FeatureGroupSummaries", - summary_name="FeatureGroupSummary", + list_method='list_feature_groups', + summaries_key='FeatureGroupSummaries', + summary_name='FeatureGroupSummary', resource_cls=FeatureGroup, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_record( self, @@ -10874,19 +10786,19 @@ def get_record( ) -> Optional[shapes.GetRecordResponse]: """ Use for OnlineStore serving from a FeatureStore. - + Parameters: - record_identifier_value_as_string: The value that corresponds to RecordIdentifier type and uniquely identifies the record in the FeatureGroup. + record_identifier_value_as_string: The value that corresponds to RecordIdentifier type and uniquely identifies the record in the FeatureGroup. feature_names: List of names of Features to be retrieved. If not specified, the latest value for all the Features are returned. expiration_time_response: Parameter to request ExpiresAt in response. If Enabled, GetRecord will return the value of ExpiresAt, if it is not null. If Disabled and null, GetRecord will return null. session: Boto3 session. region: Region name. - + Returns: shapes.GetRecordResponse - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10901,28 +10813,28 @@ def get_record( ServiceUnavailable: The service is currently unavailable. ValidationError: There was an error validating your request. """ - + + operation_input_args = { - "FeatureGroupName": self.feature_group_name, - "RecordIdentifierValueAsString": record_identifier_value_as_string, - "FeatureNames": feature_names, - "ExpirationTimeResponse": expiration_time_response, + 'FeatureGroupName': self.feature_group_name, + 'RecordIdentifierValueAsString': record_identifier_value_as_string, + 'FeatureNames': feature_names, + 'ExpirationTimeResponse': expiration_time_response, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-featurestore-runtime') + logger.debug(f"Calling get_record API") response = client.get_record(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "GetRecordResponse") + + transformed_response = transform(response, 'GetRecordResponse') return shapes.GetRecordResponse(**transformed_response) - + + @Base.add_validate_call def put_record( self, @@ -10934,16 +10846,16 @@ def put_record( ) -> None: """ The PutRecord API is used to ingest a list of Records into your feature group. - + Parameters: - record: List of FeatureValues to be inserted. This will be a full over-write. If you only want to update few of the feature values, do the following: Use GetRecord to retrieve the latest record. Update the record returned from GetRecord. Use PutRecord to update feature values. + record: List of FeatureValues to be inserted. This will be a full over-write. If you only want to update few of the feature values, do the following: Use GetRecord to retrieve the latest record. Update the record returned from GetRecord. Use PutRecord to update feature values. target_stores: A list of stores to which you're adding the record. By default, Feature Store adds the record to all of the stores that you're using for the FeatureGroup. ttl_duration: Time to live duration, where the record is hard deleted after the expiration time is reached; ExpiresAt = EventTime + TtlDuration. For information on HardDelete, see the DeleteRecord API in the Amazon SageMaker API Reference guide. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -10957,25 +10869,26 @@ def put_record( ServiceUnavailable: The service is currently unavailable. ValidationError: There was an error validating your request. """ - + + operation_input_args = { - "FeatureGroupName": self.feature_group_name, - "Record": record, - "TargetStores": target_stores, - "TtlDuration": ttl_duration, + 'FeatureGroupName': self.feature_group_name, + 'Record': record, + 'TargetStores': target_stores, + 'TtlDuration': ttl_duration, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-featurestore-runtime') + logger.debug(f"Calling put_record API") response = client.put_record(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def delete_record( self, @@ -10988,17 +10901,17 @@ def delete_record( ) -> None: """ Deletes a Record from a FeatureGroup in the OnlineStore. - + Parameters: - record_identifier_value_as_string: The value for the RecordIdentifier that uniquely identifies the record, in string format. + record_identifier_value_as_string: The value for the RecordIdentifier that uniquely identifies the record, in string format. event_time: Timestamp indicating when the deletion event occurred. EventTime can be used to query data at a certain point in time. target_stores: A list of stores from which you're deleting the record. By default, Feature Store deletes the record from all of the stores that you're using for the FeatureGroup. deletion_mode: The name of the deletion mode for deleting the record. By default, the deletion mode is set to SoftDelete. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11012,26 +10925,27 @@ def delete_record( ServiceUnavailable: The service is currently unavailable. ValidationError: There was an error validating your request. """ - + + operation_input_args = { - "FeatureGroupName": self.feature_group_name, - "RecordIdentifierValueAsString": record_identifier_value_as_string, - "EventTime": event_time, - "TargetStores": target_stores, - "DeletionMode": deletion_mode, + 'FeatureGroupName': self.feature_group_name, + 'RecordIdentifierValueAsString': record_identifier_value_as_string, + 'EventTime': event_time, + 'TargetStores': target_stores, + 'DeletionMode': deletion_mode, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-featurestore-runtime') + logger.debug(f"Calling delete_record API") response = client.delete_record(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def batch_get_record( self, @@ -11042,18 +10956,18 @@ def batch_get_record( ) -> Optional[shapes.BatchGetRecordResponse]: """ Retrieves a batch of Records from a FeatureGroup. - + Parameters: identifiers: A list containing the name or Amazon Resource Name (ARN) of the FeatureGroup, the list of names of Features to be retrieved, and the corresponding RecordIdentifier values as strings. expiration_time_response: Parameter to request ExpiresAt in response. If Enabled, BatchGetRecord will return the value of ExpiresAt, if it is not null. If Disabled and null, BatchGetRecord will return null. session: Boto3 session. region: Region name. - + Returns: shapes.BatchGetRecordResponse - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11067,43 +10981,41 @@ def batch_get_record( ServiceUnavailable: The service is currently unavailable. ValidationError: There was an error validating your request. """ - + + operation_input_args = { - "Identifiers": identifiers, - "ExpirationTimeResponse": expiration_time_response, + 'Identifiers': identifiers, + 'ExpirationTimeResponse': expiration_time_response, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-featurestore-runtime') + logger.debug(f"Calling batch_get_record API") response = client.batch_get_record(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "BatchGetRecordResponse") + + transformed_response = transform(response, 'BatchGetRecordResponse') return shapes.BatchGetRecordResponse(**transformed_response) class FeatureMetadata(Base): """ Class representing resource FeatureMetadata - + Attributes: feature_group_arn: The Amazon Resource Number (ARN) of the feature group that contains the feature. feature_group_name: The name of the feature group that you've specified. feature_name: The name of the feature that you've specified. feature_type: The data type of the feature. creation_time: A timestamp indicating when the feature was created. - last_modified_time: A timestamp indicating when the metadata for the feature group was modified. For example, if you add a parameter describing the feature, the timestamp changes to reflect the last time you + last_modified_time: A timestamp indicating when the metadata for the feature group was modified. For example, if you add a parameter describing the feature, the timestamp changes to reflect the last time you description: The description you added to describe the feature. parameters: The key-value pairs that you added to describe the feature. - + """ - feature_group_name: str feature_name: str feature_group_arn: Optional[str] = Unassigned() @@ -11112,23 +11024,23 @@ class FeatureMetadata(Base): last_modified_time: Optional[datetime.datetime] = Unassigned() description: Optional[str] = Unassigned() parameters: Optional[List[shapes.FeatureParameter]] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "feature_metadata_name" - resource_name_split = resource_name.split("_") + resource_name = 'feature_metadata_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object feature_metadata") return None - + @classmethod @Base.add_validate_call def get( @@ -11140,18 +11052,18 @@ def get( ) -> Optional["FeatureMetadata"]: """ Get a FeatureMetadata resource - + Parameters: feature_group_name: The name or Amazon Resource Name (ARN) of the feature group containing the feature. feature_name: The name of the feature. session: Boto3 session. region: Region name. - + Returns: The FeatureMetadata resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11162,39 +11074,38 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "FeatureGroupName": feature_group_name, - "FeatureName": feature_name, + 'FeatureGroupName': feature_group_name, + 'FeatureName': feature_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_feature_metadata(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeFeatureMetadataResponse") + transformed_response = transform(response, 'DescribeFeatureMetadataResponse') feature_metadata = cls(**transformed_response) return feature_metadata - + @Base.add_validate_call def refresh( self, - ) -> Optional["FeatureMetadata"]: + + ) -> Optional["FeatureMetadata"]: """ Refresh a FeatureMetadata resource - + Returns: The FeatureMetadata resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11205,22 +11116,22 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "FeatureGroupName": self.feature_group_name, - "FeatureName": self.feature_name, + 'FeatureGroupName': self.feature_group_name, + 'FeatureName': self.feature_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_feature_metadata(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeFeatureMetadataResponse", self) + transform(response, 'DescribeFeatureMetadataResponse', self) return self - + @Base.add_validate_call def update( self, @@ -11230,16 +11141,16 @@ def update( ) -> Optional["FeatureMetadata"]: """ Update a FeatureMetadata resource - + Parameters: parameter_additions: A list of key-value pairs that you can add to better describe the feature. parameter_removals: A list of parameter keys that you can specify to remove parameters that describe your feature. - + Returns: The FeatureMetadata resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11250,34 +11161,34 @@ def update( ``` ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating feature_metadata resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "FeatureGroupName": self.feature_group_name, - "FeatureName": self.feature_name, - "Description": description, - "ParameterAdditions": parameter_additions, - "ParameterRemovals": parameter_removals, + 'FeatureGroupName': self.feature_group_name, + 'FeatureName': self.feature_name, + 'Description': description, + 'ParameterAdditions': parameter_additions, + 'ParameterRemovals': parameter_removals, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_feature_metadata(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self class FlowDefinition(Base): """ Class representing resource FlowDefinition - + Attributes: flow_definition_arn: The Amazon Resource Name (ARN) of the flow defintion. flow_definition_name: The Amazon Resource Name (ARN) of the flow definition. @@ -11289,9 +11200,8 @@ class FlowDefinition(Base): human_loop_activation_config: An object containing information about what triggers a human review workflow. human_loop_config: An object containing information about who works on the task, the workforce task price, and other task details. failure_reason: The reason your flow definition failed. - + """ - flow_definition_name: str flow_definition_arn: Optional[str] = Unassigned() flow_definition_status: Optional[str] = Unassigned() @@ -11302,42 +11212,44 @@ class FlowDefinition(Base): output_config: Optional[shapes.FlowDefinitionOutputConfig] = Unassigned() role_arn: Optional[str] = Unassigned() failure_reason: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "flow_definition_name" - resource_name_split = resource_name.split("_") + resource_name = 'flow_definition_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object flow_definition") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "output_config": { - "s3_output_path": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "role_arn": {"type": "string"}, + config_schema_for_resource = \ + { + "output_config": { + "s3_output_path": { + "type": "string" + }, + "kms_key_id": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "FlowDefinition", **kwargs - ), - ) - + }, + "role_arn": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "FlowDefinition", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -11355,7 +11267,7 @@ def create( ) -> Optional["FlowDefinition"]: """ Create a FlowDefinition resource - + Parameters: flow_definition_name: The name of your flow definition. output_config: An object containing information about where the human review results will be uploaded. @@ -11366,12 +11278,12 @@ def create( tags: An array of key-value pairs that contain metadata to help you categorize and organize a flow definition. Each tag consists of a key and a value, both of which you define. session: Boto3 session. region: Region name. - + Returns: The FlowDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11386,37 +11298,33 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating flow_definition resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "FlowDefinitionName": flow_definition_name, - "HumanLoopRequestSource": human_loop_request_source, - "HumanLoopActivationConfig": human_loop_activation_config, - "HumanLoopConfig": human_loop_config, - "OutputConfig": output_config, - "RoleArn": role_arn, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="FlowDefinition", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'FlowDefinitionName': flow_definition_name, + 'HumanLoopRequestSource': human_loop_request_source, + 'HumanLoopActivationConfig': human_loop_activation_config, + 'HumanLoopConfig': human_loop_config, + 'OutputConfig': output_config, + 'RoleArn': role_arn, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='FlowDefinition', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_flow_definition(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(flow_definition_name=flow_definition_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -11427,17 +11335,17 @@ def get( ) -> Optional["FlowDefinition"]: """ Get a FlowDefinition resource - + Parameters: flow_definition_name: The name of the flow definition. session: Boto3 session. region: Region name. - + Returns: The FlowDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11448,38 +11356,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "FlowDefinitionName": flow_definition_name, + 'FlowDefinitionName': flow_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_flow_definition(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeFlowDefinitionResponse") + transformed_response = transform(response, 'DescribeFlowDefinitionResponse') flow_definition = cls(**transformed_response) return flow_definition - + @Base.add_validate_call def refresh( self, - ) -> Optional["FlowDefinition"]: + + ) -> Optional["FlowDefinition"]: """ Refresh a FlowDefinition resource - + Returns: The FlowDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11490,30 +11397,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "FlowDefinitionName": self.flow_definition_name, + 'FlowDefinitionName': self.flow_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_flow_definition(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeFlowDefinitionResponse", self) + transform(response, 'DescribeFlowDefinitionResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a FlowDefinition resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11525,78 +11433,74 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "FlowDefinitionName": self.flow_definition_name, + 'FlowDefinitionName': self.flow_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_flow_definition(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Initializing", "Active", "Failed", "Deleting"], + target_status: Literal['Initializing', 'Active', 'Failed', 'Deleting'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a FlowDefinition resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for FlowDefinition to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.flow_definition_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="FlowDefinition", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="FlowDefinition", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="FlowDefinition", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -11605,13 +11509,13 @@ def wait_for_delete( ) -> None: """ Wait for a FlowDefinition resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11625,41 +11529,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for FlowDefinition to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.flow_definition_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="FlowDefinition", status=current_status - ) + raise TimeoutExceededError(resouce_type="FlowDefinition", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -11672,7 +11569,7 @@ def get_all( ) -> ResourceIterator["FlowDefinition"]: """ Get all FlowDefinition resources - + Parameters: creation_time_after: A filter that returns only flow definitions with a creation time greater than or equal to the specified timestamp. creation_time_before: A filter that returns only flow definitions that were created before the specified timestamp. @@ -11681,12 +11578,12 @@ def get_all( max_results: The total number of items to return. If the total number of available items is more than the value specified in MaxResults, then a NextToken will be provided in the output that you can use to resume pagination. session: Boto3 session. region: Region name. - + Returns: Iterator for listed FlowDefinition resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11696,35 +11593,34 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_flow_definitions", - summaries_key="FlowDefinitionSummaries", - summary_name="FlowDefinitionSummary", + list_method='list_flow_definitions', + summaries_key='FlowDefinitionSummaries', + summary_name='FlowDefinitionSummary', resource_cls=FlowDefinition, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Hub(Base): """ Class representing resource Hub - + Attributes: hub_name: The name of the hub. hub_arn: The Amazon Resource Name (ARN) of the hub. @@ -11736,9 +11632,8 @@ class Hub(Base): hub_search_keywords: The searchable keywords for the hub. s3_storage_config: The Amazon S3 storage configuration for the hub. failure_reason: The failure reason if importing hub content failed. - + """ - hub_name: str hub_arn: Optional[str] = Unassigned() hub_display_name: Optional[str] = Unassigned() @@ -11749,38 +11644,38 @@ class Hub(Base): failure_reason: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "hub_name" - resource_name_split = resource_name.split("_") + resource_name = 'hub_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object hub") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "s3_storage_config": {"s3_output_path": {"type": "string"}} + config_schema_for_resource = \ + { + "s3_storage_config": { + "s3_output_path": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Hub", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Hub", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -11797,7 +11692,7 @@ def create( ) -> Optional["Hub"]: """ Create a Hub resource - + Parameters: hub_name: The name of the hub to create. hub_description: A description of the hub. @@ -11807,12 +11702,12 @@ def create( tags: Any tags to associate with the hub. session: Boto3 session. region: Region name. - + Returns: The Hub resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11827,36 +11722,32 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating hub resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "HubName": hub_name, - "HubDescription": hub_description, - "HubDisplayName": hub_display_name, - "HubSearchKeywords": hub_search_keywords, - "S3StorageConfig": s3_storage_config, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Hub", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'HubName': hub_name, + 'HubDescription': hub_description, + 'HubDisplayName': hub_display_name, + 'HubSearchKeywords': hub_search_keywords, + 'S3StorageConfig': s3_storage_config, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Hub', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_hub(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(hub_name=hub_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -11867,17 +11758,17 @@ def get( ) -> Optional["Hub"]: """ Get a Hub resource - + Parameters: hub_name: The name of the hub to describe. session: Boto3 session. region: Region name. - + Returns: The Hub resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11888,38 +11779,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HubName": hub_name, + 'HubName': hub_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_hub(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeHubResponse") + transformed_response = transform(response, 'DescribeHubResponse') hub = cls(**transformed_response) return hub - + @Base.add_validate_call def refresh( self, - ) -> Optional["Hub"]: + + ) -> Optional["Hub"]: """ Refresh a Hub resource - + Returns: The Hub resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11930,21 +11820,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HubName": self.hub_name, + 'HubName': self.hub_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_hub(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeHubResponse", self) + transform(response, 'DescribeHubResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -11955,12 +11845,12 @@ def update( ) -> Optional["Hub"]: """ Update a Hub resource - + Returns: The Hub resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -11971,37 +11861,38 @@ def update( ``` ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating hub resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "HubName": self.hub_name, - "HubDescription": hub_description, - "HubDisplayName": hub_display_name, - "HubSearchKeywords": hub_search_keywords, + 'HubName': self.hub_name, + 'HubDescription': hub_description, + 'HubDisplayName': hub_display_name, + 'HubSearchKeywords': hub_search_keywords, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_hub(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Hub resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12013,84 +11904,74 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "HubName": self.hub_name, + 'HubName': self.hub_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_hub(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "InService", - "Creating", - "Updating", - "Deleting", - "CreateFailed", - "UpdateFailed", - "DeleteFailed", - ], + target_status: Literal['InService', 'Creating', 'Updating', 'Deleting', 'CreateFailed', 'UpdateFailed', 'DeleteFailed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Hub resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Hub to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.hub_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Hub", status=current_status, reason=self.failure_reason - ) - + raise FailedStatusError(resource_type="Hub", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Hub", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -12099,13 +11980,13 @@ def wait_for_delete( ) -> None: """ Wait for a Hub resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12119,39 +12000,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Hub to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.hub_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Hub", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -12168,7 +12044,7 @@ def get_all( ) -> ResourceIterator["Hub"]: """ Get all Hub resources - + Parameters: name_contains: Only list hubs with names that contain the specified string. creation_time_before: Only list hubs that were created before the time specified. @@ -12181,12 +12057,12 @@ def get_all( next_token: If the response to a previous ListHubs request was truncated, the response includes a NextToken. To retrieve the next set of hubs, use the token in the next request. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Hub resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12196,39 +12072,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "SortBy": sort_by, - "SortOrder": sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_hubs", - summaries_key="HubSummaries", - summary_name="HubInfo", + list_method='list_hubs', + summaries_key='HubSummaries', + summary_name='HubInfo', resource_cls=Hub, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class HubContent(Base): """ Class representing resource HubContent - + Attributes: hub_content_name: The name of the hub content. hub_content_arn: The Amazon Resource Name (ARN) of the hub content. @@ -12236,7 +12111,7 @@ class HubContent(Base): hub_content_type: The type of hub content. document_schema_version: The document schema version for the hub content. hub_name: The name of the hub that contains the content. - hub_arn: The Amazon Resource Name (ARN) of the hub that contains the content. + hub_arn: The Amazon Resource Name (ARN) of the hub that contains the content. hub_content_document: The hub content document that describes information about the hub content such as type, associated containers, scripts, and more. hub_content_status: The status of the hub content. creation_time: The date and time that hub content was created. @@ -12250,9 +12125,9 @@ class HubContent(Base): hub_content_dependencies: The location of any dependencies that the hub content has, such as scripts, model artifacts, datasets, or notebooks. failure_reason: The failure reason if importing hub content failed. last_modified_time: The last modified time of the hub content. - + """ - + hub_content_type: str hub_content_name: str hub_content_arn: Optional[str] = Unassigned() @@ -12272,24 +12147,23 @@ class HubContent(Base): failure_reason: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() - hub_name: Optional[str] = Unassigned() - + hub_name: Optional[str] = Unassigned() def get_name(self) -> str: attributes = vars(self) - resource_name = "hub_content_name" - resource_name_split = resource_name.split("_") + resource_name = 'hub_content_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object hub_content") return None - + @classmethod @Base.add_validate_call def get( @@ -12303,7 +12177,7 @@ def get( ) -> Optional["HubContent"]: """ Get a HubContent resource - + Parameters: hub_name: The name of the hub that contains the content to describe. hub_content_type: The type of content in the hub. @@ -12311,12 +12185,12 @@ def get( hub_content_version: The version of the content to describe. session: Boto3 session. region: Region name. - + Returns: The HubContent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12327,41 +12201,40 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HubName": hub_name, - "HubContentType": hub_content_type, - "HubContentName": hub_content_name, - "HubContentVersion": hub_content_version, + 'HubName': hub_name, + 'HubContentType': hub_content_type, + 'HubContentName': hub_content_name, + 'HubContentVersion': hub_content_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_hub_content(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeHubContentResponse") + transformed_response = transform(response, 'DescribeHubContentResponse') hub_content = cls(**transformed_response) return hub_content - + @Base.add_validate_call def refresh( self, - ) -> Optional["HubContent"]: + + ) -> Optional["HubContent"]: """ Refresh a HubContent resource - + Returns: The HubContent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12372,24 +12245,24 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HubName": self.hub_name, - "HubContentType": self.hub_content_type, - "HubContentName": self.hub_content_name, - "HubContentVersion": self.hub_content_version, + 'HubName': self.hub_name, + 'HubContentType': self.hub_content_type, + 'HubContentName': self.hub_content_name, + 'HubContentVersion': self.hub_content_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_hub_content(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeHubContentResponse", self) + transform(response, 'DescribeHubContentResponse', self) return self - + @Base.add_validate_call def update( self, @@ -12403,12 +12276,12 @@ def update( ) -> Optional["HubContent"]: """ Update a HubContent resource - + Returns: The HubContent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12420,42 +12293,43 @@ def update( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating hub_content resource.") client = Base.get_sagemaker_client() - - operation_input_args = { - "HubName": self.hub_name, - "HubContentName": self.hub_content_name, - "HubContentType": hub_content_type, - "HubContentVersion": hub_content_version, - "HubContentDisplayName": hub_content_display_name, - "HubContentDescription": hub_content_description, - "HubContentMarkdown": hub_content_markdown, - "HubContentSearchKeywords": hub_content_search_keywords, - "SupportStatus": support_status, + + operation_input_args = { + 'HubName': self.hub_name, + 'HubContentName': self.hub_content_name, + 'HubContentType': hub_content_type, + 'HubContentVersion': hub_content_version, + 'HubContentDisplayName': hub_content_display_name, + 'HubContentDescription': hub_content_description, + 'HubContentMarkdown': hub_content_markdown, + 'HubContentSearchKeywords': hub_content_search_keywords, + 'SupportStatus': support_status, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_hub_content(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a HubContent resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12467,74 +12341,74 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "HubName": self.hub_name, - "HubContentType": self.hub_content_type, - "HubContentName": self.hub_content_name, - "HubContentVersion": self.hub_content_version, + 'HubName': self.hub_name, + 'HubContentType': self.hub_content_type, + 'HubContentName': self.hub_content_name, + 'HubContentVersion': self.hub_content_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_hub_content(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Supported", "Deprecated", "Restricted"], + target_status: Literal['Supported', 'Deprecated', 'Restricted'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a HubContent resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for HubContent to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.support_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="HubContent", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def load( @@ -12556,7 +12430,7 @@ def load( ) -> Optional["HubContent"]: """ Import a HubContent resource - + Parameters: hub_content_name: The name of the hub content to import. hub_content_type: The type of hub content to import. @@ -12572,12 +12446,12 @@ def load( tags: Any tags associated with the hub content. session: Boto3 session. region: Region name. - + Returns: The HubContent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12590,44 +12464,36 @@ def load( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info(f"Importing hub_content resource.") - client = SageMakerClient( - session=session, region_name=region, service_name="sagemaker" - ).client - - operation_input_args = { - "HubContentName": hub_content_name, - "HubContentVersion": hub_content_version, - "HubContentType": hub_content_type, - "DocumentSchemaVersion": document_schema_version, - "HubName": hub_name, - "HubContentDisplayName": hub_content_display_name, - "HubContentDescription": hub_content_description, - "HubContentMarkdown": hub_content_markdown, - "HubContentDocument": hub_content_document, - "SupportStatus": support_status, - "HubContentSearchKeywords": hub_content_search_keywords, - "Tags": tags, - } - + client = SageMakerClient(session=session, region_name=region, service_name='sagemaker').client + + operation_input_args = { + 'HubContentName': hub_content_name, + 'HubContentVersion': hub_content_version, + 'HubContentType': hub_content_type, + 'DocumentSchemaVersion': document_schema_version, + 'HubName': hub_name, + 'HubContentDisplayName': hub_content_display_name, + 'HubContentDescription': hub_content_description, + 'HubContentMarkdown': hub_content_markdown, + 'HubContentDocument': hub_content_document, + 'SupportStatus': support_status, + 'HubContentSearchKeywords': hub_content_search_keywords, + 'Tags': tags, + } + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # import the resource response = client.import_hub_content(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - hub_name=hub_name, - hub_content_type=hub_content_type, - hub_content_name=hub_content_name, - session=session, - region=region, - ) - + + return cls.get(hub_name=hub_name, hub_content_type=hub_content_type, hub_content_name=hub_content_name, session=session, region=region) + @classmethod @Base.add_validate_call def get_all( @@ -12645,7 +12511,7 @@ def get_all( ) -> ResourceIterator["HubContent"]: """ Get all HubContent resources - + Parameters: hub_name: The name of the hub to list the contents of. hub_content_type: The type of hub content to list. @@ -12659,12 +12525,12 @@ def get_all( next_token: If the response to a previous ListHubContents request was truncated, the response includes a NextToken. To retrieve the next set of hub content, use the token in the next request. session: Boto3 session. region: Region name. - + Returns: Iterator for listed HubContent resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12675,37 +12541,36 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "HubName": hub_name, - "HubContentType": hub_content_type, - "NameContains": name_contains, - "MaxSchemaVersion": max_schema_version, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "SortBy": sort_by, - "SortOrder": sort_order, + 'HubName': hub_name, + 'HubContentType': hub_content_type, + 'NameContains': name_contains, + 'MaxSchemaVersion': max_schema_version, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, } extract_name_mapping = {"hub_content_arn": ["hub-content/", "hub_name"]} - + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_hub_contents", - summaries_key="HubContentSummaries", - summary_name="HubContentInfo", + list_method='list_hub_contents', + summaries_key='HubContentSummaries', + summary_name='HubContentInfo', resource_cls=HubContent, extract_name_mapping=extract_name_mapping, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_versions( self, @@ -12714,13 +12579,12 @@ def get_all_versions( creation_time_before: Optional[datetime.datetime] = Unassigned(), creation_time_after: Optional[datetime.datetime] = Unassigned(), sort_by: Optional[str] = Unassigned(), - sort_order: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_order: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator["HubContent"]: """ List hub content versions. - + Parameters: min_version: The lower bound of the hub content versions to list. max_schema_version: The upper bound of the hub content schema version. @@ -12732,12 +12596,12 @@ def get_all_versions( next_token: If the response to a previous ListHubContentVersions request was truncated, the response includes a NextToken. To retrieve the next set of hub content versions, use the token in the next request. session: Boto3 session. region: Region name. - + Returns: Iterator for listed HubContent. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12748,40 +12612,40 @@ def get_all_versions( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "HubName": self.hub_name, - "HubContentType": self.hub_content_type, - "HubContentName": self.hub_content_name, - "MinVersion": min_version, - "MaxSchemaVersion": max_schema_version, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "SortBy": sort_by, - "SortOrder": sort_order, + 'HubName': self.hub_name, + 'HubContentType': self.hub_content_type, + 'HubContentName': self.hub_content_name, + 'MinVersion': min_version, + 'MaxSchemaVersion': max_schema_version, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_hub_content_versions", - summaries_key="HubContentSummaries", - summary_name="HubContentInfo", + list_method='list_hub_content_versions', + summaries_key='HubContentSummaries', + summary_name='HubContentInfo', resource_cls=HubContent, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class HubContentPresignedUrls(Base): """ Class representing resource HubContentPresignedUrls - + Attributes: hub_name: The name or Amazon Resource Name (ARN) of the hub that contains the content. For public content, use SageMakerPublicHub. hub_content_type: The type of hub content to access. Valid values include Model, Notebook, and ModelReference. @@ -12791,9 +12655,8 @@ class HubContentPresignedUrls(Base): access_config: Configuration settings for accessing the hub content, including end-user license agreement acceptance for gated models and expected S3 URL validation. max_results: The maximum number of presigned URLs to return in the response. Default value is 100. Large models may contain hundreds of files, requiring pagination to retrieve all URLs. next_token: A token for pagination. If present, indicates that more presigned URLs are available. Use this token in a subsequent request to retrieve additional URLs. - + """ - hub_name: Union[str, object] hub_content_type: str hub_content_name: Union[str, object] @@ -12802,23 +12665,23 @@ class HubContentPresignedUrls(Base): access_config: Optional[shapes.PresignedUrlAccessConfig] = Unassigned() max_results: Optional[int] = Unassigned() next_token: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "hub_content_presigned_urls_name" - resource_name_split = resource_name.split("_") + resource_name = 'hub_content_presigned_urls_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object hub_content_presigned_urls") return None - + @classmethod @Base.add_validate_call def create( @@ -12833,7 +12696,7 @@ def create( ) -> Optional["HubContentPresignedUrls"]: """ Create a HubContentPresignedUrls resource - + Parameters: hub_name: The name or Amazon Resource Name (ARN) of the hub that contains the content. For public content, use SageMakerPublicHub. hub_content_type: The type of hub content to access. Valid values include Model, Notebook, and ModelReference. @@ -12844,12 +12707,12 @@ def create( next_token: A token for pagination. Use this token to retrieve the next set of presigned URLs when the response is truncated. session: Boto3 session. region: Region name. - + Returns: The HubContentPresignedUrls resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12862,36 +12725,35 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + + operation_input_args = { - "HubName": hub_name, - "HubContentType": hub_content_type, - "HubContentName": hub_content_name, - "HubContentVersion": hub_content_version, - "AccessConfig": access_config, - "MaxResults": max_results, - "NextToken": next_token, + 'HubName': hub_name, + 'HubContentType': hub_content_type, + 'HubContentName': hub_content_name, + 'HubContentVersion': hub_content_version, + 'AccessConfig': access_config, + 'MaxResults': max_results, + 'NextToken': next_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling create_hub_content_presigned_urls API") response = client.create_hub_content_presigned_urls(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "CreateHubContentPresignedUrlsResponse") + + transformed_response = transform(response, 'CreateHubContentPresignedUrlsResponse') return cls(**operation_input_args, **transformed_response) class HubContentReference(Base): """ Class representing resource HubContentReference - + Attributes: hub_name: The name of the hub to add the hub content reference to. sage_maker_public_hub_content_arn: The ARN of the public hub content to reference. @@ -12900,9 +12762,8 @@ class HubContentReference(Base): hub_content_name: The name of the hub content to reference. min_version: The minimum version of the hub content to reference. tags: Any tags associated with the hub content to reference. - + """ - hub_name: Union[str, object] sage_maker_public_hub_content_arn: str hub_arn: str @@ -12910,23 +12771,23 @@ class HubContentReference(Base): hub_content_name: Optional[Union[str, object]] = Unassigned() min_version: Optional[str] = Unassigned() tags: Optional[List[shapes.Tag]] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "hub_content_reference_name" - resource_name_split = resource_name.split("_") + resource_name = 'hub_content_reference_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object hub_content_reference") return None - + @classmethod @Base.add_validate_call def create( @@ -12939,7 +12800,7 @@ def create( ) -> Optional["HubContentReference"]: """ Create a HubContentReference resource - + Parameters: hub_name: The name of the hub to add the hub content reference to. sage_maker_public_hub_content_arn: The ARN of the public hub content to reference. @@ -12948,12 +12809,12 @@ def create( tags: Any tags associated with the hub content to reference. session: Boto3 session. region: Region name. - + Returns: The HubContentReference resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -12969,29 +12830,28 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + + operation_input_args = { - "HubName": hub_name, - "SageMakerPublicHubContentArn": sage_maker_public_hub_content_arn, - "HubContentName": hub_content_name, - "MinVersion": min_version, - "Tags": tags, + 'HubName': hub_name, + 'SageMakerPublicHubContentArn': sage_maker_public_hub_content_arn, + 'HubContentName': hub_content_name, + 'MinVersion': min_version, + 'Tags': tags, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling create_hub_content_reference API") response = client.create_hub_content_reference(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "CreateHubContentReferenceResponse") + + transformed_response = transform(response, 'CreateHubContentReferenceResponse') return cls(**operation_input_args, **transformed_response) - + @Base.add_validate_call def update( self, @@ -13000,15 +12860,15 @@ def update( ) -> Optional["HubContentReference"]: """ Update a HubContentReference resource - + Parameters: hub_content_type: The content type of the resource that you want to update. Only specify a ModelReference resource for this API. To update a Model or Notebook resource, use the UpdateHubContent API instead. - + Returns: The HubContentReference resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13020,38 +12880,38 @@ def update( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating hub_content_reference resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "HubName": self.hub_name, - "HubContentName": self.hub_content_name, - "HubContentType": hub_content_type, - "MinVersion": min_version, + 'HubName': self.hub_name, + 'HubContentName': self.hub_content_name, + 'HubContentType': hub_content_type, + 'MinVersion': min_version, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_hub_content_reference(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, hub_content_type: str, - ) -> None: + ) -> None: """ Delete a HubContentReference resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13062,58 +12922,57 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "HubName": self.hub_name, - "HubContentType": hub_content_type, - "HubContentName": self.hub_content_name, + 'HubName': self.hub_name, + 'HubContentType': hub_content_type, + 'HubContentName': self.hub_content_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_hub_content_reference(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") class HumanTaskUi(Base): """ Class representing resource HumanTaskUi - + Attributes: human_task_ui_arn: The Amazon Resource Name (ARN) of the human task user interface (worker task template). human_task_ui_name: The name of the human task user interface (worker task template). creation_time: The timestamp when the human task user interface was created. - ui_template: + ui_template: human_task_ui_status: The status of the human task user interface (worker task template). Valid values are listed below. - + """ - human_task_ui_name: str human_task_ui_arn: Optional[str] = Unassigned() human_task_ui_status: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() ui_template: Optional[shapes.UiTemplateInfo] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "human_task_ui_name" - resource_name_split = resource_name.split("_") + resource_name = 'human_task_ui_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object human_task_ui") return None - + @classmethod @Base.add_validate_call def create( @@ -13126,19 +12985,19 @@ def create( ) -> Optional["HumanTaskUi"]: """ Create a HumanTaskUi resource - + Parameters: human_task_ui_name: The name of the user interface you are creating. - ui_template: + ui_template: tags: An array of key-value pairs that contain metadata to help you categorize and organize a human review workflow user interface. Each tag consists of a key and a value, both of which you define. session: Boto3 session. region: Region name. - + Returns: The HumanTaskUi resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13153,33 +13012,29 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating human_task_ui resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "HumanTaskUiName": human_task_ui_name, - "UiTemplate": ui_template, - "Tags": tags, + 'HumanTaskUiName': human_task_ui_name, + 'UiTemplate': ui_template, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="HumanTaskUi", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='HumanTaskUi', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_human_task_ui(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(human_task_ui_name=human_task_ui_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -13190,17 +13045,17 @@ def get( ) -> Optional["HumanTaskUi"]: """ Get a HumanTaskUi resource - + Parameters: human_task_ui_name: The name of the human task user interface (worker task template) you want information about. session: Boto3 session. region: Region name. - + Returns: The HumanTaskUi resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13211,38 +13066,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HumanTaskUiName": human_task_ui_name, + 'HumanTaskUiName': human_task_ui_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_human_task_ui(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeHumanTaskUiResponse") + transformed_response = transform(response, 'DescribeHumanTaskUiResponse') human_task_ui = cls(**transformed_response) return human_task_ui - + @Base.add_validate_call def refresh( self, - ) -> Optional["HumanTaskUi"]: + + ) -> Optional["HumanTaskUi"]: """ Refresh a HumanTaskUi resource - + Returns: The HumanTaskUi resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13253,30 +13107,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HumanTaskUiName": self.human_task_ui_name, + 'HumanTaskUiName': self.human_task_ui_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_human_task_ui(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeHumanTaskUiResponse", self) + transform(response, 'DescribeHumanTaskUiResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a HumanTaskUi resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13287,71 +13142,71 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "HumanTaskUiName": self.human_task_ui_name, + 'HumanTaskUiName': self.human_task_ui_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_human_task_ui(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Active", "Deleting"], + target_status: Literal['Active', 'Deleting'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a HumanTaskUi resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for HumanTaskUi to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.human_task_ui_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="HumanTaskUi", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -13360,13 +13215,13 @@ def wait_for_delete( ) -> None: """ Wait for a HumanTaskUi resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13380,41 +13235,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for HumanTaskUi to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.human_task_ui_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="HumanTaskUi", status=current_status - ) + raise TimeoutExceededError(resouce_type="HumanTaskUi", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -13427,7 +13275,7 @@ def get_all( ) -> ResourceIterator["HumanTaskUi"]: """ Get all HumanTaskUi resources - + Parameters: creation_time_after: A filter that returns only human task user interfaces with a creation time greater than or equal to the specified timestamp. creation_time_before: A filter that returns only human task user interfaces that were created before the specified timestamp. @@ -13436,12 +13284,12 @@ def get_all( max_results: The total number of items to return. If the total number of available items is more than the value specified in MaxResults, then a NextToken will be provided in the output that you can use to resume pagination. session: Boto3 session. region: Region name. - + Returns: Iterator for listed HumanTaskUi resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13451,35 +13299,34 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_human_task_uis", - summaries_key="HumanTaskUiSummaries", - summary_name="HumanTaskUiSummary", + list_method='list_human_task_uis', + summaries_key='HumanTaskUiSummaries', + summary_name='HumanTaskUiSummary', resource_cls=HumanTaskUi, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class HyperParameterTuningJob(Base): """ Class representing resource HyperParameterTuningJob - + Attributes: hyper_parameter_tuning_job_name: The name of the hyperparameter tuning job. hyper_parameter_tuning_job_arn: The Amazon Resource Name (ARN) of the tuning job. @@ -13491,24 +13338,21 @@ class HyperParameterTuningJob(Base): training_job_definition: The HyperParameterTrainingJobDefinition object that specifies the definition of the training jobs that this tuning job launches. training_job_definitions: A list of the HyperParameterTrainingJobDefinition objects launched for this tuning job. hyper_parameter_tuning_end_time: The date and time that the tuning job ended. - last_modified_time: The date and time that the status of the tuning job was modified. + last_modified_time: The date and time that the status of the tuning job was modified. best_training_job: A TrainingJobSummary object that describes the training job that completed with the best current HyperParameterTuningJobObjective. overall_best_training_job: If the hyperparameter tuning job is an warm start tuning job with a WarmStartType of IDENTICAL_DATA_AND_ALGORITHM, this is the TrainingJobSummary for the training job with the best objective metric value of all training jobs launched by this tuning job and all parent jobs specified for the warm start tuning job. warm_start_config: The configuration for starting the hyperparameter parameter tuning job using one or more previous tuning jobs as a starting point. The results of previous tuning jobs are used to inform which combinations of hyperparameters to search over in the new tuning job. autotune: A flag to indicate if autotune is enabled for the hyperparameter tuning job. failure_reason: If the tuning job failed, the reason it failed. tuning_job_completion_details: Tuning job completion information returned as the response from a hyperparameter tuning job. This information tells if your tuning job has or has not converged. It also includes the number of training jobs that have not improved model performance as evaluated against the objective function. - consumed_resources: - + consumed_resources: + """ - hyper_parameter_tuning_job_name: str hyper_parameter_tuning_job_arn: Optional[str] = Unassigned() hyper_parameter_tuning_job_config: Optional[shapes.HyperParameterTuningJobConfig] = Unassigned() training_job_definition: Optional[shapes.HyperParameterTrainingJobDefinition] = Unassigned() - training_job_definitions: Optional[List[shapes.HyperParameterTrainingJobDefinition]] = ( - Unassigned() - ) + training_job_definitions: Optional[List[shapes.HyperParameterTrainingJobDefinition]] = Unassigned() hyper_parameter_tuning_job_status: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() hyper_parameter_tuning_end_time: Optional[datetime.datetime] = Unassigned() @@ -13520,57 +13364,77 @@ class HyperParameterTuningJob(Base): warm_start_config: Optional[shapes.HyperParameterTuningJobWarmStartConfig] = Unassigned() autotune: Optional[shapes.Autotune] = Unassigned() failure_reason: Optional[str] = Unassigned() - tuning_job_completion_details: Optional[shapes.HyperParameterTuningJobCompletionDetails] = ( - Unassigned() - ) + tuning_job_completion_details: Optional[shapes.HyperParameterTuningJobCompletionDetails] = Unassigned() consumed_resources: Optional[shapes.HyperParameterTuningJobConsumedResources] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "hyper_parameter_tuning_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'hyper_parameter_tuning_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object hyper_parameter_tuning_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "training_job_definition": { - "role_arn": {"type": "string"}, - "output_data_config": { - "s3_output_path": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, - "resource_config": {"volume_kms_key_id": {"type": "string"}}, - "hyper_parameter_tuning_resource_config": { - "volume_kms_key_id": {"type": "string"} - }, - "checkpoint_config": {"s3_uri": {"type": "string"}}, + config_schema_for_resource = \ + { + "training_job_definition": { + "role_arn": { + "type": "string" + }, + "output_data_config": { + "s3_output_path": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" } + } + }, + "resource_config": { + "volume_kms_key_id": { + "type": "string" + } + }, + "hyper_parameter_tuning_resource_config": { + "volume_kms_key_id": { + "type": "string" + } + }, + "checkpoint_config": { + "s3_uri": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "HyperParameterTuningJob", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "HyperParameterTuningJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -13578,12 +13442,8 @@ def create( cls, hyper_parameter_tuning_job_name: str, hyper_parameter_tuning_job_config: shapes.HyperParameterTuningJobConfig, - training_job_definition: Optional[ - shapes.HyperParameterTrainingJobDefinition - ] = Unassigned(), - training_job_definitions: Optional[ - List[shapes.HyperParameterTrainingJobDefinition] - ] = Unassigned(), + training_job_definition: Optional[shapes.HyperParameterTrainingJobDefinition] = Unassigned(), + training_job_definitions: Optional[List[shapes.HyperParameterTrainingJobDefinition]] = Unassigned(), warm_start_config: Optional[shapes.HyperParameterTuningJobWarmStartConfig] = Unassigned(), tags: Optional[List[shapes.Tag]] = Unassigned(), autotune: Optional[shapes.Autotune] = Unassigned(), @@ -13592,23 +13452,23 @@ def create( ) -> Optional["HyperParameterTuningJob"]: """ Create a HyperParameterTuningJob resource - + Parameters: hyper_parameter_tuning_job_name: The name of the tuning job. This name is the prefix for the names of all training jobs that this tuning job launches. The name must be unique within the same Amazon Web Services account and Amazon Web Services Region. The name must have 1 to 32 characters. Valid characters are a-z, A-Z, 0-9, and : + = @ _ % - (hyphen). The name is not case sensitive. hyper_parameter_tuning_job_config: The HyperParameterTuningJobConfig object that describes the tuning job, including the search strategy, the objective metric used to evaluate training jobs, ranges of parameters to search, and resource limits for the tuning job. For more information, see How Hyperparameter Tuning Works. training_job_definition: The HyperParameterTrainingJobDefinition object that describes the training jobs that this tuning job launches, including static hyperparameters, input data configuration, output data configuration, resource configuration, and stopping condition. training_job_definitions: A list of the HyperParameterTrainingJobDefinition objects launched for this tuning job. - warm_start_config: Specifies the configuration for starting the hyperparameter tuning job using one or more previous tuning jobs as a starting point. The results of previous tuning jobs are used to inform which combinations of hyperparameters to search over in the new tuning job. All training jobs launched by the new hyperparameter tuning job are evaluated by using the objective metric. If you specify IDENTICAL_DATA_AND_ALGORITHM as the WarmStartType value for the warm start configuration, the training job that performs the best in the new tuning job is compared to the best training jobs from the parent tuning jobs. From these, the training job that performs the best as measured by the objective metric is returned as the overall best training job. All training jobs launched by parent hyperparameter tuning jobs and the new hyperparameter tuning jobs count against the limit of training jobs for the tuning job. + warm_start_config: Specifies the configuration for starting the hyperparameter tuning job using one or more previous tuning jobs as a starting point. The results of previous tuning jobs are used to inform which combinations of hyperparameters to search over in the new tuning job. All training jobs launched by the new hyperparameter tuning job are evaluated by using the objective metric. If you specify IDENTICAL_DATA_AND_ALGORITHM as the WarmStartType value for the warm start configuration, the training job that performs the best in the new tuning job is compared to the best training jobs from the parent tuning jobs. From these, the training job that performs the best as measured by the objective metric is returned as the overall best training job. All training jobs launched by parent hyperparameter tuning jobs and the new hyperparameter tuning jobs count against the limit of training jobs for the tuning job. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. Tags that you specify for the tuning job are also added to all training jobs that the tuning job launches. - autotune: Configures SageMaker Automatic model tuning (AMT) to automatically find optimal parameters for the following fields: ParameterRanges: The names and ranges of parameters that a hyperparameter tuning job can optimize. ResourceLimits: The maximum resources that can be used for a training job. These resources include the maximum number of training jobs, the maximum runtime of a tuning job, and the maximum number of training jobs to run at the same time. TrainingJobEarlyStoppingType: A flag that specifies whether or not to use early stopping for training jobs launched by a hyperparameter tuning job. RetryStrategy: The number of times to retry a training job. Strategy: Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to use for the training jobs that it launches. ConvergenceDetected: A flag to indicate that Automatic model tuning (AMT) has detected model convergence. + autotune: Configures SageMaker Automatic model tuning (AMT) to automatically find optimal parameters for the following fields: ParameterRanges: The names and ranges of parameters that a hyperparameter tuning job can optimize. ResourceLimits: The maximum resources that can be used for a training job. These resources include the maximum number of training jobs, the maximum runtime of a tuning job, and the maximum number of training jobs to run at the same time. TrainingJobEarlyStoppingType: A flag that specifies whether or not to use early stopping for training jobs launched by a hyperparameter tuning job. RetryStrategy: The number of times to retry a training job. Strategy: Specifies how hyperparameter tuning chooses the combinations of hyperparameter values to use for the training jobs that it launches. ConvergenceDetected: A flag to indicate that Automatic model tuning (AMT) has detected model convergence. session: Boto3 session. region: Region name. - + Returns: The HyperParameterTuningJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13623,41 +13483,33 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating hyper_parameter_tuning_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "HyperParameterTuningJobName": hyper_parameter_tuning_job_name, - "HyperParameterTuningJobConfig": hyper_parameter_tuning_job_config, - "TrainingJobDefinition": training_job_definition, - "TrainingJobDefinitions": training_job_definitions, - "WarmStartConfig": warm_start_config, - "Tags": tags, - "Autotune": autotune, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="HyperParameterTuningJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'HyperParameterTuningJobName': hyper_parameter_tuning_job_name, + 'HyperParameterTuningJobConfig': hyper_parameter_tuning_job_config, + 'TrainingJobDefinition': training_job_definition, + 'TrainingJobDefinitions': training_job_definitions, + 'WarmStartConfig': warm_start_config, + 'Tags': tags, + 'Autotune': autotune, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='HyperParameterTuningJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_hyper_parameter_tuning_job(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - hyper_parameter_tuning_job_name=hyper_parameter_tuning_job_name, - session=session, - region=region, - ) - + + return cls.get(hyper_parameter_tuning_job_name=hyper_parameter_tuning_job_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -13668,17 +13520,17 @@ def get( ) -> Optional["HyperParameterTuningJob"]: """ Get a HyperParameterTuningJob resource - + Parameters: hyper_parameter_tuning_job_name: The name of the tuning job. session: Boto3 session. region: Region name. - + Returns: The HyperParameterTuningJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13689,38 +13541,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HyperParameterTuningJobName": hyper_parameter_tuning_job_name, + 'HyperParameterTuningJobName': hyper_parameter_tuning_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_hyper_parameter_tuning_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeHyperParameterTuningJobResponse") + transformed_response = transform(response, 'DescribeHyperParameterTuningJobResponse') hyper_parameter_tuning_job = cls(**transformed_response) return hyper_parameter_tuning_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["HyperParameterTuningJob"]: + + ) -> Optional["HyperParameterTuningJob"]: """ Refresh a HyperParameterTuningJob resource - + Returns: The HyperParameterTuningJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13731,30 +13582,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "HyperParameterTuningJobName": self.hyper_parameter_tuning_job_name, + 'HyperParameterTuningJobName': self.hyper_parameter_tuning_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_hyper_parameter_tuning_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeHyperParameterTuningJobResponse", self) + transform(response, 'DescribeHyperParameterTuningJobResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a HyperParameterTuningJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13764,27 +13616,27 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "HyperParameterTuningJobName": self.hyper_parameter_tuning_job_name, + 'HyperParameterTuningJobName': self.hyper_parameter_tuning_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_hyper_parameter_tuning_job(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def stop(self) -> None: """ Stop a HyperParameterTuningJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13795,81 +13647,77 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "HyperParameterTuningJobName": self.hyper_parameter_tuning_job_name, + 'HyperParameterTuningJobName': self.hyper_parameter_tuning_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_hyper_parameter_tuning_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a HyperParameterTuningJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed", "Stopped", "DeleteFailed"] + terminal_states = ['Completed', 'Failed', 'Stopped', 'DeleteFailed'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for HyperParameterTuningJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.hyper_parameter_tuning_job_status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="HyperParameterTuningJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="HyperParameterTuningJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="HyperParameterTuningJob", status=current_status - ) + raise TimeoutExceededError(resouce_type="HyperParameterTuningJob", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -13878,13 +13726,13 @@ def wait_for_delete( ) -> None: """ Wait for a HyperParameterTuningJob resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13898,41 +13746,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for HyperParameterTuningJob to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.hyper_parameter_tuning_job_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="HyperParameterTuningJob", status=current_status - ) + raise TimeoutExceededError(resouce_type="HyperParameterTuningJob", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -13950,7 +13791,7 @@ def get_all( ) -> ResourceIterator["HyperParameterTuningJob"]: """ Get all HyperParameterTuningJob resources - + Parameters: next_token: If the result of the previous ListHyperParameterTuningJobs request was truncated, the response includes a NextToken. To retrieve the next set of tuning jobs, use the token in the next request. max_results: The maximum number of tuning jobs to return. The default value is 10. @@ -13964,12 +13805,12 @@ def get_all( status_equals: A filter that returns only tuning jobs with the specified status. session: Boto3 session. region: Region name. - + Returns: Iterator for listed HyperParameterTuningJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -13979,47 +13820,46 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "StatusEquals": status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'StatusEquals': status_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_hyper_parameter_tuning_jobs", - summaries_key="HyperParameterTuningJobSummaries", - summary_name="HyperParameterTuningJobSummary", + list_method='list_hyper_parameter_tuning_jobs', + summaries_key='HyperParameterTuningJobSummaries', + summary_name='HyperParameterTuningJobSummary', resource_cls=HyperParameterTuningJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_training_jobs( self, status_equals: Optional[str] = Unassigned(), sort_by: Optional[str] = Unassigned(), - sort_order: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_order: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.HyperParameterTrainingJobSummary]: """ Gets a list of TrainingJobSummary objects that describe the training jobs that a hyperparameter tuning job launched. - + Parameters: next_token: If the result of the previous ListTrainingJobsForHyperParameterTuningJob request was truncated, the response includes a NextToken. To retrieve the next set of training jobs, use the token in the next request. max_results: The maximum number of training jobs to return. The default value is 10. @@ -14028,12 +13868,12 @@ def get_all_training_jobs( sort_order: The sort order for results. The default is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed HyperParameterTrainingJobSummary. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14044,35 +13884,35 @@ def get_all_training_jobs( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "HyperParameterTuningJobName": self.hyper_parameter_tuning_job_name, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, + 'HyperParameterTuningJobName': self.hyper_parameter_tuning_job_name, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_training_jobs_for_hyper_parameter_tuning_job", - summaries_key="TrainingJobSummaries", - summary_name="HyperParameterTrainingJobSummary", + list_method='list_training_jobs_for_hyper_parameter_tuning_job', + summaries_key='TrainingJobSummaries', + summary_name='HyperParameterTrainingJobSummary', resource_cls=shapes.HyperParameterTrainingJobSummary, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Image(Base): """ Class representing resource Image - + Attributes: creation_time: When the image was created. description: The description of the image. @@ -14083,9 +13923,8 @@ class Image(Base): image_status: The status of the image. last_modified_time: When the image was last modified. role_arn: The ARN of the IAM role that enables Amazon SageMaker AI to perform tasks on your behalf. - + """ - image_name: str creation_time: Optional[datetime.datetime] = Unassigned() description: Optional[str] = Unassigned() @@ -14095,36 +13934,36 @@ class Image(Base): image_status: Optional[str] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() role_arn: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "image_name" - resource_name_split = resource_name.split("_") + resource_name = 'image_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object image") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = {"role_arn": {"type": "string"}} - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Image", **kwargs - ), - ) - + config_schema_for_resource = \ + { + "role_arn": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Image", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -14140,7 +13979,7 @@ def create( ) -> Optional["Image"]: """ Create a Image resource - + Parameters: image_name: The name of the image. Must be unique to your account. role_arn: The ARN of an IAM role that enables Amazon SageMaker AI to perform tasks on your behalf. @@ -14149,12 +13988,12 @@ def create( tags: A list of tags to apply to the image. session: Boto3 session. region: Region name. - + Returns: The Image resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14169,35 +14008,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating image resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "Description": description, - "DisplayName": display_name, - "ImageName": image_name, - "RoleArn": role_arn, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Image", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'Description': description, + 'DisplayName': display_name, + 'ImageName': image_name, + 'RoleArn': role_arn, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Image', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_image(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(image_name=image_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -14208,17 +14043,17 @@ def get( ) -> Optional["Image"]: """ Get a Image resource - + Parameters: image_name: The name of the image to describe. session: Boto3 session. region: Region name. - + Returns: The Image resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14229,38 +14064,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ImageName": image_name, + 'ImageName': image_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_image(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeImageResponse") + transformed_response = transform(response, 'DescribeImageResponse') image = cls(**transformed_response) return image - + @Base.add_validate_call def refresh( self, - ) -> Optional["Image"]: + + ) -> Optional["Image"]: """ Refresh a Image resource - + Returns: The Image resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14271,21 +14105,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ImageName": self.image_name, + 'ImageName': self.image_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_image(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeImageResponse", self) + transform(response, 'DescribeImageResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -14297,15 +14131,15 @@ def update( ) -> Optional["Image"]: """ Update a Image resource - + Parameters: delete_properties: A list of properties to delete. Only the Description and DisplayName properties can be deleted. - + Returns: The Image resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14317,38 +14151,39 @@ def update( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating image resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "DeleteProperties": delete_properties, - "Description": description, - "DisplayName": display_name, - "ImageName": self.image_name, - "RoleArn": role_arn, + 'DeleteProperties': delete_properties, + 'Description': description, + 'DisplayName': display_name, + 'ImageName': self.image_name, + 'RoleArn': role_arn, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_image(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Image resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14360,84 +14195,74 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ImageName": self.image_name, + 'ImageName': self.image_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_image(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "CREATING", - "CREATED", - "CREATE_FAILED", - "UPDATING", - "UPDATE_FAILED", - "DELETING", - "DELETE_FAILED", - ], + target_status: Literal['CREATING', 'CREATED', 'CREATE_FAILED', 'UPDATING', 'UPDATE_FAILED', 'DELETING', 'DELETE_FAILED'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Image resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Image to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.image_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Image", status=current_status, reason=self.failure_reason - ) - + raise FailedStatusError(resource_type="Image", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Image", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -14446,13 +14271,13 @@ def wait_for_delete( ) -> None: """ Wait for a Image resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14466,47 +14291,37 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Image to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.image_status status.update(f"Current status: [bold]{current_status}") - - if ( - "delete_failed" in current_status.lower() - or "deletefailed" in current_status.lower() - ): - raise DeleteFailedStatusError( - resource_type="Image", reason=self.failure_reason - ) - + + if "delete_failed" in current_status.lower() or "deletefailed" in current_status.lower(): + raise DeleteFailedStatusError(resource_type="Image", reason=self.failure_reason) + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Image", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -14523,25 +14338,25 @@ def get_all( ) -> ResourceIterator["Image"]: """ Get all Image resources - + Parameters: creation_time_after: A filter that returns only images created on or after the specified time. creation_time_before: A filter that returns only images created on or before the specified time. last_modified_time_after: A filter that returns only images modified on or after the specified time. last_modified_time_before: A filter that returns only images modified on or before the specified time. - max_results: The maximum number of images to return in the response. The default value is 10. + max_results: The maximum number of images to return in the response. The default value is 10. name_contains: A filter that returns only images whose name contains the specified string. next_token: If the previous call to ListImages didn't return the full set of images, the call returns a token for getting the next set of images. sort_by: The property used to sort results. The default value is CREATION_TIME. sort_order: The sort order. The default value is DESCENDING. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Image resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14551,45 +14366,44 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_images", - summaries_key="Images", - summary_name="Image", + list_method='list_images', + summaries_key='Images', + summary_name='Image', resource_cls=Image, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_aliases( self, alias: Optional[str] = Unassigned(), - version: Optional[int] = Unassigned(), - session: Optional[Session] = None, + version: Optional[int] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[str]: """ Lists the aliases of a specified image or image version. - + Parameters: alias: The alias of the image version. version: The version of the image. If image version is not specified, the aliases of all versions of the image are listed. @@ -14597,12 +14411,12 @@ def get_all_aliases( next_token: If the previous call to ListAliases didn't return the full set of aliases, the call returns a token for retrieving the next set of aliases. session: Boto3 session. region: Region name. - + Returns: Iterator for listed str. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14613,34 +14427,34 @@ def get_all_aliases( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "ImageName": self.image_name, - "Alias": alias, - "Version": version, + 'ImageName': self.image_name, + 'Alias': alias, + 'Version': version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_aliases", - summaries_key="SageMakerImageVersionAliases", - summary_name="SageMakerImageVersionAlias", + list_method='list_aliases', + summaries_key='SageMakerImageVersionAliases', + summary_name='SageMakerImageVersionAlias', resource_cls=str, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ImageVersion(Base): """ Class representing resource ImageVersion - + Attributes: base_image: The registry path of the container image on which this image version is based. container_image: The registry path of the container image that contains this image version. @@ -14651,16 +14465,15 @@ class ImageVersion(Base): image_version_status: The status of the version. last_modified_time: When the version was last modified. version: The version number. - vendor_guidance: The stability of the image version specified by the maintainer. NOT_PROVIDED: The maintainers did not provide a status for image version stability. STABLE: The image version is stable. TO_BE_ARCHIVED: The image version is set to be archived. Custom image versions that are set to be archived are automatically archived after three months. ARCHIVED: The image version is archived. Archived image versions are not searchable and are no longer actively supported. - job_type: Indicates SageMaker AI job type compatibility. TRAINING: The image version is compatible with SageMaker AI training jobs. INFERENCE: The image version is compatible with SageMaker AI inference jobs. NOTEBOOK_KERNEL: The image version is compatible with SageMaker AI notebook kernels. + vendor_guidance: The stability of the image version specified by the maintainer. NOT_PROVIDED: The maintainers did not provide a status for image version stability. STABLE: The image version is stable. TO_BE_ARCHIVED: The image version is set to be archived. Custom image versions that are set to be archived are automatically archived after three months. ARCHIVED: The image version is archived. Archived image versions are not searchable and are no longer actively supported. + job_type: Indicates SageMaker AI job type compatibility. TRAINING: The image version is compatible with SageMaker AI training jobs. INFERENCE: The image version is compatible with SageMaker AI inference jobs. NOTEBOOK_KERNEL: The image version is compatible with SageMaker AI notebook kernels. ml_framework: The machine learning framework vended in the image version. programming_lang: The supported programming language and its version. - processor: Indicates CPU or GPU compatibility. CPU: The image version is compatible with CPU. GPU: The image version is compatible with GPU. + processor: Indicates CPU or GPU compatibility. CPU: The image version is compatible with CPU. GPU: The image version is compatible with GPU. horovod: Indicates Horovod compatibility. release_notes: The maintainer description of the image version. - + """ - image_name: str base_image: Optional[str] = Unassigned() container_image: Optional[str] = Unassigned() @@ -14678,23 +14491,23 @@ class ImageVersion(Base): processor: Optional[str] = Unassigned() horovod: Optional[bool] = Unassigned() release_notes: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "image_version_name" - resource_name_split = resource_name.split("_") + resource_name = 'image_version_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object image_version") return None - + @classmethod @Base.add_validate_call def create( @@ -14715,27 +14528,27 @@ def create( ) -> Optional["ImageVersion"]: """ Create a ImageVersion resource - + Parameters: - base_image: The registry path of the container image to use as the starting point for this version. The path is an Amazon ECR URI in the following format: <acct-id>.dkr.ecr.<region>.amazonaws.com/<repo-name[:tag] or [@digest]> + base_image: The registry path of the container image to use as the starting point for this version. The path is an Amazon ECR URI in the following format: <acct-id>.dkr.ecr.<region>.amazonaws.com/<repo-name[:tag] or [@digest]> client_token: A unique ID. If not specified, the Amazon Web Services CLI and Amazon Web Services SDKs, such as the SDK for Python (Boto3), add a unique value to the call. image_name: The ImageName of the Image to create a version of. aliases: A list of aliases created with the image version. - vendor_guidance: The stability of the image version, specified by the maintainer. NOT_PROVIDED: The maintainers did not provide a status for image version stability. STABLE: The image version is stable. TO_BE_ARCHIVED: The image version is set to be archived. Custom image versions that are set to be archived are automatically archived after three months. ARCHIVED: The image version is archived. Archived image versions are not searchable and are no longer actively supported. - job_type: Indicates SageMaker AI job type compatibility. TRAINING: The image version is compatible with SageMaker AI training jobs. INFERENCE: The image version is compatible with SageMaker AI inference jobs. NOTEBOOK_KERNEL: The image version is compatible with SageMaker AI notebook kernels. + vendor_guidance: The stability of the image version, specified by the maintainer. NOT_PROVIDED: The maintainers did not provide a status for image version stability. STABLE: The image version is stable. TO_BE_ARCHIVED: The image version is set to be archived. Custom image versions that are set to be archived are automatically archived after three months. ARCHIVED: The image version is archived. Archived image versions are not searchable and are no longer actively supported. + job_type: Indicates SageMaker AI job type compatibility. TRAINING: The image version is compatible with SageMaker AI training jobs. INFERENCE: The image version is compatible with SageMaker AI inference jobs. NOTEBOOK_KERNEL: The image version is compatible with SageMaker AI notebook kernels. ml_framework: The machine learning framework vended in the image version. programming_lang: The supported programming language and its version. - processor: Indicates CPU or GPU compatibility. CPU: The image version is compatible with CPU. GPU: The image version is compatible with GPU. + processor: Indicates CPU or GPU compatibility. CPU: The image version is compatible with CPU. GPU: The image version is compatible with GPU. horovod: Indicates Horovod compatibility. release_notes: The maintainer description of the image version. session: Boto3 session. region: Region name. - + Returns: The ImageVersion resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14751,41 +14564,37 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating image_version resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "BaseImage": base_image, - "ClientToken": client_token, - "ImageName": image_name, - "Aliases": aliases, - "VendorGuidance": vendor_guidance, - "JobType": job_type, - "MLFramework": ml_framework, - "ProgrammingLang": programming_lang, - "Processor": processor, - "Horovod": horovod, - "ReleaseNotes": release_notes, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ImageVersion", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'BaseImage': base_image, + 'ClientToken': client_token, + 'ImageName': image_name, + 'Aliases': aliases, + 'VendorGuidance': vendor_guidance, + 'JobType': job_type, + 'MLFramework': ml_framework, + 'ProgrammingLang': programming_lang, + 'Processor': processor, + 'Horovod': horovod, + 'ReleaseNotes': release_notes, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ImageVersion', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_image_version(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(image_name=image_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -14798,19 +14607,19 @@ def get( ) -> Optional["ImageVersion"]: """ Get a ImageVersion resource - + Parameters: image_name: The name of the image. version: The version of the image. If not specified, the latest version is described. alias: The alias of the image version. session: Boto3 session. region: Region name. - + Returns: The ImageVersion resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14821,41 +14630,39 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ImageName": image_name, - "Version": version, - "Alias": alias, + 'ImageName': image_name, + 'Version': version, + 'Alias': alias, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_image_version(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeImageVersionResponse") + transformed_response = transform(response, 'DescribeImageVersionResponse') image_version = cls(**transformed_response) return image_version - + @Base.add_validate_call def refresh( self, - alias: Optional[str] = Unassigned(), - ) -> Optional["ImageVersion"]: + alias: Optional[str] = Unassigned(), + ) -> Optional["ImageVersion"]: """ Refresh a ImageVersion resource - + Returns: The ImageVersion resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14866,23 +14673,23 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ImageName": self.image_name, - "Version": self.version, - "Alias": alias, + 'ImageName': self.image_name, + 'Version': self.version, + 'Alias': alias, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_image_version(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeImageVersionResponse", self) + transform(response, 'DescribeImageVersionResponse', self) return self - + @Base.add_validate_call def update( self, @@ -14900,17 +14707,17 @@ def update( ) -> Optional["ImageVersion"]: """ Update a ImageVersion resource - + Parameters: alias: The alias of the image version. aliases_to_add: A list of aliases to add. aliases_to_delete: A list of aliases to delete. - + Returns: The ImageVersion resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14922,46 +14729,46 @@ def update( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating image_version resource.") client = Base.get_sagemaker_client() - - operation_input_args = { - "ImageName": self.image_name, - "Alias": alias, - "Version": version, - "AliasesToAdd": aliases_to_add, - "AliasesToDelete": aliases_to_delete, - "VendorGuidance": vendor_guidance, - "JobType": job_type, - "MLFramework": ml_framework, - "ProgrammingLang": programming_lang, - "Processor": processor, - "Horovod": horovod, - "ReleaseNotes": release_notes, + + operation_input_args = { + 'ImageName': self.image_name, + 'Alias': alias, + 'Version': version, + 'AliasesToAdd': aliases_to_add, + 'AliasesToDelete': aliases_to_delete, + 'VendorGuidance': vendor_guidance, + 'JobType': job_type, + 'MLFramework': ml_framework, + 'ProgrammingLang': programming_lang, + 'Processor': processor, + 'Horovod': horovod, + 'ReleaseNotes': release_notes, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_image_version(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, alias: Optional[str] = Unassigned(), - ) -> None: + ) -> None: """ Delete a ImageVersion resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -14973,80 +14780,76 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ImageName": self.image_name, - "Version": self.version, - "Alias": alias, + 'ImageName': self.image_name, + 'Version': self.version, + 'Alias': alias, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_image_version(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["CREATING", "CREATED", "CREATE_FAILED", "DELETING", "DELETE_FAILED"], + target_status: Literal['CREATING', 'CREATED', 'CREATE_FAILED', 'DELETING', 'DELETE_FAILED'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a ImageVersion resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for ImageVersion to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.image_version_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="ImageVersion", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="ImageVersion", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="ImageVersion", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -15055,13 +14858,13 @@ def wait_for_delete( ) -> None: """ Wait for a ImageVersion resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15075,49 +14878,37 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for ImageVersion to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.image_version_status status.update(f"Current status: [bold]{current_status}") - - if ( - "delete_failed" in current_status.lower() - or "deletefailed" in current_status.lower() - ): - raise DeleteFailedStatusError( - resource_type="ImageVersion", reason=self.failure_reason - ) - + + if "delete_failed" in current_status.lower() or "deletefailed" in current_status.lower(): + raise DeleteFailedStatusError(resource_type="ImageVersion", reason=self.failure_reason) + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ImageVersion", status=current_status - ) + raise TimeoutExceededError(resouce_type="ImageVersion", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -15134,25 +14925,25 @@ def get_all( ) -> ResourceIterator["ImageVersion"]: """ Get all ImageVersion resources - + Parameters: image_name: The name of the image to list the versions of. creation_time_after: A filter that returns only versions created on or after the specified time. creation_time_before: A filter that returns only versions created on or before the specified time. last_modified_time_after: A filter that returns only versions modified on or after the specified time. last_modified_time_before: A filter that returns only versions modified on or before the specified time. - max_results: The maximum number of versions to return in the response. The default value is 10. + max_results: The maximum number of versions to return in the response. The default value is 10. next_token: If the previous call to ListImageVersions didn't return the full set of versions, the call returns a token for getting the next set of versions. sort_by: The property used to sort results. The default value is CREATION_TIME. sort_order: The sort order. The default value is DESCENDING. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ImageVersion resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15163,41 +14954,39 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "ImageName": image_name, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'ImageName': image_name, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } extract_name_mapping = {"image_version_arn": ["image-version/", "image_name"]} - + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_image_versions", - summaries_key="ImageVersions", - summary_name="ImageVersion", + list_method='list_image_versions', + summaries_key='ImageVersions', + summary_name='ImageVersion', resource_cls=ImageVersion, extract_name_mapping=extract_name_mapping, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class InferenceComponent(Base): """ Class representing resource InferenceComponent - + Attributes: inference_component_name: The name of the inference component. inference_component_arn: The Amazon Resource Name (ARN) of the inference component. @@ -15211,9 +15000,8 @@ class InferenceComponent(Base): runtime_config: Details about the runtime settings for the model that is deployed with the inference component. inference_component_status: The status of the inference component. last_deployment_config: The deployment and rollback settings that you assigned to the inference component. - + """ - inference_component_name: str inference_component_arn: Optional[str] = Unassigned() endpoint_name: Optional[str] = Unassigned() @@ -15226,23 +15014,23 @@ class InferenceComponent(Base): last_modified_time: Optional[datetime.datetime] = Unassigned() inference_component_status: Optional[str] = Unassigned() last_deployment_config: Optional[shapes.InferenceComponentDeploymentConfig] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "inference_component_name" - resource_name_split = resource_name.split("_") + resource_name = 'inference_component_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object inference_component") return None - + @classmethod @Base.add_validate_call def create( @@ -15258,7 +15046,7 @@ def create( ) -> Optional["InferenceComponent"]: """ Create a InferenceComponent resource - + Parameters: inference_component_name: A unique name to assign to the inference component. endpoint_name: The name of an existing endpoint where you host the inference component. @@ -15268,12 +15056,12 @@ def create( tags: A list of key-value pairs associated with the model. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference. session: Boto3 session. region: Region name. - + Returns: The InferenceComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15287,38 +15075,32 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating inference_component resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "InferenceComponentName": inference_component_name, - "EndpointName": endpoint_name, - "VariantName": variant_name, - "Specification": specification, - "RuntimeConfig": runtime_config, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="InferenceComponent", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'InferenceComponentName': inference_component_name, + 'EndpointName': endpoint_name, + 'VariantName': variant_name, + 'Specification': specification, + 'RuntimeConfig': runtime_config, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='InferenceComponent', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_inference_component(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - inference_component_name=inference_component_name, session=session, region=region - ) - + + return cls.get(inference_component_name=inference_component_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -15329,17 +15111,17 @@ def get( ) -> Optional["InferenceComponent"]: """ Get a InferenceComponent resource - + Parameters: inference_component_name: The name of the inference component. session: Boto3 session. region: Region name. - + Returns: The InferenceComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15349,38 +15131,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "InferenceComponentName": inference_component_name, + 'InferenceComponentName': inference_component_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_inference_component(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeInferenceComponentOutput") + transformed_response = transform(response, 'DescribeInferenceComponentOutput') inference_component = cls(**transformed_response) return inference_component - + @Base.add_validate_call def refresh( self, - ) -> Optional["InferenceComponent"]: + + ) -> Optional["InferenceComponent"]: """ Refresh a InferenceComponent resource - + Returns: The InferenceComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15390,21 +15171,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "InferenceComponentName": self.inference_component_name, + 'InferenceComponentName': self.inference_component_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_inference_component(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeInferenceComponentOutput", self) + transform(response, 'DescribeInferenceComponentOutput', self) return self - + @Base.add_validate_call def update( self, @@ -15414,15 +15195,15 @@ def update( ) -> Optional["InferenceComponent"]: """ Update a InferenceComponent resource - + Parameters: deployment_config: The deployment configuration for the inference component. The configuration contains the desired deployment strategy and rollback settings. - + Returns: The InferenceComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15433,37 +15214,38 @@ def update( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + logger.info("Updating inference_component resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "InferenceComponentName": self.inference_component_name, - "Specification": specification, - "RuntimeConfig": runtime_config, - "DeploymentConfig": deployment_config, + 'InferenceComponentName': self.inference_component_name, + 'Specification': specification, + 'RuntimeConfig': runtime_config, + 'DeploymentConfig': deployment_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_inference_component(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a InferenceComponent resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15473,82 +15255,74 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "InferenceComponentName": self.inference_component_name, + 'InferenceComponentName': self.inference_component_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_inference_component(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["InService", "Creating", "Updating", "Failed", "Deleting"], + target_status: Literal['InService', 'Creating', 'Updating', 'Failed', 'Deleting'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a InferenceComponent resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) - progress.add_task( - f"Waiting for InferenceComponent to reach [bold]{target_status} status..." - ) + progress.add_task(f"Waiting for InferenceComponent to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.inference_component_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="InferenceComponent", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="InferenceComponent", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="InferenceComponent", status=current_status - ) + raise TimeoutExceededError(resouce_type="InferenceComponent", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -15557,13 +15331,13 @@ def wait_for_delete( ) -> None: """ Wait for a InferenceComponent resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15577,41 +15351,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for InferenceComponent to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.inference_component_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="InferenceComponent", status=current_status - ) + raise TimeoutExceededError(resouce_type="InferenceComponent", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -15631,7 +15398,7 @@ def get_all( ) -> ResourceIterator["InferenceComponent"]: """ Get all InferenceComponent resources - + Parameters: sort_by: The field by which to sort the inference components in the response. The default is CreationTime. sort_order: The sort order for results. The default is Descending. @@ -15647,12 +15414,12 @@ def get_all( variant_name_equals: A production variant name to filter the listed inference components. The response includes only those inference components that are hosted at the specified variant. session: Boto3 session. region: Region name. - + Returns: Iterator for listed InferenceComponent resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15662,37 +15429,37 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "StatusEquals": status_equals, - "EndpointNameEquals": endpoint_name_equals, - "VariantNameEquals": variant_name_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'StatusEquals': status_equals, + 'EndpointNameEquals': endpoint_name_equals, + 'VariantNameEquals': variant_name_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_inference_components", - summaries_key="InferenceComponents", - summary_name="InferenceComponentSummary", + list_method='list_inference_components', + summaries_key='InferenceComponents', + summary_name='InferenceComponentSummary', resource_cls=InferenceComponent, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def update_runtime_configs( self, @@ -15702,14 +15469,14 @@ def update_runtime_configs( ) -> None: """ Runtime settings for a model that is deployed with an inference component. - + Parameters: desired_runtime_config: Runtime settings for a model that is deployed with an inference component. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15720,48 +15487,47 @@ def update_runtime_configs( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + + operation_input_args = { - "InferenceComponentName": self.inference_component_name, - "DesiredRuntimeConfig": desired_runtime_config, + 'InferenceComponentName': self.inference_component_name, + 'DesiredRuntimeConfig': desired_runtime_config, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling update_inference_component_runtime_config API") response = client.update_inference_component_runtime_config(**operation_input_args) logger.debug(f"Response: {response}") + class InferenceExperiment(Base): """ Class representing resource InferenceExperiment - + Attributes: arn: The ARN of the inference experiment being described. name: The name of the inference experiment. type: The type of the inference experiment. - status: The status of the inference experiment. The following are the possible statuses for an inference experiment: Creating - Amazon SageMaker is creating your experiment. Created - Amazon SageMaker has finished the creation of your experiment and will begin the experiment at the scheduled time. Updating - When you make changes to your experiment, your experiment shows as updating. Starting - Amazon SageMaker is beginning your experiment. Running - Your experiment is in progress. Stopping - Amazon SageMaker is stopping your experiment. Completed - Your experiment has completed. Cancelled - When you conclude your experiment early using the StopInferenceExperiment API, or if any operation fails with an unexpected error, it shows as cancelled. + status: The status of the inference experiment. The following are the possible statuses for an inference experiment: Creating - Amazon SageMaker is creating your experiment. Created - Amazon SageMaker has finished the creation of your experiment and will begin the experiment at the scheduled time. Updating - When you make changes to your experiment, your experiment shows as updating. Starting - Amazon SageMaker is beginning your experiment. Running - Your experiment is in progress. Stopping - Amazon SageMaker is stopping your experiment. Completed - Your experiment has completed. Cancelled - When you conclude your experiment early using the StopInferenceExperiment API, or if any operation fails with an unexpected error, it shows as cancelled. endpoint_metadata: The metadata of the endpoint on which the inference experiment ran. - model_variants: An array of ModelVariantConfigSummary objects. There is one for each variant in the inference experiment. Each ModelVariantConfigSummary object in the array describes the infrastructure configuration for deploying the corresponding variant. + model_variants: An array of ModelVariantConfigSummary objects. There is one for each variant in the inference experiment. Each ModelVariantConfigSummary object in the array describes the infrastructure configuration for deploying the corresponding variant. schedule: The duration for which the inference experiment ran or will run. - status_reason: The error message or client-specified Reason from the StopInferenceExperiment API, that explains the status of the inference experiment. + status_reason: The error message or client-specified Reason from the StopInferenceExperiment API, that explains the status of the inference experiment. description: The description of the inference experiment. creation_time: The timestamp at which you created the inference experiment. - completion_time: The timestamp at which the inference experiment was completed. + completion_time: The timestamp at which the inference experiment was completed. last_modified_time: The timestamp at which you last modified the inference experiment. - role_arn: The ARN of the IAM role that Amazon SageMaker can assume to access model artifacts and container images, and manage Amazon SageMaker Inference endpoints for model deployment. + role_arn: The ARN of the IAM role that Amazon SageMaker can assume to access model artifacts and container images, and manage Amazon SageMaker Inference endpoints for model deployment. data_storage_config: The Amazon S3 location and configuration for storing inference request and response data. - shadow_mode_config: The configuration of ShadowMode inference experiment type, which shows the production variant that takes all the inference requests, and the shadow variant to which Amazon SageMaker replicates a percentage of the inference requests. For the shadow variant it also shows the percentage of requests that Amazon SageMaker replicates. - kms_key: The Amazon Web Services Key Management Service (Amazon Web Services KMS) key that Amazon SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. For more information, see CreateInferenceExperiment. - + shadow_mode_config: The configuration of ShadowMode inference experiment type, which shows the production variant that takes all the inference requests, and the shadow variant to which Amazon SageMaker replicates a percentage of the inference requests. For the shadow variant it also shows the percentage of requests that Amazon SageMaker replicates. + kms_key: The Amazon Web Services Key Management Service (Amazon Web Services KMS) key that Amazon SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. For more information, see CreateInferenceExperiment. + """ - name: str arn: Optional[str] = Unassigned() type: Optional[str] = Unassigned() @@ -15778,40 +15544,44 @@ class InferenceExperiment(Base): data_storage_config: Optional[shapes.InferenceExperimentDataStorageConfig] = Unassigned() shadow_mode_config: Optional[shapes.ShadowModeConfig] = Unassigned() kms_key: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "inference_experiment_name" - resource_name_split = resource_name.split("_") + resource_name = 'inference_experiment_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object inference_experiment") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "role_arn": {"type": "string"}, - "data_storage_config": {"kms_key": {"type": "string"}}, - "kms_key": {"type": "string"}, + config_schema_for_resource = \ + { + "role_arn": { + "type": "string" + }, + "data_storage_config": { + "kms_key": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "InferenceExperiment", **kwargs - ), - ) - + }, + "kms_key": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "InferenceExperiment", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -15833,27 +15603,27 @@ def create( ) -> Optional["InferenceExperiment"]: """ Create a InferenceExperiment resource - + Parameters: name: The name for the inference experiment. - type: The type of the inference experiment that you want to run. The following types of experiments are possible: ShadowMode: You can use this type to validate a shadow variant. For more information, see Shadow tests. - role_arn: The ARN of the IAM role that Amazon SageMaker can assume to access model artifacts and container images, and manage Amazon SageMaker Inference endpoints for model deployment. - endpoint_name: The name of the Amazon SageMaker endpoint on which you want to run the inference experiment. - model_variants: An array of ModelVariantConfig objects. There is one for each variant in the inference experiment. Each ModelVariantConfig object in the array describes the infrastructure configuration for the corresponding variant. - shadow_mode_config: The configuration of ShadowMode inference experiment type. Use this field to specify a production variant which takes all the inference requests, and a shadow variant to which Amazon SageMaker replicates a percentage of the inference requests. For the shadow variant also specify the percentage of requests that Amazon SageMaker replicates. - schedule: The duration for which you want the inference experiment to run. If you don't specify this field, the experiment automatically starts immediately upon creation and concludes after 7 days. + type: The type of the inference experiment that you want to run. The following types of experiments are possible: ShadowMode: You can use this type to validate a shadow variant. For more information, see Shadow tests. + role_arn: The ARN of the IAM role that Amazon SageMaker can assume to access model artifacts and container images, and manage Amazon SageMaker Inference endpoints for model deployment. + endpoint_name: The name of the Amazon SageMaker endpoint on which you want to run the inference experiment. + model_variants: An array of ModelVariantConfig objects. There is one for each variant in the inference experiment. Each ModelVariantConfig object in the array describes the infrastructure configuration for the corresponding variant. + shadow_mode_config: The configuration of ShadowMode inference experiment type. Use this field to specify a production variant which takes all the inference requests, and a shadow variant to which Amazon SageMaker replicates a percentage of the inference requests. For the shadow variant also specify the percentage of requests that Amazon SageMaker replicates. + schedule: The duration for which you want the inference experiment to run. If you don't specify this field, the experiment automatically starts immediately upon creation and concludes after 7 days. description: A description for the inference experiment. - data_storage_config: The Amazon S3 location and configuration for storing inference request and response data. This is an optional parameter that you can use for data capture. For more information, see Capture data. - kms_key: The Amazon Web Services Key Management Service (Amazon Web Services KMS) key that Amazon SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. The KmsKey can be any of the following formats: KMS key ID "1234abcd-12ab-34cd-56ef-1234567890ab" Amazon Resource Name (ARN) of a KMS key "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" KMS key Alias "alias/ExampleAlias" Amazon Resource Name (ARN) of a KMS key Alias "arn:aws:kms:us-west-2:111122223333:alias/ExampleAlias" If you use a KMS key ID or an alias of your KMS key, the Amazon SageMaker execution role must include permissions to call kms:Encrypt. If you don't provide a KMS key ID, Amazon SageMaker uses the default KMS key for Amazon S3 for your role's account. Amazon SageMaker uses server-side encryption with KMS managed keys for OutputDataConfig. If you use a bucket policy with an s3:PutObject permission that only allows objects with server-side encryption, set the condition key of s3:x-amz-server-side-encryption to "aws:kms". For more information, see KMS managed Encryption Keys in the Amazon Simple Storage Service Developer Guide. The KMS key policy must grant permission to the IAM role that you specify in your CreateEndpoint and UpdateEndpoint requests. For more information, see Using Key Policies in Amazon Web Services KMS in the Amazon Web Services Key Management Service Developer Guide. - tags: Array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging your Amazon Web Services Resources. + data_storage_config: The Amazon S3 location and configuration for storing inference request and response data. This is an optional parameter that you can use for data capture. For more information, see Capture data. + kms_key: The Amazon Web Services Key Management Service (Amazon Web Services KMS) key that Amazon SageMaker uses to encrypt data on the storage volume attached to the ML compute instance that hosts the endpoint. The KmsKey can be any of the following formats: KMS key ID "1234abcd-12ab-34cd-56ef-1234567890ab" Amazon Resource Name (ARN) of a KMS key "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" KMS key Alias "alias/ExampleAlias" Amazon Resource Name (ARN) of a KMS key Alias "arn:aws:kms:us-west-2:111122223333:alias/ExampleAlias" If you use a KMS key ID or an alias of your KMS key, the Amazon SageMaker execution role must include permissions to call kms:Encrypt. If you don't provide a KMS key ID, Amazon SageMaker uses the default KMS key for Amazon S3 for your role's account. Amazon SageMaker uses server-side encryption with KMS managed keys for OutputDataConfig. If you use a bucket policy with an s3:PutObject permission that only allows objects with server-side encryption, set the condition key of s3:x-amz-server-side-encryption to "aws:kms". For more information, see KMS managed Encryption Keys in the Amazon Simple Storage Service Developer Guide. The KMS key policy must grant permission to the IAM role that you specify in your CreateEndpoint and UpdateEndpoint requests. For more information, see Using Key Policies in Amazon Web Services KMS in the Amazon Web Services Key Management Service Developer Guide. + tags: Array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging your Amazon Web Services Resources. session: Boto3 session. region: Region name. - + Returns: The InferenceExperiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15868,41 +15638,37 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating inference_experiment resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "Name": name, - "Type": type, - "Schedule": schedule, - "Description": description, - "RoleArn": role_arn, - "EndpointName": endpoint_name, - "ModelVariants": model_variants, - "DataStorageConfig": data_storage_config, - "ShadowModeConfig": shadow_mode_config, - "KmsKey": kms_key, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="InferenceExperiment", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'Name': name, + 'Type': type, + 'Schedule': schedule, + 'Description': description, + 'RoleArn': role_arn, + 'EndpointName': endpoint_name, + 'ModelVariants': model_variants, + 'DataStorageConfig': data_storage_config, + 'ShadowModeConfig': shadow_mode_config, + 'KmsKey': kms_key, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='InferenceExperiment', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_inference_experiment(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(name=name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -15913,17 +15679,17 @@ def get( ) -> Optional["InferenceExperiment"]: """ Get a InferenceExperiment resource - + Parameters: name: The name of the inference experiment to describe. session: Boto3 session. region: Region name. - + Returns: The InferenceExperiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15934,38 +15700,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "Name": name, + 'Name': name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_inference_experiment(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeInferenceExperimentResponse") + transformed_response = transform(response, 'DescribeInferenceExperimentResponse') inference_experiment = cls(**transformed_response) return inference_experiment - + @Base.add_validate_call def refresh( self, - ) -> Optional["InferenceExperiment"]: + + ) -> Optional["InferenceExperiment"]: """ Refresh a InferenceExperiment resource - + Returns: The InferenceExperiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -15976,21 +15741,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "Name": self.name, + 'Name': self.name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_inference_experiment(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeInferenceExperimentResponse", self) + transform(response, 'DescribeInferenceExperimentResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -16003,12 +15768,12 @@ def update( ) -> Optional["InferenceExperiment"]: """ Update a InferenceExperiment resource - + Returns: The InferenceExperiment resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16020,39 +15785,40 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating inference_experiment resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "Name": self.name, - "Schedule": schedule, - "Description": description, - "ModelVariants": model_variants, - "DataStorageConfig": data_storage_config, - "ShadowModeConfig": shadow_mode_config, + 'Name': self.name, + 'Schedule': schedule, + 'Description': description, + 'ModelVariants': model_variants, + 'DataStorageConfig': data_storage_config, + 'ShadowModeConfig': shadow_mode_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_inference_experiment(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a InferenceExperiment resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16064,27 +15830,27 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "Name": self.name, + 'Name': self.name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_inference_experiment(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def stop(self) -> None: """ Stop a InferenceExperiment resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16096,88 +15862,75 @@ def stop(self) -> None: ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "Name": self.name, - "ModelVariantActions": self.model_variant_actions, - "DesiredModelVariants": self.desired_model_variants, - "DesiredState": self.desired_state, - "Reason": self.reason, + 'Name': self.name, + 'ModelVariantActions': self.model_variant_actions, + 'DesiredModelVariants': self.desired_model_variants, + 'DesiredState': self.desired_state, + 'Reason': self.reason, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_inference_experiment(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Creating", - "Created", - "Updating", - "Running", - "Starting", - "Stopping", - "Completed", - "Cancelled", - ], + target_status: Literal['Creating', 'Created', 'Updating', 'Running', 'Starting', 'Stopping', 'Completed', 'Cancelled'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a InferenceExperiment resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) - progress.add_task( - f"Waiting for InferenceExperiment to reach [bold]{target_status} status..." - ) + progress.add_task(f"Waiting for InferenceExperiment to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="InferenceExperiment", status=current_status - ) + raise TimeoutExceededError(resouce_type="InferenceExperiment", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -16196,27 +15949,27 @@ def get_all( ) -> ResourceIterator["InferenceExperiment"]: """ Get all InferenceExperiment resources - + Parameters: name_contains: Selects inference experiments whose names contain this name. - type: Selects inference experiments of this type. For the possible types of inference experiments, see CreateInferenceExperiment. - status_equals: Selects inference experiments which are in this status. For the possible statuses, see DescribeInferenceExperiment. + type: Selects inference experiments of this type. For the possible types of inference experiments, see CreateInferenceExperiment. + status_equals: Selects inference experiments which are in this status. For the possible statuses, see DescribeInferenceExperiment. creation_time_after: Selects inference experiments which were created after this timestamp. creation_time_before: Selects inference experiments which were created before this timestamp. last_modified_time_after: Selects inference experiments which were last modified after this timestamp. last_modified_time_before: Selects inference experiments which were last modified before this timestamp. sort_by: The column by which to sort the listed inference experiments. sort_order: The direction of sorting (ascending or descending). - next_token: The response from the last list when returning a list large enough to need tokening. + next_token: The response from the last list when returning a list large enough to need tokening. max_results: The maximum number of results to select. session: Boto3 session. region: Region name. - + Returns: Iterator for listed InferenceExperiment resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16226,41 +15979,40 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "NameContains": name_contains, - "Type": type, - "StatusEquals": status_equals, - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'NameContains': name_contains, + 'Type': type, + 'StatusEquals': status_equals, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_inference_experiments", - summaries_key="InferenceExperiments", - summary_name="InferenceExperimentSummary", + list_method='list_inference_experiments', + summaries_key='InferenceExperiments', + summary_name='InferenceExperimentSummary', resource_cls=InferenceExperiment, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class InferenceRecommendationsJob(Base): """ Class representing resource InferenceRecommendationsJob - + Attributes: job_name: The name of the job. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. job_type: The job type that you provided when you initiated the job. @@ -16276,9 +16028,8 @@ class InferenceRecommendationsJob(Base): stopping_conditions: The stopping conditions that you provided when you initiated the job. inference_recommendations: The recommendations made by Inference Recommender. endpoint_performances: The performance results from running an Inference Recommender job on an existing endpoint. - + """ - job_name: str job_description: Optional[str] = Unassigned() job_type: Optional[str] = Unassigned() @@ -16293,45 +16044,55 @@ class InferenceRecommendationsJob(Base): stopping_conditions: Optional[shapes.RecommendationJobStoppingConditions] = Unassigned() inference_recommendations: Optional[List[shapes.InferenceRecommendation]] = Unassigned() endpoint_performances: Optional[List[shapes.EndpointPerformance]] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "inference_recommendations_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'inference_recommendations_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object inference_recommendations_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "role_arn": {"type": "string"}, - "input_config": { - "volume_kms_key_id": {"type": "string"}, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, - }, + config_schema_for_resource = \ + { + "role_arn": { + "type": "string" + }, + "input_config": { + "volume_kms_key_id": { + "type": "string" + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "InferenceRecommendationsJob", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "InferenceRecommendationsJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -16350,7 +16111,7 @@ def create( ) -> Optional["InferenceRecommendationsJob"]: """ Create a InferenceRecommendationsJob resource - + Parameters: job_name: A name for the recommendation job. The name must be unique within the Amazon Web Services Region and within your Amazon Web Services account. The job name is passed down to the resources created by the recommendation job. The names of resources (such as the model, endpoint configuration, endpoint, and compilation) that are prefixed with the job name are truncated at 40 characters. job_type: Defines the type of recommendation job. Specify Default to initiate an instance recommendation and Advanced to initiate a load test. If left unspecified, Amazon SageMaker Inference Recommender will run an instance recommendation (DEFAULT) job. @@ -16362,12 +16123,12 @@ def create( tags: The metadata that you apply to Amazon Web Services resources to help you categorize and organize them. Each tag consists of a key and a value, both of which you define. For more information, see Tagging Amazon Web Services Resources in the Amazon Web Services General Reference. session: Boto3 session. region: Region name. - + Returns: The InferenceRecommendationsJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16382,38 +16143,34 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating inference_recommendations_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "JobName": job_name, - "JobType": job_type, - "RoleArn": role_arn, - "InputConfig": input_config, - "JobDescription": job_description, - "StoppingConditions": stopping_conditions, - "OutputConfig": output_config, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="InferenceRecommendationsJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'JobName': job_name, + 'JobType': job_type, + 'RoleArn': role_arn, + 'InputConfig': input_config, + 'JobDescription': job_description, + 'StoppingConditions': stopping_conditions, + 'OutputConfig': output_config, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='InferenceRecommendationsJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_inference_recommendations_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(job_name=job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -16424,17 +16181,17 @@ def get( ) -> Optional["InferenceRecommendationsJob"]: """ Get a InferenceRecommendationsJob resource - + Parameters: job_name: The name of the job. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. session: Boto3 session. region: Region name. - + Returns: The InferenceRecommendationsJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16445,38 +16202,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobName": job_name, + 'JobName': job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_inference_recommendations_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeInferenceRecommendationsJobResponse") + transformed_response = transform(response, 'DescribeInferenceRecommendationsJobResponse') inference_recommendations_job = cls(**transformed_response) return inference_recommendations_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["InferenceRecommendationsJob"]: + + ) -> Optional["InferenceRecommendationsJob"]: """ Refresh a InferenceRecommendationsJob resource - + Returns: The InferenceRecommendationsJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16487,28 +16243,28 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobName": self.job_name, + 'JobName': self.job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_inference_recommendations_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeInferenceRecommendationsJobResponse", self) + transform(response, 'DescribeInferenceRecommendationsJobResponse', self) return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a InferenceRecommendationsJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16519,81 +16275,77 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "JobName": self.job_name, + 'JobName': self.job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_inference_recommendations_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a InferenceRecommendationsJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["COMPLETED", "FAILED", "STOPPED", "DELETED"] + terminal_states = ['COMPLETED', 'FAILED', 'STOPPED', 'DELETED'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for InferenceRecommendationsJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="InferenceRecommendationsJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="InferenceRecommendationsJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="InferenceRecommendationsJob", status=current_status - ) + raise TimeoutExceededError(resouce_type="InferenceRecommendationsJob", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -16602,13 +16354,13 @@ def wait_for_delete( ) -> None: """ Wait for a InferenceRecommendationsJob resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16622,45 +16374,38 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for InferenceRecommendationsJob to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + + if current_status.lower() == "deleted": print("Resource was deleted.") return - + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="InferenceRecommendationsJob", status=current_status - ) + raise TimeoutExceededError(resouce_type="InferenceRecommendationsJob", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -16680,7 +16425,7 @@ def get_all( ) -> ResourceIterator["InferenceRecommendationsJob"]: """ Get all InferenceRecommendationsJob resources - + Parameters: creation_time_after: A filter that returns only jobs created after the specified time (timestamp). creation_time_before: A filter that returns only jobs created before the specified time (timestamp). @@ -16696,12 +16441,12 @@ def get_all( model_package_version_arn_equals: A filter that returns only jobs that were created for this versioned model package. session: Boto3 session. region: Region name. - + Returns: Iterator for listed InferenceRecommendationsJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16711,59 +16456,58 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, - "ModelNameEquals": model_name_equals, - "ModelPackageVersionArnEquals": model_package_version_arn_equals, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'ModelNameEquals': model_name_equals, + 'ModelPackageVersionArnEquals': model_package_version_arn_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_inference_recommendations_jobs", - summaries_key="InferenceRecommendationsJobs", - summary_name="InferenceRecommendationsJob", + list_method='list_inference_recommendations_jobs', + summaries_key='InferenceRecommendationsJobs', + summary_name='InferenceRecommendationsJob', resource_cls=InferenceRecommendationsJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_steps( self, - step_type: Optional[str] = Unassigned(), - session: Optional[Session] = None, + step_type: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.InferenceRecommendationsJobStep]: """ Returns a list of the subtasks for an Inference Recommender job. - + Parameters: step_type: A filter to return details about the specified type of subtask. BENCHMARK: Evaluate the performance of your model on different instance types. max_results: The maximum number of results to return. next_token: A token that you can specify to return more results from the list. Specify this field if you have a token that was returned from a previous request. session: Boto3 session. region: Region name. - + Returns: Iterator for listed InferenceRecommendationsJobStep. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16774,37 +16518,37 @@ def get_all_steps( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "JobName": self.job_name, - "Status": self.status, - "StepType": step_type, + 'JobName': self.job_name, + 'Status': self.status, + 'StepType': step_type, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_inference_recommendations_job_steps", - summaries_key="Steps", - summary_name="InferenceRecommendationsJobStep", + list_method='list_inference_recommendations_job_steps', + summaries_key='Steps', + summary_name='InferenceRecommendationsJobStep', resource_cls=shapes.InferenceRecommendationsJobStep, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class LabelingJob(Base): """ Class representing resource LabelingJob - + Attributes: - labeling_job_status: The processing status of the labeling job. - label_counters: Provides a breakdown of the number of data objects labeled by humans, the number of objects labeled by machine, the number of objects than couldn't be labeled, and the total number of objects labeled. + labeling_job_status: The processing status of the labeling job. + label_counters: Provides a breakdown of the number of data objects labeled by humans, the number of objects labeled by machine, the number of objects than couldn't be labeled, and the total number of objects labeled. creation_time: The date and time that the labeling job was created. last_modified_time: The date and time that the labeling job was last updated. job_reference_code: A unique identifier for work done as part of a labeling job. @@ -16814,16 +16558,15 @@ class LabelingJob(Base): output_config: The location of the job's output data and the Amazon Web Services Key Management Service key ID for the key used to encrypt the output data, if any. role_arn: The Amazon Resource Name (ARN) that SageMaker assumes to perform tasks on your behalf during data labeling. human_task_config: Configuration information required for human workers to complete a labeling task. - failure_reason: If the job failed, the reason that it failed. + failure_reason: If the job failed, the reason that it failed. label_attribute_name: The attribute used as the label in the output manifest file. - label_category_config_s3_uri: The S3 location of the JSON file that defines the categories used to label data objects. Please note the following label-category limits: Semantic segmentation labeling jobs using automated labeling: 20 labels Box bounding labeling jobs (all): 10 labels The file is a JSON structure in the following format: { "document-version": "2018-11-28" "labels": [ { "label": "label 1" }, { "label": "label 2" }, ... { "label": "label n" } ] } + label_category_config_s3_uri: The S3 location of the JSON file that defines the categories used to label data objects. Please note the following label-category limits: Semantic segmentation labeling jobs using automated labeling: 20 labels Box bounding labeling jobs (all): 10 labels The file is a JSON structure in the following format: { "document-version": "2018-11-28" "labels": [ { "label": "label 1" }, { "label": "label 2" }, ... { "label": "label n" } ] } stopping_conditions: A set of conditions for stopping a labeling job. If any of the conditions are met, the job is automatically stopped. labeling_job_algorithms_config: Configuration information for automated data labeling. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. labeling_job_output: The location of the output produced by the labeling job. - + """ - labeling_job_name: str labeling_job_status: Optional[str] = Unassigned() label_counters: Optional[shapes.LabelCounters] = Unassigned() @@ -16842,57 +16585,89 @@ class LabelingJob(Base): human_task_config: Optional[shapes.HumanTaskConfig] = Unassigned() tags: Optional[List[shapes.Tag]] = Unassigned() labeling_job_output: Optional[shapes.LabelingJobOutput] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "labeling_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'labeling_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object labeling_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "input_config": { - "data_source": {"s3_data_source": {"manifest_s3_uri": {"type": "string"}}} - }, - "output_config": { - "s3_output_path": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "role_arn": {"type": "string"}, - "human_task_config": {"ui_config": {"ui_template_s3_uri": {"type": "string"}}}, - "label_category_config_s3_uri": {"type": "string"}, - "labeling_job_algorithms_config": { - "labeling_job_resource_config": { - "volume_kms_key_id": {"type": "string"}, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, - } + config_schema_for_resource = \ + { + "input_config": { + "data_source": { + "s3_data_source": { + "manifest_s3_uri": { + "type": "string" + } + } + } + }, + "output_config": { + "s3_output_path": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + }, + "role_arn": { + "type": "string" + }, + "human_task_config": { + "ui_config": { + "ui_template_s3_uri": { + "type": "string" + } + } + }, + "label_category_config_s3_uri": { + "type": "string" + }, + "labeling_job_algorithms_config": { + "labeling_job_resource_config": { + "volume_kms_key_id": { + "type": "string" + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } }, - "labeling_job_output": {"output_dataset_s3_uri": {"type": "string"}}, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "LabelingJob", **kwargs - ), - ) - + }, + "labeling_job_output": { + "output_dataset_s3_uri": { + "type": "string" + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "LabelingJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -16913,26 +16688,26 @@ def create( ) -> Optional["LabelingJob"]: """ Create a LabelingJob resource - + Parameters: labeling_job_name: The name of the labeling job. This name is used to identify the job in a list of labeling jobs. Labeling job names must be unique within an Amazon Web Services account and region. LabelingJobName is not case sensitive. For example, Example-job and example-job are considered the same labeling job name by Ground Truth. - label_attribute_name: The attribute name to use for the label in the output manifest file. This is the key for the key/value pair formed with the label that a worker assigns to the object. The LabelAttributeName must meet the following requirements. The name can't end with "-metadata". If you are using one of the following built-in task types, the attribute name must end with "-ref". If the task type you are using is not listed below, the attribute name must not end with "-ref". Image semantic segmentation (SemanticSegmentation), and adjustment (AdjustmentSemanticSegmentation) and verification (VerificationSemanticSegmentation) labeling jobs for this task type. Video frame object detection (VideoObjectDetection), and adjustment and verification (AdjustmentVideoObjectDetection) labeling jobs for this task type. Video frame object tracking (VideoObjectTracking), and adjustment and verification (AdjustmentVideoObjectTracking) labeling jobs for this task type. 3D point cloud semantic segmentation (3DPointCloudSemanticSegmentation), and adjustment and verification (Adjustment3DPointCloudSemanticSegmentation) labeling jobs for this task type. 3D point cloud object tracking (3DPointCloudObjectTracking), and adjustment and verification (Adjustment3DPointCloudObjectTracking) labeling jobs for this task type. If you are creating an adjustment or verification labeling job, you must use a different LabelAttributeName than the one used in the original labeling job. The original labeling job is the Ground Truth labeling job that produced the labels that you want verified or adjusted. To learn more about adjustment and verification labeling jobs, see Verify and Adjust Labels. + label_attribute_name: The attribute name to use for the label in the output manifest file. This is the key for the key/value pair formed with the label that a worker assigns to the object. The LabelAttributeName must meet the following requirements. The name can't end with "-metadata". If you are using one of the following built-in task types, the attribute name must end with "-ref". If the task type you are using is not listed below, the attribute name must not end with "-ref". Image semantic segmentation (SemanticSegmentation), and adjustment (AdjustmentSemanticSegmentation) and verification (VerificationSemanticSegmentation) labeling jobs for this task type. Video frame object detection (VideoObjectDetection), and adjustment and verification (AdjustmentVideoObjectDetection) labeling jobs for this task type. Video frame object tracking (VideoObjectTracking), and adjustment and verification (AdjustmentVideoObjectTracking) labeling jobs for this task type. 3D point cloud semantic segmentation (3DPointCloudSemanticSegmentation), and adjustment and verification (Adjustment3DPointCloudSemanticSegmentation) labeling jobs for this task type. 3D point cloud object tracking (3DPointCloudObjectTracking), and adjustment and verification (Adjustment3DPointCloudObjectTracking) labeling jobs for this task type. If you are creating an adjustment or verification labeling job, you must use a different LabelAttributeName than the one used in the original labeling job. The original labeling job is the Ground Truth labeling job that produced the labels that you want verified or adjusted. To learn more about adjustment and verification labeling jobs, see Verify and Adjust Labels. input_config: Input data for the labeling job, such as the Amazon S3 location of the data objects and the location of the manifest file that describes the data objects. You must specify at least one of the following: S3DataSource or SnsDataSource. Use SnsDataSource to specify an SNS input topic for a streaming labeling job. If you do not specify and SNS input topic ARN, Ground Truth will create a one-time labeling job that stops after all data objects in the input manifest file have been labeled. Use S3DataSource to specify an input manifest file for both streaming and one-time labeling jobs. Adding an S3DataSource is optional if you use SnsDataSource to create a streaming labeling job. If you use the Amazon Mechanical Turk workforce, your input data should not include confidential information, personal information or protected health information. Use ContentClassifiers to specify that your data is free of personally identifiable information and adult content. output_config: The location of the output data and the Amazon Web Services Key Management Service key ID for the key used to encrypt the output data, if any. role_arn: The Amazon Resource Number (ARN) that Amazon SageMaker assumes to perform tasks on your behalf during data labeling. You must grant this role the necessary permissions so that Amazon SageMaker can successfully complete data labeling. human_task_config: Configures the labeling task and how it is presented to workers; including, but not limited to price, keywords, and batch size (task count). - label_category_config_s3_uri: The S3 URI of the file, referred to as a label category configuration file, that defines the categories used to label the data objects. For 3D point cloud and video frame task types, you can add label category attributes and frame attributes to your label category configuration file. To learn how, see Create a Labeling Category Configuration File for 3D Point Cloud Labeling Jobs. For named entity recognition jobs, in addition to "labels", you must provide worker instructions in the label category configuration file using the "instructions" parameter: "instructions": {"shortInstruction":"<h1>Add header</h1><p>Add Instructions</p>", "fullInstruction":"<p>Add additional instructions.</p>"}. For details and an example, see Create a Named Entity Recognition Labeling Job (API) . For all other built-in task types and custom tasks, your label category configuration file must be a JSON file in the following format. Identify the labels you want to use by replacing label_1, label_2,...,label_n with your label categories. { "document-version": "2018-11-28", "labels": [{"label": "label_1"},{"label": "label_2"},...{"label": "label_n"}] } Note the following about the label category configuration file: For image classification and text classification (single and multi-label) you must specify at least two label categories. For all other task types, the minimum number of label categories required is one. Each label category must be unique, you cannot specify duplicate label categories. If you create a 3D point cloud or video frame adjustment or verification labeling job, you must include auditLabelAttributeName in the label category configuration. Use this parameter to enter the LabelAttributeName of the labeling job you want to adjust or verify annotations of. + label_category_config_s3_uri: The S3 URI of the file, referred to as a label category configuration file, that defines the categories used to label the data objects. For 3D point cloud and video frame task types, you can add label category attributes and frame attributes to your label category configuration file. To learn how, see Create a Labeling Category Configuration File for 3D Point Cloud Labeling Jobs. For named entity recognition jobs, in addition to "labels", you must provide worker instructions in the label category configuration file using the "instructions" parameter: "instructions": {"shortInstruction":"<h1>Add header</h1><p>Add Instructions</p>", "fullInstruction":"<p>Add additional instructions.</p>"}. For details and an example, see Create a Named Entity Recognition Labeling Job (API) . For all other built-in task types and custom tasks, your label category configuration file must be a JSON file in the following format. Identify the labels you want to use by replacing label_1, label_2,...,label_n with your label categories. { "document-version": "2018-11-28", "labels": [{"label": "label_1"},{"label": "label_2"},...{"label": "label_n"}] } Note the following about the label category configuration file: For image classification and text classification (single and multi-label) you must specify at least two label categories. For all other task types, the minimum number of label categories required is one. Each label category must be unique, you cannot specify duplicate label categories. If you create a 3D point cloud or video frame adjustment or verification labeling job, you must include auditLabelAttributeName in the label category configuration. Use this parameter to enter the LabelAttributeName of the labeling job you want to adjust or verify annotations of. stopping_conditions: A set of conditions for stopping the labeling job. If any of the conditions are met, the job is automatically stopped. You can use these conditions to control the cost of data labeling. labeling_job_algorithms_config: Configures the information required to perform automated data labeling. tags: An array of key/value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. session: Boto3 session. region: Region name. - + Returns: The LabelingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -16947,40 +16722,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating labeling_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "LabelingJobName": labeling_job_name, - "LabelAttributeName": label_attribute_name, - "InputConfig": input_config, - "OutputConfig": output_config, - "RoleArn": role_arn, - "LabelCategoryConfigS3Uri": label_category_config_s3_uri, - "StoppingConditions": stopping_conditions, - "LabelingJobAlgorithmsConfig": labeling_job_algorithms_config, - "HumanTaskConfig": human_task_config, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="LabelingJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'LabelingJobName': labeling_job_name, + 'LabelAttributeName': label_attribute_name, + 'InputConfig': input_config, + 'OutputConfig': output_config, + 'RoleArn': role_arn, + 'LabelCategoryConfigS3Uri': label_category_config_s3_uri, + 'StoppingConditions': stopping_conditions, + 'LabelingJobAlgorithmsConfig': labeling_job_algorithms_config, + 'HumanTaskConfig': human_task_config, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='LabelingJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_labeling_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(labeling_job_name=labeling_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -16991,17 +16762,17 @@ def get( ) -> Optional["LabelingJob"]: """ Get a LabelingJob resource - + Parameters: labeling_job_name: The name of the labeling job to return information for. session: Boto3 session. region: Region name. - + Returns: The LabelingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17012,38 +16783,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "LabelingJobName": labeling_job_name, + 'LabelingJobName': labeling_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_labeling_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeLabelingJobResponse") + transformed_response = transform(response, 'DescribeLabelingJobResponse') labeling_job = cls(**transformed_response) return labeling_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["LabelingJob"]: + + ) -> Optional["LabelingJob"]: """ Refresh a LabelingJob resource - + Returns: The LabelingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17054,28 +16824,28 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "LabelingJobName": self.labeling_job_name, + 'LabelingJobName': self.labeling_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_labeling_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeLabelingJobResponse", self) + transform(response, 'DescribeLabelingJobResponse', self) return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a LabelingJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17086,79 +16856,77 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "LabelingJobName": self.labeling_job_name, + 'LabelingJobName': self.labeling_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_labeling_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a LabelingJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed", "Stopped"] + terminal_states = ['Completed', 'Failed', 'Stopped'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for LabelingJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.labeling_job_status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="LabelingJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="LabelingJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="LabelingJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -17176,7 +16944,7 @@ def get_all( ) -> ResourceIterator["LabelingJob"]: """ Get all LabelingJob resources - + Parameters: creation_time_after: A filter that returns only labeling jobs created after the specified time (timestamp). creation_time_before: A filter that returns only labeling jobs created before the specified time (timestamp). @@ -17190,12 +16958,12 @@ def get_all( status_equals: A filter that retrieves only labeling jobs with a specific status. session: Boto3 session. region: Region name. - + Returns: Iterator for listed LabelingJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17205,52 +16973,50 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, - "StatusEquals": status_equals, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'StatusEquals': status_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_labeling_jobs", - summaries_key="LabelingJobSummaryList", - summary_name="LabelingJobSummary", + list_method='list_labeling_jobs', + summaries_key='LabelingJobSummaryList', + summary_name='LabelingJobSummary', resource_cls=LabelingJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class LineageGroup(Base): """ Class representing resource LineageGroup - + Attributes: lineage_group_name: The name of the lineage group. lineage_group_arn: The Amazon Resource Name (ARN) of the lineage group. display_name: The display name of the lineage group. description: The description of the lineage group. creation_time: The creation time of lineage group. - created_by: + created_by: last_modified_time: The last modified time of the lineage group. - last_modified_by: - + last_modified_by: + """ - lineage_group_name: str lineage_group_arn: Optional[str] = Unassigned() display_name: Optional[str] = Unassigned() @@ -17259,23 +17025,23 @@ class LineageGroup(Base): created_by: Optional[shapes.UserContext] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "lineage_group_name" - resource_name_split = resource_name.split("_") + resource_name = 'lineage_group_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object lineage_group") return None - + @classmethod @Base.add_validate_call def get( @@ -17286,17 +17052,17 @@ def get( ) -> Optional["LineageGroup"]: """ Get a LineageGroup resource - + Parameters: lineage_group_name: The name of the lineage group. session: Boto3 session. region: Region name. - + Returns: The LineageGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17307,38 +17073,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "LineageGroupName": lineage_group_name, + 'LineageGroupName': lineage_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_lineage_group(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeLineageGroupResponse") + transformed_response = transform(response, 'DescribeLineageGroupResponse') lineage_group = cls(**transformed_response) return lineage_group - + @Base.add_validate_call def refresh( self, - ) -> Optional["LineageGroup"]: + + ) -> Optional["LineageGroup"]: """ Refresh a LineageGroup resource - + Returns: The LineageGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17349,21 +17114,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "LineageGroupName": self.lineage_group_name, + 'LineageGroupName': self.lineage_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_lineage_group(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeLineageGroupResponse", self) + transform(response, 'DescribeLineageGroupResponse', self) return self - + @classmethod @Base.add_validate_call def get_all( @@ -17377,7 +17142,7 @@ def get_all( ) -> ResourceIterator["LineageGroup"]: """ Get all LineageGroup resources - + Parameters: created_after: A timestamp to filter against lineage groups created after a certain point in time. created_before: A timestamp to filter against lineage groups created before a certain point in time. @@ -17387,12 +17152,12 @@ def get_all( max_results: The maximum number of endpoints to return in the response. This value defaults to 10. session: Boto3 session. region: Region name. - + Returns: Iterator for listed LineageGroup resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17402,49 +17167,50 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_lineage_groups", - summaries_key="LineageGroupSummaries", - summary_name="LineageGroupSummary", + list_method='list_lineage_groups', + summaries_key='LineageGroupSummaries', + summary_name='LineageGroupSummary', resource_cls=LineageGroup, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_policy( self, + session: Optional[Session] = None, region: Optional[str] = None, ) -> Optional[shapes.GetLineageGroupPolicyResponse]: """ The resource policy for the lineage group. - + Parameters: session: Boto3 session. region: Region name. - + Returns: shapes.GetLineageGroupPolicyResponse - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17455,30 +17221,29 @@ def get_policy( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "LineageGroupName": self.lineage_group_name, + 'LineageGroupName': self.lineage_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling get_lineage_group_policy API") response = client.get_lineage_group_policy(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "GetLineageGroupPolicyResponse") + + transformed_response = transform(response, 'GetLineageGroupPolicyResponse') return shapes.GetLineageGroupPolicyResponse(**transformed_response) class MlflowTrackingServer(Base): """ Class representing resource MlflowTrackingServer - + Attributes: tracking_server_arn: The ARN of the described tracking server. tracking_server_name: The name of the described tracking server. @@ -17487,18 +17252,17 @@ class MlflowTrackingServer(Base): mlflow_version: The MLflow version used for the described tracking server. role_arn: The Amazon Resource Name (ARN) for an IAM role in your account that the described MLflow Tracking Server uses to access the artifact store in Amazon S3. tracking_server_status: The current creation status of the described MLflow Tracking Server. - tracking_server_maintenance_status: The current maintenance status of the described MLflow Tracking Server. + tracking_server_maintenance_status: The current maintenance status of the described MLflow Tracking Server. is_active: Whether the described MLflow Tracking Server is currently active. tracking_server_url: The URL to connect to the MLflow user interface for the described tracking server. weekly_maintenance_window_start: The day and time of the week when weekly maintenance occurs on the described tracking server. automatic_model_registration: Whether automatic registration of new MLflow models to the SageMaker Model Registry is enabled. creation_time: The timestamp of when the described MLflow Tracking Server was created. - created_by: + created_by: last_modified_time: The timestamp of when the described MLflow Tracking Server was last modified. - last_modified_by: - + last_modified_by: + """ - tracking_server_name: str tracking_server_arn: Optional[str] = Unassigned() artifact_store_uri: Optional[str] = Unassigned() @@ -17515,36 +17279,36 @@ class MlflowTrackingServer(Base): created_by: Optional[shapes.UserContext] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "mlflow_tracking_server_name" - resource_name_split = resource_name.split("_") + resource_name = 'mlflow_tracking_server_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object mlflow_tracking_server") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = {"role_arn": {"type": "string"}} - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "MlflowTrackingServer", **kwargs - ), - ) - + config_schema_for_resource = \ + { + "role_arn": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "MlflowTrackingServer", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -17563,24 +17327,24 @@ def create( ) -> Optional["MlflowTrackingServer"]: """ Create a MlflowTrackingServer resource - + Parameters: tracking_server_name: A unique string identifying the tracking server name. This string is part of the tracking server ARN. artifact_store_uri: The S3 URI for a general purpose bucket to use as the MLflow Tracking Server artifact store. role_arn: The Amazon Resource Name (ARN) for an IAM role in your account that the MLflow Tracking Server uses to access the artifact store in Amazon S3. The role should have AmazonS3FullAccess permissions. For more information on IAM permissions for tracking server creation, see Set up IAM permissions for MLflow. - tracking_server_size: The size of the tracking server you want to create. You can choose between "Small", "Medium", and "Large". The default MLflow Tracking Server configuration size is "Small". You can choose a size depending on the projected use of the tracking server such as the volume of data logged, number of users, and frequency of use. We recommend using a small tracking server for teams of up to 25 users, a medium tracking server for teams of up to 50 users, and a large tracking server for teams of up to 100 users. + tracking_server_size: The size of the tracking server you want to create. You can choose between "Small", "Medium", and "Large". The default MLflow Tracking Server configuration size is "Small". You can choose a size depending on the projected use of the tracking server such as the volume of data logged, number of users, and frequency of use. We recommend using a small tracking server for teams of up to 25 users, a medium tracking server for teams of up to 50 users, and a large tracking server for teams of up to 100 users. mlflow_version: The version of MLflow that the tracking server uses. To see which MLflow versions are available to use, see How it works. automatic_model_registration: Whether to enable or disable automatic registration of new MLflow models to the SageMaker Model Registry. To enable automatic model registration, set this value to True. To disable automatic model registration, set this value to False. If not specified, AutomaticModelRegistration defaults to False. weekly_maintenance_window_start: The day and time of the week in Coordinated Universal Time (UTC) 24-hour standard time that weekly maintenance updates are scheduled. For example: TUE:03:30. tags: Tags consisting of key-value pairs used to manage metadata for the tracking server. session: Boto3 session. region: Region name. - + Returns: The MlflowTrackingServer resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17594,38 +17358,34 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating mlflow_tracking_server resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "TrackingServerName": tracking_server_name, - "ArtifactStoreUri": artifact_store_uri, - "TrackingServerSize": tracking_server_size, - "MlflowVersion": mlflow_version, - "RoleArn": role_arn, - "AutomaticModelRegistration": automatic_model_registration, - "WeeklyMaintenanceWindowStart": weekly_maintenance_window_start, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="MlflowTrackingServer", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'TrackingServerName': tracking_server_name, + 'ArtifactStoreUri': artifact_store_uri, + 'TrackingServerSize': tracking_server_size, + 'MlflowVersion': mlflow_version, + 'RoleArn': role_arn, + 'AutomaticModelRegistration': automatic_model_registration, + 'WeeklyMaintenanceWindowStart': weekly_maintenance_window_start, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='MlflowTrackingServer', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_mlflow_tracking_server(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(tracking_server_name=tracking_server_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -17636,17 +17396,17 @@ def get( ) -> Optional["MlflowTrackingServer"]: """ Get a MlflowTrackingServer resource - + Parameters: tracking_server_name: The name of the MLflow Tracking Server to describe. session: Boto3 session. region: Region name. - + Returns: The MlflowTrackingServer resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17657,38 +17417,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrackingServerName": tracking_server_name, + 'TrackingServerName': tracking_server_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_mlflow_tracking_server(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeMlflowTrackingServerResponse") + transformed_response = transform(response, 'DescribeMlflowTrackingServerResponse') mlflow_tracking_server = cls(**transformed_response) return mlflow_tracking_server - + @Base.add_validate_call def refresh( self, - ) -> Optional["MlflowTrackingServer"]: + + ) -> Optional["MlflowTrackingServer"]: """ Refresh a MlflowTrackingServer resource - + Returns: The MlflowTrackingServer resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17699,21 +17458,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrackingServerName": self.tracking_server_name, + 'TrackingServerName': self.tracking_server_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_mlflow_tracking_server(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeMlflowTrackingServerResponse", self) + transform(response, 'DescribeMlflowTrackingServerResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -17725,12 +17484,12 @@ def update( ) -> Optional["MlflowTrackingServer"]: """ Update a MlflowTrackingServer resource - + Returns: The MlflowTrackingServer resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17743,38 +17502,39 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating mlflow_tracking_server resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "TrackingServerName": self.tracking_server_name, - "ArtifactStoreUri": artifact_store_uri, - "TrackingServerSize": tracking_server_size, - "AutomaticModelRegistration": automatic_model_registration, - "WeeklyMaintenanceWindowStart": weekly_maintenance_window_start, + 'TrackingServerName': self.tracking_server_name, + 'ArtifactStoreUri': artifact_store_uri, + 'TrackingServerSize': tracking_server_size, + 'AutomaticModelRegistration': automatic_model_registration, + 'WeeklyMaintenanceWindowStart': weekly_maintenance_window_start, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_mlflow_tracking_server(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a MlflowTrackingServer resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17785,27 +17545,27 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "TrackingServerName": self.tracking_server_name, + 'TrackingServerName': self.tracking_server_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_mlflow_tracking_server(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def stop(self) -> None: """ Stop a MlflowTrackingServer resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17817,100 +17577,74 @@ def stop(self) -> None: ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "TrackingServerName": self.tracking_server_name, + 'TrackingServerName': self.tracking_server_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_mlflow_tracking_server(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Creating", - "Created", - "CreateFailed", - "Updating", - "Updated", - "UpdateFailed", - "Deleting", - "DeleteFailed", - "Stopping", - "Stopped", - "StopFailed", - "Starting", - "Started", - "StartFailed", - "MaintenanceInProgress", - "MaintenanceComplete", - "MaintenanceFailed", - ], + target_status: Literal['Creating', 'Created', 'CreateFailed', 'Updating', 'Updated', 'UpdateFailed', 'Deleting', 'DeleteFailed', 'Stopping', 'Stopped', 'StopFailed', 'Starting', 'Started', 'StartFailed', 'MaintenanceInProgress', 'MaintenanceComplete', 'MaintenanceFailed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a MlflowTrackingServer resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) - progress.add_task( - f"Waiting for MlflowTrackingServer to reach [bold]{target_status} status..." - ) + progress.add_task(f"Waiting for MlflowTrackingServer to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.tracking_server_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="MlflowTrackingServer", - status=current_status, - reason="(Unknown)", - ) - + raise FailedStatusError(resource_type="MlflowTrackingServer", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="MlflowTrackingServer", status=current_status - ) + raise TimeoutExceededError(resouce_type="MlflowTrackingServer", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -17919,13 +17653,13 @@ def wait_for_delete( ) -> None: """ Wait for a MlflowTrackingServer resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -17939,41 +17673,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for MlflowTrackingServer to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.tracking_server_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="MlflowTrackingServer", status=current_status - ) + raise TimeoutExceededError(resouce_type="MlflowTrackingServer", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -17989,7 +17716,7 @@ def get_all( ) -> ResourceIterator["MlflowTrackingServer"]: """ Get all MlflowTrackingServer resources - + Parameters: created_after: Use the CreatedAfter filter to only list tracking servers created after a specific date and time. Listed tracking servers are shown with a date and time such as "2024-03-16T01:46:56+00:00". The CreatedAfter parameter takes in a Unix timestamp. To convert a date and time into a Unix timestamp, see EpochConverter. created_before: Use the CreatedBefore filter to only list tracking servers created before a specific date and time. Listed tracking servers are shown with a date and time such as "2024-03-16T01:46:56+00:00". The CreatedBefore parameter takes in a Unix timestamp. To convert a date and time into a Unix timestamp, see EpochConverter. @@ -18001,12 +17728,12 @@ def get_all( max_results: The maximum number of tracking servers to list. session: Boto3 session. region: Region name. - + Returns: Iterator for listed MlflowTrackingServer resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18016,52 +17743,50 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "TrackingServerStatus": tracking_server_status, - "MlflowVersion": mlflow_version, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'TrackingServerStatus': tracking_server_status, + 'MlflowVersion': mlflow_version, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_mlflow_tracking_servers", - summaries_key="TrackingServerSummaries", - summary_name="TrackingServerSummary", + list_method='list_mlflow_tracking_servers', + summaries_key='TrackingServerSummaries', + summary_name='TrackingServerSummary', resource_cls=MlflowTrackingServer, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Model(Base): """ Class representing resource Model - + Attributes: model_name: Name of the SageMaker model. creation_time: A timestamp that shows when the model was created. model_arn: The Amazon Resource Name (ARN) of the model. - primary_container: The location of the primary inference code, associated artifacts, and custom environment map that the inference code uses when it is deployed in production. + primary_container: The location of the primary inference code, associated artifacts, and custom environment map that the inference code uses when it is deployed in production. containers: The containers in the inference pipeline. inference_execution_config: Specifies details of how containers in a multi-container endpoint are called. execution_role_arn: The Amazon Resource Name (ARN) of the IAM role that you specified for the model. - vpc_config: A VpcConfig object that specifies the VPC that this model has access to. For more information, see Protect Endpoints by Using an Amazon Virtual Private Cloud + vpc_config: A VpcConfig object that specifies the VPC that this model has access to. For more information, see Protect Endpoints by Using an Amazon Virtual Private Cloud enable_network_isolation: If True, no inbound or outbound network calls can be made to or from the model container. deployment_recommendation: A set of recommended deployment configurations for the model. - + """ - model_name: str primary_container: Optional[shapes.ContainerDefinition] = Unassigned() containers: Optional[List[shapes.ContainerDefinition]] = Unassigned() @@ -18072,51 +17797,65 @@ class Model(Base): model_arn: Optional[str] = Unassigned() enable_network_isolation: Optional[bool] = Unassigned() deployment_recommendation: Optional[shapes.DeploymentRecommendation] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "primary_container": { - "model_data_source": { - "s3_data_source": { - "s3_uri": {"type": "string"}, - "s3_data_type": {"type": "string"}, - "manifest_s3_uri": {"type": "string"}, - } - } + config_schema_for_resource = \ + { + "primary_container": { + "model_data_source": { + "s3_data_source": { + "s3_uri": { + "type": "string" }, - "execution_role_arn": {"type": "string"}, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, + "s3_data_type": { + "type": "string" }, + "manifest_s3_uri": { + "type": "string" + } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Model", **kwargs - ), - ) - + }, + "execution_role_arn": { + "type": "string" + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Model", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -18135,24 +17874,24 @@ def create( ) -> Optional["Model"]: """ Create a Model resource - + Parameters: model_name: The name of the new model. - primary_container: The location of the primary docker image containing inference code, associated artifacts, and custom environment map that the inference code uses when the model is deployed for predictions. + primary_container: The location of the primary docker image containing inference code, associated artifacts, and custom environment map that the inference code uses when the model is deployed for predictions. containers: Specifies the containers in the inference pipeline. inference_execution_config: Specifies details of how containers in a multi-container endpoint are called. - execution_role_arn: The Amazon Resource Name (ARN) of the IAM role that SageMaker can assume to access model artifacts and docker image for deployment on ML compute instances or for batch transform jobs. Deploying on ML compute instances is part of model hosting. For more information, see SageMaker Roles. To be able to pass this role to SageMaker, the caller of this API must have the iam:PassRole permission. + execution_role_arn: The Amazon Resource Name (ARN) of the IAM role that SageMaker can assume to access model artifacts and docker image for deployment on ML compute instances or for batch transform jobs. Deploying on ML compute instances is part of model hosting. For more information, see SageMaker Roles. To be able to pass this role to SageMaker, the caller of this API must have the iam:PassRole permission. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. vpc_config: A VpcConfig object that specifies the VPC that you want your model to connect to. Control access to and from your model container by configuring the VPC. VpcConfig is used in hosting services and in batch transform. For more information, see Protect Endpoints by Using an Amazon Virtual Private Cloud and Protect Data in Batch Transform Jobs by Using an Amazon Virtual Private Cloud. enable_network_isolation: Isolates the model container. No inbound or outbound network calls can be made to or from the model container. session: Boto3 session. region: Region name. - + Returns: The Model resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18166,38 +17905,34 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ModelName": model_name, - "PrimaryContainer": primary_container, - "Containers": containers, - "InferenceExecutionConfig": inference_execution_config, - "ExecutionRoleArn": execution_role_arn, - "Tags": tags, - "VpcConfig": vpc_config, - "EnableNetworkIsolation": enable_network_isolation, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Model", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ModelName': model_name, + 'PrimaryContainer': primary_container, + 'Containers': containers, + 'InferenceExecutionConfig': inference_execution_config, + 'ExecutionRoleArn': execution_role_arn, + 'Tags': tags, + 'VpcConfig': vpc_config, + 'EnableNetworkIsolation': enable_network_isolation, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Model', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(model_name=model_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -18208,17 +17943,17 @@ def get( ) -> Optional["Model"]: """ Get a Model resource - + Parameters: model_name: The name of the model. session: Boto3 session. region: Region name. - + Returns: The Model resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18228,38 +17963,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ModelName": model_name, + 'ModelName': model_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeModelOutput") + transformed_response = transform(response, 'DescribeModelOutput') model = cls(**transformed_response) return model - + @Base.add_validate_call def refresh( self, - ) -> Optional["Model"]: + + ) -> Optional["Model"]: """ Refresh a Model resource - + Returns: The Model resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18269,30 +18003,31 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ModelName": self.model_name, + 'ModelName': self.model_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelOutput", self) + transform(response, 'DescribeModelOutput', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Model resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18302,20 +18037,20 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ModelName": self.model_name, + 'ModelName': self.model_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_model(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -18330,7 +18065,7 @@ def get_all( ) -> ResourceIterator["Model"]: """ Get all Model resources - + Parameters: sort_by: Sorts the list of results. The default is CreationTime. sort_order: The sort order for results. The default is Descending. @@ -18341,12 +18076,12 @@ def get_all( creation_time_after: A filter that returns only models with a creation time greater than or equal to the specified time (timestamp). session: Boto3 session. region: Region name. - + Returns: Iterator for listed Model resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18356,54 +18091,53 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_models", - summaries_key="Models", - summary_name="ModelSummary", + list_method='list_models', + summaries_key='Models', + summary_name='ModelSummary', resource_cls=Model, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_metadata( self, - search_expression: Optional[shapes.ModelMetadataSearchExpression] = Unassigned(), - session: Optional[Session] = None, + search_expression: Optional[shapes.ModelMetadataSearchExpression] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.ModelMetadataSummary]: """ Lists the domain, framework, task, and model name of standard machine learning models found in common model zoos. - + Parameters: search_expression: One or more filters that searches for the specified resource or resources in a search. All resource objects that satisfy the expression's condition are included in the search results. Specify the Framework, FrameworkVersion, Domain or Task to filter supported. Filter names and values are case-sensitive. next_token: If the response to a previous ListModelMetadataResponse request was truncated, the response includes a NextToken. To retrieve the next set of model metadata, use the token in the next request. max_results: The maximum number of models to return in the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelMetadataSummary. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18413,47 +18147,46 @@ def get_all_metadata( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "SearchExpression": search_expression, + 'SearchExpression': search_expression, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_model_metadata", - summaries_key="ModelMetadataSummaries", - summary_name="ModelMetadataSummary", + list_method='list_model_metadata', + summaries_key='ModelMetadataSummaries', + summary_name='ModelMetadataSummary', resource_cls=shapes.ModelMetadataSummary, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ModelBiasJobDefinition(Base): """ Class representing resource ModelBiasJobDefinition - + Attributes: job_definition_arn: The Amazon Resource Name (ARN) of the model bias job. job_definition_name: The name of the bias job definition. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. creation_time: The time at which the model bias job was created. model_bias_app_specification: Configures the model bias job to run a specified Docker container image. model_bias_job_input: Inputs for the model bias job. - model_bias_job_output_config: - job_resources: + model_bias_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of the IAM role that has read permission to the input data location and write permission to the output data location in Amazon S3. model_bias_baseline_config: The baseline configuration for a model bias job. network_config: Networking options for a model bias job. - stopping_condition: - + stopping_condition: + """ - job_definition_name: str job_definition_arn: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() @@ -18465,61 +18198,97 @@ class ModelBiasJobDefinition(Base): network_config: Optional[shapes.MonitoringNetworkConfig] = Unassigned() role_arn: Optional[str] = Unassigned() stopping_condition: Optional[shapes.MonitoringStoppingCondition] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_bias_job_definition_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_bias_job_definition_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model_bias_job_definition") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "model_bias_job_input": { - "ground_truth_s3_input": {"s3_uri": {"type": "string"}}, - "endpoint_input": { - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - "batch_transform_input": { - "data_captured_destination_s3_uri": {"type": "string"}, - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - }, - "model_bias_job_output_config": {"kms_key_id": {"type": "string"}}, - "job_resources": {"cluster_config": {"volume_kms_key_id": {"type": "string"}}}, - "role_arn": {"type": "string"}, - "model_bias_baseline_config": { - "constraints_resource": {"s3_uri": {"type": "string"}} - }, - "network_config": { - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - } - }, + config_schema_for_resource = \ + { + "model_bias_job_input": { + "ground_truth_s3_input": { + "s3_uri": { + "type": "string" + } + }, + "endpoint_input": { + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } + }, + "batch_transform_input": { + "data_captured_destination_s3_uri": { + "type": "string" + }, + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "ModelBiasJobDefinition", **kwargs - ), - ) - + }, + "model_bias_job_output_config": { + "kms_key_id": { + "type": "string" + } + }, + "job_resources": { + "cluster_config": { + "volume_kms_key_id": { + "type": "string" + } + } + }, + "role_arn": { + "type": "string" + }, + "model_bias_baseline_config": { + "constraints_resource": { + "s3_uri": { + "type": "string" + } + } + }, + "network_config": { + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "ModelBiasJobDefinition", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -18540,26 +18309,26 @@ def create( ) -> Optional["ModelBiasJobDefinition"]: """ Create a ModelBiasJobDefinition resource - + Parameters: job_definition_name: The name of the bias job definition. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. model_bias_app_specification: Configures the model bias job to run a specified Docker container image. model_bias_job_input: Inputs for the model bias job. - model_bias_job_output_config: - job_resources: + model_bias_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform tasks on your behalf. model_bias_baseline_config: The baseline configuration for a model bias job. network_config: Networking options for a model bias job. - stopping_condition: + stopping_condition: tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. session: Boto3 session. region: Region name. - + Returns: The ModelBiasJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18574,40 +18343,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model_bias_job_definition resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "JobDefinitionName": job_definition_name, - "ModelBiasBaselineConfig": model_bias_baseline_config, - "ModelBiasAppSpecification": model_bias_app_specification, - "ModelBiasJobInput": model_bias_job_input, - "ModelBiasJobOutputConfig": model_bias_job_output_config, - "JobResources": job_resources, - "NetworkConfig": network_config, - "RoleArn": role_arn, - "StoppingCondition": stopping_condition, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ModelBiasJobDefinition", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'JobDefinitionName': job_definition_name, + 'ModelBiasBaselineConfig': model_bias_baseline_config, + 'ModelBiasAppSpecification': model_bias_app_specification, + 'ModelBiasJobInput': model_bias_job_input, + 'ModelBiasJobOutputConfig': model_bias_job_output_config, + 'JobResources': job_resources, + 'NetworkConfig': network_config, + 'RoleArn': role_arn, + 'StoppingCondition': stopping_condition, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ModelBiasJobDefinition', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model_bias_job_definition(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(job_definition_name=job_definition_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -18618,17 +18383,17 @@ def get( ) -> Optional["ModelBiasJobDefinition"]: """ Get a ModelBiasJobDefinition resource - + Parameters: job_definition_name: The name of the model bias job definition. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. session: Boto3 session. region: Region name. - + Returns: The ModelBiasJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18639,38 +18404,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": job_definition_name, + 'JobDefinitionName': job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model_bias_job_definition(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeModelBiasJobDefinitionResponse") + transformed_response = transform(response, 'DescribeModelBiasJobDefinitionResponse') model_bias_job_definition = cls(**transformed_response) return model_bias_job_definition - + @Base.add_validate_call def refresh( self, - ) -> Optional["ModelBiasJobDefinition"]: + + ) -> Optional["ModelBiasJobDefinition"]: """ Refresh a ModelBiasJobDefinition resource - + Returns: The ModelBiasJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18681,30 +18445,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model_bias_job_definition(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelBiasJobDefinitionResponse", self) + transform(response, 'DescribeModelBiasJobDefinitionResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ModelBiasJobDefinition resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18715,20 +18480,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_model_bias_job_definition(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -18744,7 +18509,7 @@ def get_all( ) -> ResourceIterator["ModelBiasJobDefinition"]: """ Get all ModelBiasJobDefinition resources - + Parameters: endpoint_name: Name of the endpoint to monitor for model bias. sort_by: Whether to sort results by the Name or CreationTime field. The default is CreationTime. @@ -18756,12 +18521,12 @@ def get_all( creation_time_after: A filter that returns only model bias jobs created after a specified time. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelBiasJobDefinition resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18771,58 +18536,52 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "EndpointName": endpoint_name, - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - } - - custom_key_mapping = { - "monitoring_job_definition_name": "job_definition_name", - "monitoring_job_definition_arn": "job_definition_arn", + 'EndpointName': endpoint_name, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, } + + custom_key_mapping = {"monitoring_job_definition_name": "job_definition_name", "monitoring_job_definition_arn": "job_definition_arn"} # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_model_bias_job_definitions", - summaries_key="JobDefinitionSummaries", - summary_name="MonitoringJobDefinitionSummary", + list_method='list_model_bias_job_definitions', + summaries_key='JobDefinitionSummaries', + summary_name='MonitoringJobDefinitionSummary', resource_cls=ModelBiasJobDefinition, custom_key_mapping=custom_key_mapping, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ModelCard(Base): """ Class representing resource ModelCard - + Attributes: model_card_arn: The Amazon Resource Name (ARN) of the model card. model_card_name: The name of the model card. model_card_version: The version of the model card. content: The content of the model card. - model_card_status: The approval status of the model card within your organization. Different organizations might have different criteria for model card review and approval. Draft: The model card is a work in progress. PendingReview: The model card is pending review. Approved: The model card is approved. Archived: The model card is archived. No more updates should be made to the model card, but it can still be exported. + model_card_status: The approval status of the model card within your organization. Different organizations might have different criteria for model card review and approval. Draft: The model card is a work in progress. PendingReview: The model card is pending review. Approved: The model card is approved. Archived: The model card is archived. No more updates should be made to the model card, but it can still be exported. creation_time: The date and time the model card was created. - created_by: + created_by: security_config: The security configuration used to protect model card content. last_modified_time: The date and time the model card was last modified. - last_modified_by: - model_card_processing_status: The processing status of model card deletion. The ModelCardProcessingStatus updates throughout the different deletion steps. DeletePending: Model card deletion request received. DeleteInProgress: Model card deletion is in progress. ContentDeleted: Deleted model card content. ExportJobsDeleted: Deleted all export jobs associated with the model card. DeleteCompleted: Successfully deleted the model card. DeleteFailed: The model card failed to delete. - + last_modified_by: + model_card_processing_status: The processing status of model card deletion. The ModelCardProcessingStatus updates throughout the different deletion steps. DeletePending: Model card deletion request received. DeleteInProgress: Model card deletion is in progress. ContentDeleted: Deleted model card content. ExportJobsDeleted: Deleted all export jobs associated with the model card. DeleteCompleted: Successfully deleted the model card. DeleteFailed: The model card failed to delete. + """ - model_card_name: str model_card_arn: Optional[str] = Unassigned() model_card_version: Optional[int] = Unassigned() @@ -18834,36 +18593,38 @@ class ModelCard(Base): last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() model_card_processing_status: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_card_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_card_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model_card") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = {"security_config": {"kms_key_id": {"type": "string"}}} - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "ModelCard", **kwargs - ), - ) - + config_schema_for_resource = \ + { + "security_config": { + "kms_key_id": { + "type": "string" + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "ModelCard", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -18879,21 +18640,21 @@ def create( ) -> Optional["ModelCard"]: """ Create a ModelCard resource - + Parameters: model_card_name: The unique name of the model card. content: The content of the model card. Content must be in model card JSON schema and provided as a string. - model_card_status: The approval status of the model card within your organization. Different organizations might have different criteria for model card review and approval. Draft: The model card is a work in progress. PendingReview: The model card is pending review. Approved: The model card is approved. Archived: The model card is archived. No more updates should be made to the model card, but it can still be exported. + model_card_status: The approval status of the model card within your organization. Different organizations might have different criteria for model card review and approval. Draft: The model card is a work in progress. PendingReview: The model card is pending review. Approved: The model card is approved. Archived: The model card is archived. No more updates should be made to the model card, but it can still be exported. security_config: An optional Key Management Service key to encrypt, decrypt, and re-encrypt model card content for regulated workloads with highly sensitive data. tags: Key-value pairs used to manage metadata for model cards. session: Boto3 session. region: Region name. - + Returns: The ModelCard resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18908,35 +18669,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model_card resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ModelCardName": model_card_name, - "SecurityConfig": security_config, - "Content": content, - "ModelCardStatus": model_card_status, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ModelCard", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ModelCardName': model_card_name, + 'SecurityConfig': security_config, + 'Content': content, + 'ModelCardStatus': model_card_status, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ModelCard', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model_card(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(model_card_name=model_card_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -18948,18 +18705,18 @@ def get( ) -> Optional["ModelCard"]: """ Get a ModelCard resource - + Parameters: model_card_name: The name or Amazon Resource Name (ARN) of the model card to describe. model_card_version: The version of the model card to describe. If a version is not provided, then the latest version of the model card is described. session: Boto3 session. region: Region name. - + Returns: The ModelCard resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -18970,39 +18727,38 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ModelCardName": model_card_name, - "ModelCardVersion": model_card_version, + 'ModelCardName': model_card_name, + 'ModelCardVersion': model_card_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model_card(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeModelCardResponse") + transformed_response = transform(response, 'DescribeModelCardResponse') model_card = cls(**transformed_response) return model_card - + @Base.add_validate_call def refresh( self, - ) -> Optional["ModelCard"]: + + ) -> Optional["ModelCard"]: """ Refresh a ModelCard resource - + Returns: The ModelCard resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19013,22 +18769,22 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ModelCardName": self.model_card_name, - "ModelCardVersion": self.model_card_version, + 'ModelCardName': self.model_card_name, + 'ModelCardVersion': self.model_card_version, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model_card(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelCardResponse", self) + transform(response, 'DescribeModelCardResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -19038,12 +18794,12 @@ def update( ) -> Optional["ModelCard"]: """ Update a ModelCard resource - + Returns: The ModelCard resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19056,36 +18812,37 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating model_card resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ModelCardName": self.model_card_name, - "Content": content, - "ModelCardStatus": model_card_status, + 'ModelCardName': self.model_card_name, + 'Content': content, + 'ModelCardStatus': model_card_status, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_model_card(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ModelCard resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19097,71 +18854,71 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ModelCardName": self.model_card_name, + 'ModelCardName': self.model_card_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_model_card(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Draft", "PendingReview", "Approved", "Archived"], + target_status: Literal['Draft', 'PendingReview', 'Approved', 'Archived'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a ModelCard resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for ModelCard to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.model_card_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="ModelCard", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -19177,7 +18934,7 @@ def get_all( ) -> ResourceIterator["ModelCard"]: """ Get all ModelCard resources - + Parameters: creation_time_after: Only list model cards that were created after the time specified. creation_time_before: Only list model cards that were created before the time specified. @@ -19189,12 +18946,12 @@ def get_all( sort_order: Sort model cards by ascending or descending order. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelCard resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19204,46 +18961,45 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "NameContains": name_contains, - "ModelCardStatus": model_card_status, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'NameContains': name_contains, + 'ModelCardStatus': model_card_status, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_model_cards", - summaries_key="ModelCardSummaries", - summary_name="ModelCardSummary", + list_method='list_model_cards', + summaries_key='ModelCardSummaries', + summary_name='ModelCardSummary', resource_cls=ModelCard, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_versions( self, creation_time_after: Optional[datetime.datetime] = Unassigned(), creation_time_before: Optional[datetime.datetime] = Unassigned(), sort_by: Optional[str] = Unassigned(), - sort_order: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_order: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.ModelCardVersionSummary]: """ List existing versions of an Amazon SageMaker Model Card. - + Parameters: creation_time_after: Only list model card versions that were created after the time specified. creation_time_before: Only list model card versions that were created before the time specified. @@ -19253,12 +19009,12 @@ def get_all_versions( sort_order: Sort model card versions by ascending or descending order. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelCardVersionSummary. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19269,41 +19025,41 @@ def get_all_versions( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "ModelCardName": self.model_card_name, - "ModelCardStatus": self.model_card_status, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'ModelCardName': self.model_card_name, + 'ModelCardStatus': self.model_card_status, + 'SortBy': sort_by, + 'SortOrder': sort_order, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_model_card_versions", - summaries_key="ModelCardVersionSummaryList", - summary_name="ModelCardVersionSummary", + list_method='list_model_card_versions', + summaries_key='ModelCardVersionSummaryList', + summary_name='ModelCardVersionSummary', resource_cls=shapes.ModelCardVersionSummary, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ModelCardExportJob(Base): """ Class representing resource ModelCardExportJob - + Attributes: model_card_export_job_name: The name of the model card export job to describe. model_card_export_job_arn: The Amazon Resource Name (ARN) of the model card export job. - status: The completion status of the model card export job. InProgress: The model card export job is in progress. Completed: The model card export job is complete. Failed: The model card export job failed. To see the reason for the failure, see the FailureReason field in the response to a DescribeModelCardExportJob call. + status: The completion status of the model card export job. InProgress: The model card export job is in progress. Completed: The model card export job is complete. Failed: The model card export job failed. To see the reason for the failure, see the FailureReason field in the response to a DescribeModelCardExportJob call. model_card_name: The name or Amazon Resource Name (ARN) of the model card that the model export job exports. model_card_version: The version of the model card that the model export job exports. output_config: The export output details for the model card. @@ -19311,9 +19067,8 @@ class ModelCardExportJob(Base): last_modified_at: The date and time that the model export job was last modified. failure_reason: The failure reason if the model export job fails. export_artifacts: The exported model card artifacts. - + """ - model_card_export_job_arn: str model_card_export_job_name: Optional[str] = Unassigned() status: Optional[str] = Unassigned() @@ -19324,39 +19079,43 @@ class ModelCardExportJob(Base): last_modified_at: Optional[datetime.datetime] = Unassigned() failure_reason: Optional[str] = Unassigned() export_artifacts: Optional[shapes.ModelCardExportArtifacts] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_card_export_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_card_export_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model_card_export_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "output_config": {"s3_output_path": {"type": "string"}}, - "export_artifacts": {"s3_export_artifacts": {"type": "string"}}, + config_schema_for_resource = \ + { + "output_config": { + "s3_output_path": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "ModelCardExportJob", **kwargs - ), - ) - + }, + "export_artifacts": { + "s3_export_artifacts": { + "type": "string" + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "ModelCardExportJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -19371,7 +19130,7 @@ def create( ) -> Optional["ModelCardExportJob"]: """ Create a ModelCardExportJob resource - + Parameters: model_card_name: The name or Amazon Resource Name (ARN) of the model card to export. model_card_export_job_name: The name of the model card export job. @@ -19379,12 +19138,12 @@ def create( model_card_version: The version of the model card to export. If a version is not provided, then the latest version of the model card is exported. session: Boto3 session. region: Region name. - + Returns: The ModelCardExportJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19400,38 +19159,30 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model_card_export_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "ModelCardName": model_card_name, - "ModelCardVersion": model_card_version, - "ModelCardExportJobName": model_card_export_job_name, - "OutputConfig": output_config, + 'ModelCardName': model_card_name, + 'ModelCardVersion': model_card_version, + 'ModelCardExportJobName': model_card_export_job_name, + 'OutputConfig': output_config, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ModelCardExportJob", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='ModelCardExportJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model_card_export_job(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - model_card_export_job_arn=response["ModelCardExportJobArn"], - session=session, - region=region, - ) - + + return cls.get(model_card_export_job_arn=response['ModelCardExportJobArn'], session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -19442,17 +19193,17 @@ def get( ) -> Optional["ModelCardExportJob"]: """ Get a ModelCardExportJob resource - + Parameters: model_card_export_job_arn: The Amazon Resource Name (ARN) of the model card export job to describe. session: Boto3 session. region: Region name. - + Returns: The ModelCardExportJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19463,38 +19214,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ModelCardExportJobArn": model_card_export_job_arn, + 'ModelCardExportJobArn': model_card_export_job_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model_card_export_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeModelCardExportJobResponse") + transformed_response = transform(response, 'DescribeModelCardExportJobResponse') model_card_export_job = cls(**transformed_response) return model_card_export_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["ModelCardExportJob"]: + + ) -> Optional["ModelCardExportJob"]: """ Refresh a ModelCardExportJob resource - + Returns: The ModelCardExportJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19505,82 +19255,78 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ModelCardExportJobArn": self.model_card_export_job_arn, + 'ModelCardExportJobArn': self.model_card_export_job_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model_card_export_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelCardExportJobResponse", self) + transform(response, 'DescribeModelCardExportJobResponse', self) return self - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a ModelCardExportJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed"] + terminal_states = ['Completed', 'Failed'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for ModelCardExportJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="ModelCardExportJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="ModelCardExportJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ModelCardExportJob", status=current_status - ) + raise TimeoutExceededError(resouce_type="ModelCardExportJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -19598,7 +19344,7 @@ def get_all( ) -> ResourceIterator["ModelCardExportJob"]: """ Get all ModelCardExportJob resources - + Parameters: model_card_name: List export jobs for the model card with the specified name. model_card_version: List export jobs for the model card with the specified version. @@ -19612,12 +19358,12 @@ def get_all( max_results: The maximum number of model card export jobs to list. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelCardExportJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19627,124 +19373,150 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "ModelCardName": model_card_name, - "ModelCardVersion": model_card_version, - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "ModelCardExportJobNameContains": model_card_export_job_name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, + 'ModelCardName': model_card_name, + 'ModelCardVersion': model_card_version, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'ModelCardExportJobNameContains': model_card_export_job_name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_model_card_export_jobs", - summaries_key="ModelCardExportJobSummaries", - summary_name="ModelCardExportJobSummary", + list_method='list_model_card_export_jobs', + summaries_key='ModelCardExportJobSummaries', + summary_name='ModelCardExportJobSummary', resource_cls=ModelCardExportJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ModelExplainabilityJobDefinition(Base): """ Class representing resource ModelExplainabilityJobDefinition - + Attributes: job_definition_arn: The Amazon Resource Name (ARN) of the model explainability job. job_definition_name: The name of the explainability job definition. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. creation_time: The time at which the model explainability job was created. model_explainability_app_specification: Configures the model explainability job to run a specified Docker container image. model_explainability_job_input: Inputs for the model explainability job. - model_explainability_job_output_config: - job_resources: + model_explainability_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of the IAM role that has read permission to the input data location and write permission to the output data location in Amazon S3. model_explainability_baseline_config: The baseline configuration for a model explainability job. network_config: Networking options for a model explainability job. - stopping_condition: - + stopping_condition: + """ - job_definition_name: str job_definition_arn: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() - model_explainability_baseline_config: Optional[shapes.ModelExplainabilityBaselineConfig] = ( - Unassigned() - ) - model_explainability_app_specification: Optional[shapes.ModelExplainabilityAppSpecification] = ( - Unassigned() - ) + model_explainability_baseline_config: Optional[shapes.ModelExplainabilityBaselineConfig] = Unassigned() + model_explainability_app_specification: Optional[shapes.ModelExplainabilityAppSpecification] = Unassigned() model_explainability_job_input: Optional[shapes.ModelExplainabilityJobInput] = Unassigned() model_explainability_job_output_config: Optional[shapes.MonitoringOutputConfig] = Unassigned() job_resources: Optional[shapes.MonitoringResources] = Unassigned() network_config: Optional[shapes.MonitoringNetworkConfig] = Unassigned() role_arn: Optional[str] = Unassigned() stopping_condition: Optional[shapes.MonitoringStoppingCondition] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_explainability_job_definition_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_explainability_job_definition_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model_explainability_job_definition") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "model_explainability_job_input": { - "endpoint_input": { - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - "batch_transform_input": { - "data_captured_destination_s3_uri": {"type": "string"}, - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - }, - "model_explainability_job_output_config": {"kms_key_id": {"type": "string"}}, - "job_resources": {"cluster_config": {"volume_kms_key_id": {"type": "string"}}}, - "role_arn": {"type": "string"}, - "model_explainability_baseline_config": { - "constraints_resource": {"s3_uri": {"type": "string"}} - }, - "network_config": { - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - } - }, + config_schema_for_resource = \ + { + "model_explainability_job_input": { + "endpoint_input": { + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } + }, + "batch_transform_input": { + "data_captured_destination_s3_uri": { + "type": "string" + }, + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "ModelExplainabilityJobDefinition", **kwargs - ), - ) - + }, + "model_explainability_job_output_config": { + "kms_key_id": { + "type": "string" + } + }, + "job_resources": { + "cluster_config": { + "volume_kms_key_id": { + "type": "string" + } + } + }, + "role_arn": { + "type": "string" + }, + "model_explainability_baseline_config": { + "constraints_resource": { + "s3_uri": { + "type": "string" + } + } + }, + "network_config": { + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "ModelExplainabilityJobDefinition", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -19756,9 +19528,7 @@ def create( model_explainability_job_output_config: shapes.MonitoringOutputConfig, job_resources: shapes.MonitoringResources, role_arn: str, - model_explainability_baseline_config: Optional[ - shapes.ModelExplainabilityBaselineConfig - ] = Unassigned(), + model_explainability_baseline_config: Optional[shapes.ModelExplainabilityBaselineConfig] = Unassigned(), network_config: Optional[shapes.MonitoringNetworkConfig] = Unassigned(), stopping_condition: Optional[shapes.MonitoringStoppingCondition] = Unassigned(), tags: Optional[List[shapes.Tag]] = Unassigned(), @@ -19767,26 +19537,26 @@ def create( ) -> Optional["ModelExplainabilityJobDefinition"]: """ Create a ModelExplainabilityJobDefinition resource - + Parameters: job_definition_name: The name of the model explainability job definition. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. model_explainability_app_specification: Configures the model explainability job to run a specified Docker container image. model_explainability_job_input: Inputs for the model explainability job. - model_explainability_job_output_config: - job_resources: + model_explainability_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform tasks on your behalf. model_explainability_baseline_config: The baseline configuration for a model explainability job. network_config: Networking options for a model explainability job. - stopping_condition: + stopping_condition: tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. session: Boto3 session. region: Region name. - + Returns: The ModelExplainabilityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19801,41 +19571,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model_explainability_job_definition resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "JobDefinitionName": job_definition_name, - "ModelExplainabilityBaselineConfig": model_explainability_baseline_config, - "ModelExplainabilityAppSpecification": model_explainability_app_specification, - "ModelExplainabilityJobInput": model_explainability_job_input, - "ModelExplainabilityJobOutputConfig": model_explainability_job_output_config, - "JobResources": job_resources, - "NetworkConfig": network_config, - "RoleArn": role_arn, - "StoppingCondition": stopping_condition, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ModelExplainabilityJobDefinition", - operation_input_args=operation_input_args, - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'JobDefinitionName': job_definition_name, + 'ModelExplainabilityBaselineConfig': model_explainability_baseline_config, + 'ModelExplainabilityAppSpecification': model_explainability_app_specification, + 'ModelExplainabilityJobInput': model_explainability_job_input, + 'ModelExplainabilityJobOutputConfig': model_explainability_job_output_config, + 'JobResources': job_resources, + 'NetworkConfig': network_config, + 'RoleArn': role_arn, + 'StoppingCondition': stopping_condition, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ModelExplainabilityJobDefinition', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model_explainability_job_definition(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(job_definition_name=job_definition_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -19846,17 +19611,17 @@ def get( ) -> Optional["ModelExplainabilityJobDefinition"]: """ Get a ModelExplainabilityJobDefinition resource - + Parameters: job_definition_name: The name of the model explainability job definition. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. session: Boto3 session. region: Region name. - + Returns: The ModelExplainabilityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19867,40 +19632,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": job_definition_name, + 'JobDefinitionName': job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model_explainability_job_definition(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform( - response, "DescribeModelExplainabilityJobDefinitionResponse" - ) + transformed_response = transform(response, 'DescribeModelExplainabilityJobDefinitionResponse') model_explainability_job_definition = cls(**transformed_response) return model_explainability_job_definition - + @Base.add_validate_call def refresh( self, - ) -> Optional["ModelExplainabilityJobDefinition"]: + + ) -> Optional["ModelExplainabilityJobDefinition"]: """ Refresh a ModelExplainabilityJobDefinition resource - + Returns: The ModelExplainabilityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19911,30 +19673,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model_explainability_job_definition(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelExplainabilityJobDefinitionResponse", self) + transform(response, 'DescribeModelExplainabilityJobDefinitionResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ModelExplainabilityJobDefinition resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -19945,20 +19708,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_model_explainability_job_definition(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -19974,7 +19737,7 @@ def get_all( ) -> ResourceIterator["ModelExplainabilityJobDefinition"]: """ Get all ModelExplainabilityJobDefinition resources - + Parameters: endpoint_name: Name of the endpoint to monitor for model explainability. sort_by: Whether to sort results by the Name or CreationTime field. The default is CreationTime. @@ -19986,12 +19749,12 @@ def get_all( creation_time_after: A filter that returns only model explainability jobs created after a specified time. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelExplainabilityJobDefinition resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20001,43 +19764,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "EndpointName": endpoint_name, - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - } - - custom_key_mapping = { - "monitoring_job_definition_name": "job_definition_name", - "monitoring_job_definition_arn": "job_definition_arn", + 'EndpointName': endpoint_name, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, } + + custom_key_mapping = {"monitoring_job_definition_name": "job_definition_name", "monitoring_job_definition_arn": "job_definition_arn"} # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_model_explainability_job_definitions", - summaries_key="JobDefinitionSummaries", - summary_name="MonitoringJobDefinitionSummary", + list_method='list_model_explainability_job_definitions', + summaries_key='JobDefinitionSummaries', + summary_name='MonitoringJobDefinitionSummary', resource_cls=ModelExplainabilityJobDefinition, custom_key_mapping=custom_key_mapping, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ModelPackage(Base): """ Class representing resource ModelPackage - + Attributes: model_package_name: The name of the model package being described. model_package_arn: The Amazon Resource Name (ARN) of the model package. @@ -20052,26 +19810,25 @@ class ModelPackage(Base): validation_specification: Configurations for one or more transform jobs that SageMaker runs to test the model package. certify_for_marketplace: Whether the model package is certified for listing on Amazon Web Services Marketplace. model_approval_status: The approval status of the model package. - created_by: - metadata_properties: + created_by: + metadata_properties: model_metrics: Metrics for the model. last_modified_time: The last time that the model package was modified. - last_modified_by: + last_modified_by: approval_description: A description provided for the model approval. domain: The machine learning domain of the model package you specified. Common machine learning domains include computer vision and natural language processing. task: The machine learning task you specified that your model package accomplishes. Common machine learning tasks include object detection and image classification. sample_payload_url: The Amazon Simple Storage Service (Amazon S3) path where the sample payload are stored. This path points to a single gzip compressed tar archive (.tar.gz suffix). customer_metadata_properties: The metadata properties associated with the model package versions. - drift_check_baselines: Represents the drift check baselines that can be used when the model monitor is set using the model package. For more information, see the topic on Drift Detection against Previous Baselines in SageMaker Pipelines in the Amazon SageMaker Developer Guide. + drift_check_baselines: Represents the drift check baselines that can be used when the model monitor is set using the model package. For more information, see the topic on Drift Detection against Previous Baselines in SageMaker Pipelines in the Amazon SageMaker Developer Guide. additional_inference_specifications: An array of additional Inference Specification objects. Each additional Inference Specification specifies artifacts based on this model package that can be used on inference endpoints. Generally used with SageMaker Neo to store the compiled artifacts. skip_model_validation: Indicates if you want to skip model validation. source_uri: The URI of the source for the model package. security_config: The KMS Key ID (KMSKeyId) used for encryption of model package information. model_card: The model card associated with the model package. Since ModelPackageModelCard is tied to a model package, it is a specific usage of a model card and its schema is simplified compared to the schema of ModelCard. The ModelPackageModelCard schema does not include model_package_details, and model_overview is composed of the model_creator and model_artifact properties. For more information about the model package model card schema, see Model package model card schema. For more information about the model card associated with the model package, see View the Details of a Model Version. - model_life_cycle: A structure describing the current state of the model in its life cycle. - + model_life_cycle: A structure describing the current state of the model in its life cycle. + """ - model_package_name: str model_package_group_name: Optional[str] = Unassigned() model_package_version: Optional[int] = Unassigned() @@ -20096,82 +19853,154 @@ class ModelPackage(Base): sample_payload_url: Optional[str] = Unassigned() customer_metadata_properties: Optional[Dict[str, str]] = Unassigned() drift_check_baselines: Optional[shapes.DriftCheckBaselines] = Unassigned() - additional_inference_specifications: Optional[ - List[shapes.AdditionalInferenceSpecificationDefinition] - ] = Unassigned() + additional_inference_specifications: Optional[List[shapes.AdditionalInferenceSpecificationDefinition]] = Unassigned() skip_model_validation: Optional[str] = Unassigned() source_uri: Optional[str] = Unassigned() security_config: Optional[shapes.ModelPackageSecurityConfig] = Unassigned() model_card: Optional[shapes.ModelPackageModelCard] = Unassigned() model_life_cycle: Optional[shapes.ModelLifeCycle] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_package_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_package_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model_package") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "validation_specification": {"validation_role": {"type": "string"}}, - "model_metrics": { - "model_quality": { - "statistics": {"s3_uri": {"type": "string"}}, - "constraints": {"s3_uri": {"type": "string"}}, - }, - "model_data_quality": { - "statistics": {"s3_uri": {"type": "string"}}, - "constraints": {"s3_uri": {"type": "string"}}, - }, - "bias": { - "report": {"s3_uri": {"type": "string"}}, - "pre_training_report": {"s3_uri": {"type": "string"}}, - "post_training_report": {"s3_uri": {"type": "string"}}, - }, - "explainability": {"report": {"s3_uri": {"type": "string"}}}, - }, - "drift_check_baselines": { - "bias": { - "config_file": {"s3_uri": {"type": "string"}}, - "pre_training_constraints": {"s3_uri": {"type": "string"}}, - "post_training_constraints": {"s3_uri": {"type": "string"}}, - }, - "explainability": { - "constraints": {"s3_uri": {"type": "string"}}, - "config_file": {"s3_uri": {"type": "string"}}, - }, - "model_quality": { - "statistics": {"s3_uri": {"type": "string"}}, - "constraints": {"s3_uri": {"type": "string"}}, - }, - "model_data_quality": { - "statistics": {"s3_uri": {"type": "string"}}, - "constraints": {"s3_uri": {"type": "string"}}, - }, - }, - "security_config": {"kms_key_id": {"type": "string"}}, + config_schema_for_resource = \ + { + "validation_specification": { + "validation_role": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "ModelPackage", **kwargs - ), - ) - + }, + "model_metrics": { + "model_quality": { + "statistics": { + "s3_uri": { + "type": "string" + } + }, + "constraints": { + "s3_uri": { + "type": "string" + } + } + }, + "model_data_quality": { + "statistics": { + "s3_uri": { + "type": "string" + } + }, + "constraints": { + "s3_uri": { + "type": "string" + } + } + }, + "bias": { + "report": { + "s3_uri": { + "type": "string" + } + }, + "pre_training_report": { + "s3_uri": { + "type": "string" + } + }, + "post_training_report": { + "s3_uri": { + "type": "string" + } + } + }, + "explainability": { + "report": { + "s3_uri": { + "type": "string" + } + } + } + }, + "drift_check_baselines": { + "bias": { + "config_file": { + "s3_uri": { + "type": "string" + } + }, + "pre_training_constraints": { + "s3_uri": { + "type": "string" + } + }, + "post_training_constraints": { + "s3_uri": { + "type": "string" + } + } + }, + "explainability": { + "constraints": { + "s3_uri": { + "type": "string" + } + }, + "config_file": { + "s3_uri": { + "type": "string" + } + } + }, + "model_quality": { + "statistics": { + "s3_uri": { + "type": "string" + } + }, + "constraints": { + "s3_uri": { + "type": "string" + } + } + }, + "model_data_quality": { + "statistics": { + "s3_uri": { + "type": "string" + } + }, + "constraints": { + "s3_uri": { + "type": "string" + } + } + } + }, + "security_config": { + "kms_key_id": { + "type": "string" + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "ModelPackage", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -20181,12 +20010,8 @@ def create( model_package_group_name: Optional[Union[str, object]] = Unassigned(), model_package_description: Optional[str] = Unassigned(), inference_specification: Optional[shapes.InferenceSpecification] = Unassigned(), - validation_specification: Optional[ - shapes.ModelPackageValidationSpecification - ] = Unassigned(), - source_algorithm_specification: Optional[ - shapes.SourceAlgorithmSpecification - ] = Unassigned(), + validation_specification: Optional[shapes.ModelPackageValidationSpecification] = Unassigned(), + source_algorithm_specification: Optional[shapes.SourceAlgorithmSpecification] = Unassigned(), certify_for_marketplace: Optional[bool] = Unassigned(), tags: Optional[List[shapes.Tag]] = Unassigned(), model_approval_status: Optional[str] = Unassigned(), @@ -20198,9 +20023,7 @@ def create( sample_payload_url: Optional[str] = Unassigned(), customer_metadata_properties: Optional[Dict[str, str]] = Unassigned(), drift_check_baselines: Optional[shapes.DriftCheckBaselines] = Unassigned(), - additional_inference_specifications: Optional[ - List[shapes.AdditionalInferenceSpecificationDefinition] - ] = Unassigned(), + additional_inference_specifications: Optional[List[shapes.AdditionalInferenceSpecificationDefinition]] = Unassigned(), skip_model_validation: Optional[str] = Unassigned(), source_uri: Optional[str] = Unassigned(), security_config: Optional[shapes.ModelPackageSecurityConfig] = Unassigned(), @@ -20211,39 +20034,39 @@ def create( ) -> Optional["ModelPackage"]: """ Create a ModelPackage resource - + Parameters: model_package_name: The name of the model package. The name must have 1 to 63 characters. Valid characters are a-z, A-Z, 0-9, and - (hyphen). This parameter is required for unversioned models. It is not applicable to versioned models. model_package_group_name: The name or Amazon Resource Name (ARN) of the model package group that this model version belongs to. This parameter is required for versioned models, and does not apply to unversioned models. model_package_description: A description of the model package. - inference_specification: Specifies details about inference jobs that you can run with models based on this model package, including the following information: The Amazon ECR paths of containers that contain the inference code and model artifacts. The instance types that the model package supports for transform jobs and real-time endpoints used for inference. The input and output content formats that the model package supports for inference. + inference_specification: Specifies details about inference jobs that you can run with models based on this model package, including the following information: The Amazon ECR paths of containers that contain the inference code and model artifacts. The instance types that the model package supports for transform jobs and real-time endpoints used for inference. The input and output content formats that the model package supports for inference. validation_specification: Specifies configurations for one or more transform jobs that SageMaker runs to test the model package. source_algorithm_specification: Details about the algorithm that was used to create the model package. certify_for_marketplace: Whether to certify the model package for listing on Amazon Web Services Marketplace. This parameter is optional for unversioned models, and does not apply to versioned models. - tags: A list of key value pairs associated with the model. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference Guide. If you supply ModelPackageGroupName, your model package belongs to the model group you specify and uses the tags associated with the model group. In this case, you cannot supply a tag argument. + tags: A list of key value pairs associated with the model. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference Guide. If you supply ModelPackageGroupName, your model package belongs to the model group you specify and uses the tags associated with the model group. In this case, you cannot supply a tag argument. model_approval_status: Whether the model is approved for deployment. This parameter is optional for versioned models, and does not apply to unversioned models. For versioned models, the value of this parameter must be set to Approved to deploy the model. - metadata_properties: + metadata_properties: model_metrics: A structure that contains model metrics reports. client_token: A unique token that guarantees that the call to this API is idempotent. domain: The machine learning domain of your model package and its components. Common machine learning domains include computer vision and natural language processing. task: The machine learning task your model package accomplishes. Common machine learning tasks include object detection and image classification. The following tasks are supported by Inference Recommender: "IMAGE_CLASSIFICATION" \| "OBJECT_DETECTION" \| "TEXT_GENERATION" \|"IMAGE_SEGMENTATION" \| "FILL_MASK" \| "CLASSIFICATION" \| "REGRESSION" \| "OTHER". Specify "OTHER" if none of the tasks listed fit your use case. sample_payload_url: The Amazon Simple Storage Service (Amazon S3) path where the sample payload is stored. This path must point to a single gzip compressed tar archive (.tar.gz suffix). This archive can hold multiple files that are all equally used in the load test. Each file in the archive must satisfy the size constraints of the InvokeEndpoint call. customer_metadata_properties: The metadata properties associated with the model package versions. - drift_check_baselines: Represents the drift check baselines that can be used when the model monitor is set using the model package. For more information, see the topic on Drift Detection against Previous Baselines in SageMaker Pipelines in the Amazon SageMaker Developer Guide. - additional_inference_specifications: An array of additional Inference Specification objects. Each additional Inference Specification specifies artifacts based on this model package that can be used on inference endpoints. Generally used with SageMaker Neo to store the compiled artifacts. + drift_check_baselines: Represents the drift check baselines that can be used when the model monitor is set using the model package. For more information, see the topic on Drift Detection against Previous Baselines in SageMaker Pipelines in the Amazon SageMaker Developer Guide. + additional_inference_specifications: An array of additional Inference Specification objects. Each additional Inference Specification specifies artifacts based on this model package that can be used on inference endpoints. Generally used with SageMaker Neo to store the compiled artifacts. skip_model_validation: Indicates if you want to skip model validation. source_uri: The URI of the source for the model package. If you want to clone a model package, set it to the model package Amazon Resource Name (ARN). If you want to register a model, set it to the model ARN. security_config: The KMS Key ID (KMSKeyId) used for encryption of model package information. model_card: The model card associated with the model package. Since ModelPackageModelCard is tied to a model package, it is a specific usage of a model card and its schema is simplified compared to the schema of ModelCard. The ModelPackageModelCard schema does not include model_package_details, and model_overview is composed of the model_creator and model_artifact properties. For more information about the model package model card schema, see Model package model card schema. For more information about the model card associated with the model package, see View the Details of a Model Version. - model_life_cycle: A structure describing the current state of the model in its life cycle. + model_life_cycle: A structure describing the current state of the model in its life cycle. session: Boto3 session. region: Region name. - + Returns: The ModelPackage resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20258,55 +20081,49 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model_package resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ModelPackageName": model_package_name, - "ModelPackageGroupName": model_package_group_name, - "ModelPackageDescription": model_package_description, - "InferenceSpecification": inference_specification, - "ValidationSpecification": validation_specification, - "SourceAlgorithmSpecification": source_algorithm_specification, - "CertifyForMarketplace": certify_for_marketplace, - "Tags": tags, - "ModelApprovalStatus": model_approval_status, - "MetadataProperties": metadata_properties, - "ModelMetrics": model_metrics, - "ClientToken": client_token, - "Domain": domain, - "Task": task, - "SamplePayloadUrl": sample_payload_url, - "CustomerMetadataProperties": customer_metadata_properties, - "DriftCheckBaselines": drift_check_baselines, - "AdditionalInferenceSpecifications": additional_inference_specifications, - "SkipModelValidation": skip_model_validation, - "SourceUri": source_uri, - "SecurityConfig": security_config, - "ModelCard": model_card, - "ModelLifeCycle": model_life_cycle, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ModelPackage", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ModelPackageName': model_package_name, + 'ModelPackageGroupName': model_package_group_name, + 'ModelPackageDescription': model_package_description, + 'InferenceSpecification': inference_specification, + 'ValidationSpecification': validation_specification, + 'SourceAlgorithmSpecification': source_algorithm_specification, + 'CertifyForMarketplace': certify_for_marketplace, + 'Tags': tags, + 'ModelApprovalStatus': model_approval_status, + 'MetadataProperties': metadata_properties, + 'ModelMetrics': model_metrics, + 'ClientToken': client_token, + 'Domain': domain, + 'Task': task, + 'SamplePayloadUrl': sample_payload_url, + 'CustomerMetadataProperties': customer_metadata_properties, + 'DriftCheckBaselines': drift_check_baselines, + 'AdditionalInferenceSpecifications': additional_inference_specifications, + 'SkipModelValidation': skip_model_validation, + 'SourceUri': source_uri, + 'SecurityConfig': security_config, + 'ModelCard': model_card, + 'ModelLifeCycle': model_life_cycle, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ModelPackage', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model_package(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - model_package_name=response["ModelPackageName"], session=session, region=region - ) - + + return cls.get(model_package_name=response['ModelPackageName'], session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -20317,17 +20134,17 @@ def get( ) -> Optional["ModelPackage"]: """ Get a ModelPackage resource - + Parameters: model_package_name: The name or Amazon Resource Name (ARN) of the model package to describe. When you specify a name, the name must have 1 to 63 characters. Valid characters are a-z, A-Z, 0-9, and - (hyphen). session: Boto3 session. region: Region name. - + Returns: The ModelPackage resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20337,38 +20154,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ModelPackageName": model_package_name, + 'ModelPackageName': model_package_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model_package(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeModelPackageOutput") + transformed_response = transform(response, 'DescribeModelPackageOutput') model_package = cls(**transformed_response) return model_package - + @Base.add_validate_call def refresh( self, - ) -> Optional["ModelPackage"]: + + ) -> Optional["ModelPackage"]: """ Refresh a ModelPackage resource - + Returns: The ModelPackage resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20378,21 +20194,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ModelPackageName": self.model_package_name, + 'ModelPackageName': self.model_package_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model_package(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelPackageOutput", self) + transform(response, 'DescribeModelPackageOutput', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -20401,9 +20217,7 @@ def update( approval_description: Optional[str] = Unassigned(), customer_metadata_properties: Optional[Dict[str, str]] = Unassigned(), customer_metadata_properties_to_remove: Optional[List[str]] = Unassigned(), - additional_inference_specifications_to_add: Optional[ - List[shapes.AdditionalInferenceSpecificationDefinition] - ] = Unassigned(), + additional_inference_specifications_to_add: Optional[List[shapes.AdditionalInferenceSpecificationDefinition]] = Unassigned(), inference_specification: Optional[shapes.InferenceSpecification] = Unassigned(), source_uri: Optional[str] = Unassigned(), model_card: Optional[shapes.ModelPackageModelCard] = Unassigned(), @@ -20412,17 +20226,17 @@ def update( ) -> Optional["ModelPackage"]: """ Update a ModelPackage resource - + Parameters: customer_metadata_properties_to_remove: The metadata properties associated with the model package versions to remove. additional_inference_specifications_to_add: An array of additional Inference Specification objects to be added to the existing array additional Inference Specification. Total number of additional Inference Specifications can not exceed 15. Each additional Inference Specification specifies artifacts based on this model package that can be used on inference endpoints. Generally used with SageMaker Neo to store the compiled artifacts. - client_token: A unique token that guarantees that the call to this API is idempotent. - + client_token: A unique token that guarantees that the call to this API is idempotent. + Returns: The ModelPackage resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20433,44 +20247,45 @@ def update( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + logger.info("Updating model_package resource.") client = Base.get_sagemaker_client() - - operation_input_args = { - "ModelPackageArn": self.model_package_arn, - "ModelApprovalStatus": model_approval_status, - "ApprovalDescription": approval_description, - "CustomerMetadataProperties": customer_metadata_properties, - "CustomerMetadataPropertiesToRemove": customer_metadata_properties_to_remove, - "AdditionalInferenceSpecificationsToAdd": additional_inference_specifications_to_add, - "InferenceSpecification": inference_specification, - "SourceUri": source_uri, - "ModelCard": model_card, - "ModelLifeCycle": model_life_cycle, - "ClientToken": client_token, + + operation_input_args = { + 'ModelPackageArn': self.model_package_arn, + 'ModelApprovalStatus': model_approval_status, + 'ApprovalDescription': approval_description, + 'CustomerMetadataProperties': customer_metadata_properties, + 'CustomerMetadataPropertiesToRemove': customer_metadata_properties_to_remove, + 'AdditionalInferenceSpecificationsToAdd': additional_inference_specifications_to_add, + 'InferenceSpecification': inference_specification, + 'SourceUri': source_uri, + 'ModelCard': model_card, + 'ModelLifeCycle': model_life_cycle, + 'ClientToken': client_token, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_model_package(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ModelPackage resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20481,76 +20296,74 @@ def delete( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ModelPackageName": self.model_package_name, + 'ModelPackageName': self.model_package_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_model_package(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Pending", "InProgress", "Completed", "Failed", "Deleting"], + target_status: Literal['Pending', 'InProgress', 'Completed', 'Failed', 'Deleting'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a ModelPackage resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for ModelPackage to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.model_package_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="ModelPackage", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="ModelPackage", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="ModelPackage", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -20559,13 +20372,13 @@ def wait_for_delete( ) -> None: """ Wait for a ModelPackage resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20579,41 +20392,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for ModelPackage to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.model_package_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ModelPackage", status=current_status - ) + raise TimeoutExceededError(resouce_type="ModelPackage", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -20631,7 +20437,7 @@ def get_all( ) -> ResourceIterator["ModelPackage"]: """ Get all ModelPackage resources - + Parameters: creation_time_after: A filter that returns only model packages created after the specified time (timestamp). creation_time_before: A filter that returns only model packages created before the specified time (timestamp). @@ -20639,18 +20445,18 @@ def get_all( name_contains: A string in the model package name. This filter returns only model packages whose name contains the specified string. model_approval_status: A filter that returns only the model packages with the specified approval status. model_package_group_name: A filter that returns only model versions that belong to the specified model group. - model_package_type: A filter that returns only the model packages of the specified type. This can be one of the following values. UNVERSIONED - List only unversioined models. This is the default value if no ModelPackageType is specified. VERSIONED - List only versioned models. BOTH - List both versioned and unversioned models. + model_package_type: A filter that returns only the model packages of the specified type. This can be one of the following values. UNVERSIONED - List only unversioined models. This is the default value if no ModelPackageType is specified. VERSIONED - List only versioned models. BOTH - List both versioned and unversioned models. next_token: If the response to a previous ListModelPackages request was truncated, the response includes a NextToken. To retrieve the next set of model packages, use the token in the next request. sort_by: The parameter by which to sort the results. The default is CreationTime. sort_order: The sort order for the results. The default is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelPackage resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20660,35 +20466,35 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "NameContains": name_contains, - "ModelApprovalStatus": model_approval_status, - "ModelPackageGroupName": model_package_group_name, - "ModelPackageType": model_package_type, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'NameContains': name_contains, + 'ModelApprovalStatus': model_approval_status, + 'ModelPackageGroupName': model_package_group_name, + 'ModelPackageType': model_package_type, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_model_packages", - summaries_key="ModelPackageSummaryList", - summary_name="ModelPackageSummary", + list_method='list_model_packages', + summaries_key='ModelPackageSummaryList', + summary_name='ModelPackageSummary', resource_cls=ModelPackage, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def batch_get( self, @@ -20698,17 +20504,17 @@ def batch_get( ) -> Optional[shapes.BatchDescribeModelPackageOutput]: """ This action batch describes a list of versioned model packages. - + Parameters: model_package_arn_list: The list of Amazon Resource Name (ARN) of the model package groups. session: Boto3 session. region: Region name. - + Returns: shapes.BatchDescribeModelPackageOutput - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20718,63 +20524,61 @@ def batch_get( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "ModelPackageArnList": model_package_arn_list, + 'ModelPackageArnList': model_package_arn_list, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling batch_describe_model_package API") response = client.batch_describe_model_package(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "BatchDescribeModelPackageOutput") + + transformed_response = transform(response, 'BatchDescribeModelPackageOutput') return shapes.BatchDescribeModelPackageOutput(**transformed_response) class ModelPackageGroup(Base): """ Class representing resource ModelPackageGroup - + Attributes: model_package_group_name: The name of the model group. model_package_group_arn: The Amazon Resource Name (ARN) of the model group. creation_time: The time that the model group was created. - created_by: + created_by: model_package_group_status: The status of the model group. model_package_group_description: A description of the model group. - + """ - model_package_group_name: str model_package_group_arn: Optional[str] = Unassigned() model_package_group_description: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() created_by: Optional[shapes.UserContext] = Unassigned() model_package_group_status: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_package_group_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_package_group_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model_package_group") return None - + @classmethod @Base.add_validate_call def create( @@ -20787,19 +20591,19 @@ def create( ) -> Optional["ModelPackageGroup"]: """ Create a ModelPackageGroup resource - + Parameters: model_package_group_name: The name of the model group. model_package_group_description: A description for the model group. tags: A list of key value pairs associated with the model group. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference Guide. session: Boto3 session. region: Region name. - + Returns: The ModelPackageGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20813,35 +20617,29 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model_package_group resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "ModelPackageGroupName": model_package_group_name, - "ModelPackageGroupDescription": model_package_group_description, - "Tags": tags, + 'ModelPackageGroupName': model_package_group_name, + 'ModelPackageGroupDescription': model_package_group_description, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ModelPackageGroup", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='ModelPackageGroup', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model_package_group(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - model_package_group_name=model_package_group_name, session=session, region=region - ) - + + return cls.get(model_package_group_name=model_package_group_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -20852,17 +20650,17 @@ def get( ) -> Optional["ModelPackageGroup"]: """ Get a ModelPackageGroup resource - + Parameters: model_package_group_name: The name of the model group to describe. session: Boto3 session. region: Region name. - + Returns: The ModelPackageGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20872,38 +20670,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ModelPackageGroupName": model_package_group_name, + 'ModelPackageGroupName': model_package_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model_package_group(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeModelPackageGroupOutput") + transformed_response = transform(response, 'DescribeModelPackageGroupOutput') model_package_group = cls(**transformed_response) return model_package_group - + @Base.add_validate_call def refresh( self, - ) -> Optional["ModelPackageGroup"]: + + ) -> Optional["ModelPackageGroup"]: """ Refresh a ModelPackageGroup resource - + Returns: The ModelPackageGroup resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20913,30 +20710,31 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ModelPackageGroupName": self.model_package_group_name, + 'ModelPackageGroupName': self.model_package_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model_package_group(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelPackageGroupOutput", self) + transform(response, 'DescribeModelPackageGroupOutput', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ModelPackageGroup resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -20947,80 +20745,74 @@ def delete( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ModelPackageGroupName": self.model_package_group_name, + 'ModelPackageGroupName': self.model_package_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_model_package_group(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Pending", "InProgress", "Completed", "Failed", "Deleting", "DeleteFailed" - ], + target_status: Literal['Pending', 'InProgress', 'Completed', 'Failed', 'Deleting', 'DeleteFailed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a ModelPackageGroup resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for ModelPackageGroup to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.model_package_group_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="ModelPackageGroup", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="ModelPackageGroup", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ModelPackageGroup", status=current_status - ) + raise TimeoutExceededError(resouce_type="ModelPackageGroup", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -21029,13 +20821,13 @@ def wait_for_delete( ) -> None: """ Wait for a ModelPackageGroup resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21049,41 +20841,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for ModelPackageGroup to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.model_package_group_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="ModelPackageGroup", status=current_status - ) + raise TimeoutExceededError(resouce_type="ModelPackageGroup", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -21099,7 +20884,7 @@ def get_all( ) -> ResourceIterator["ModelPackageGroup"]: """ Get all ModelPackageGroup resources - + Parameters: creation_time_after: A filter that returns only model groups created after the specified time. creation_time_before: A filter that returns only model groups created before the specified time. @@ -21111,12 +20896,12 @@ def get_all( cross_account_filter_option: A filter that returns either model groups shared with you or model groups in your own account. When the value is CrossAccount, the results show the resources made discoverable to you from other accounts. When the value is SameAccount or null, the results show resources from your account. The default is SameAccount. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelPackageGroup resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21126,51 +20911,52 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, - "CrossAccountFilterOption": cross_account_filter_option, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'CrossAccountFilterOption': cross_account_filter_option, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_model_package_groups", - summaries_key="ModelPackageGroupSummaryList", - summary_name="ModelPackageGroupSummary", + list_method='list_model_package_groups', + summaries_key='ModelPackageGroupSummaryList', + summary_name='ModelPackageGroupSummary', resource_cls=ModelPackageGroup, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_policy( self, + session: Optional[Session] = None, region: Optional[str] = None, ) -> Optional[str]: """ Gets a resource policy that manages access for a model group. - + Parameters: session: Boto3 session. region: Region name. - + Returns: str - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21180,39 +20966,40 @@ def get_policy( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "ModelPackageGroupName": self.model_package_group_name, + 'ModelPackageGroupName': self.model_package_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling get_model_package_group_policy API") response = client.get_model_package_group_policy(**operation_input_args) logger.debug(f"Response: {response}") - + return list(response.values())[0] - + + @Base.add_validate_call def delete_policy( self, + session: Optional[Session] = None, region: Optional[str] = None, ) -> None: """ Deletes a model group resource policy. - + Parameters: session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21222,22 +21009,23 @@ def delete_policy( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "ModelPackageGroupName": self.model_package_group_name, + 'ModelPackageGroupName': self.model_package_group_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling delete_model_package_group_policy API") response = client.delete_model_package_group_policy(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def put_policy( self, @@ -21247,14 +21035,14 @@ def put_policy( ) -> None: """ Adds a resouce policy to control access to a model group. - + Parameters: resource_policy: The resource policy for the model group. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21265,43 +21053,42 @@ def put_policy( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + + operation_input_args = { - "ModelPackageGroupName": self.model_package_group_name, - "ResourcePolicy": resource_policy, + 'ModelPackageGroupName': self.model_package_group_name, + 'ResourcePolicy': resource_policy, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling put_model_package_group_policy API") response = client.put_model_package_group_policy(**operation_input_args) logger.debug(f"Response: {response}") + class ModelQualityJobDefinition(Base): """ Class representing resource ModelQualityJobDefinition - + Attributes: job_definition_arn: The Amazon Resource Name (ARN) of the model quality job. job_definition_name: The name of the quality job definition. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. creation_time: The time at which the model quality job was created. model_quality_app_specification: Configures the model quality job to run a specified Docker container image. model_quality_job_input: Inputs for the model quality job. - model_quality_job_output_config: - job_resources: + model_quality_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform tasks on your behalf. model_quality_baseline_config: The baseline configuration for a model quality job. network_config: Networking options for a model quality job. - stopping_condition: - + stopping_condition: + """ - job_definition_name: str job_definition_arn: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() @@ -21313,61 +21100,97 @@ class ModelQualityJobDefinition(Base): network_config: Optional[shapes.MonitoringNetworkConfig] = Unassigned() role_arn: Optional[str] = Unassigned() stopping_condition: Optional[shapes.MonitoringStoppingCondition] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "model_quality_job_definition_name" - resource_name_split = resource_name.split("_") + resource_name = 'model_quality_job_definition_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object model_quality_job_definition") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "model_quality_job_input": { - "ground_truth_s3_input": {"s3_uri": {"type": "string"}}, - "endpoint_input": { - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - "batch_transform_input": { - "data_captured_destination_s3_uri": {"type": "string"}, - "s3_input_mode": {"type": "string"}, - "s3_data_distribution_type": {"type": "string"}, - }, - }, - "model_quality_job_output_config": {"kms_key_id": {"type": "string"}}, - "job_resources": {"cluster_config": {"volume_kms_key_id": {"type": "string"}}}, - "role_arn": {"type": "string"}, - "model_quality_baseline_config": { - "constraints_resource": {"s3_uri": {"type": "string"}} - }, - "network_config": { - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - } - }, + config_schema_for_resource = \ + { + "model_quality_job_input": { + "ground_truth_s3_input": { + "s3_uri": { + "type": "string" + } + }, + "endpoint_input": { + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } + }, + "batch_transform_input": { + "data_captured_destination_s3_uri": { + "type": "string" + }, + "s3_input_mode": { + "type": "string" + }, + "s3_data_distribution_type": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "ModelQualityJobDefinition", **kwargs - ), - ) - + }, + "model_quality_job_output_config": { + "kms_key_id": { + "type": "string" + } + }, + "job_resources": { + "cluster_config": { + "volume_kms_key_id": { + "type": "string" + } + } + }, + "role_arn": { + "type": "string" + }, + "model_quality_baseline_config": { + "constraints_resource": { + "s3_uri": { + "type": "string" + } + } + }, + "network_config": { + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "ModelQualityJobDefinition", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -21388,26 +21211,26 @@ def create( ) -> Optional["ModelQualityJobDefinition"]: """ Create a ModelQualityJobDefinition resource - + Parameters: job_definition_name: The name of the monitoring job definition. model_quality_app_specification: The container that runs the monitoring job. model_quality_job_input: A list of the inputs that are monitored. Currently endpoints are supported. - model_quality_job_output_config: - job_resources: + model_quality_job_output_config: + job_resources: role_arn: The Amazon Resource Name (ARN) of an IAM role that Amazon SageMaker AI can assume to perform tasks on your behalf. model_quality_baseline_config: Specifies the constraints and baselines for the monitoring job. network_config: Specifies the network configuration for the monitoring job. - stopping_condition: + stopping_condition: tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. session: Boto3 session. region: Region name. - + Returns: The ModelQualityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21422,40 +21245,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating model_quality_job_definition resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "JobDefinitionName": job_definition_name, - "ModelQualityBaselineConfig": model_quality_baseline_config, - "ModelQualityAppSpecification": model_quality_app_specification, - "ModelQualityJobInput": model_quality_job_input, - "ModelQualityJobOutputConfig": model_quality_job_output_config, - "JobResources": job_resources, - "NetworkConfig": network_config, - "RoleArn": role_arn, - "StoppingCondition": stopping_condition, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ModelQualityJobDefinition", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'JobDefinitionName': job_definition_name, + 'ModelQualityBaselineConfig': model_quality_baseline_config, + 'ModelQualityAppSpecification': model_quality_app_specification, + 'ModelQualityJobInput': model_quality_job_input, + 'ModelQualityJobOutputConfig': model_quality_job_output_config, + 'JobResources': job_resources, + 'NetworkConfig': network_config, + 'RoleArn': role_arn, + 'StoppingCondition': stopping_condition, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ModelQualityJobDefinition', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_model_quality_job_definition(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(job_definition_name=job_definition_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -21466,17 +21285,17 @@ def get( ) -> Optional["ModelQualityJobDefinition"]: """ Get a ModelQualityJobDefinition resource - + Parameters: job_definition_name: The name of the model quality job. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. session: Boto3 session. region: Region name. - + Returns: The ModelQualityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21487,38 +21306,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": job_definition_name, + 'JobDefinitionName': job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_model_quality_job_definition(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeModelQualityJobDefinitionResponse") + transformed_response = transform(response, 'DescribeModelQualityJobDefinitionResponse') model_quality_job_definition = cls(**transformed_response) return model_quality_job_definition - + @Base.add_validate_call def refresh( self, - ) -> Optional["ModelQualityJobDefinition"]: + + ) -> Optional["ModelQualityJobDefinition"]: """ Refresh a ModelQualityJobDefinition resource - + Returns: The ModelQualityJobDefinition resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21529,30 +21347,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_model_quality_job_definition(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeModelQualityJobDefinitionResponse", self) + transform(response, 'DescribeModelQualityJobDefinitionResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a ModelQualityJobDefinition resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21563,20 +21382,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "JobDefinitionName": self.job_definition_name, + 'JobDefinitionName': self.job_definition_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_model_quality_job_definition(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -21592,7 +21411,7 @@ def get_all( ) -> ResourceIterator["ModelQualityJobDefinition"]: """ Get all ModelQualityJobDefinition resources - + Parameters: endpoint_name: A filter that returns only model quality monitoring job definitions that are associated with the specified endpoint. sort_by: The field to sort results by. The default is CreationTime. @@ -21604,12 +21423,12 @@ def get_all( creation_time_after: A filter that returns only model quality monitoring job definitions created after the specified time. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ModelQualityJobDefinition resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21619,43 +21438,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "EndpointName": endpoint_name, - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - } - - custom_key_mapping = { - "monitoring_job_definition_name": "job_definition_name", - "monitoring_job_definition_arn": "job_definition_arn", + 'EndpointName': endpoint_name, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, } + + custom_key_mapping = {"monitoring_job_definition_name": "job_definition_name", "monitoring_job_definition_arn": "job_definition_arn"} # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_model_quality_job_definitions", - summaries_key="JobDefinitionSummaries", - summary_name="MonitoringJobDefinitionSummary", + list_method='list_model_quality_job_definitions', + summaries_key='JobDefinitionSummaries', + summary_name='MonitoringJobDefinitionSummary', resource_cls=ModelQualityJobDefinition, custom_key_mapping=custom_key_mapping, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class MonitoringAlert(Base): """ Class representing resource MonitoringAlert - + Attributes: monitoring_alert_name: The name of a monitoring alert. creation_time: A timestamp that indicates when a monitor alert was created. @@ -21664,9 +21478,8 @@ class MonitoringAlert(Base): datapoints_to_alert: Within EvaluationPeriod, how many execution failures will raise an alert. evaluation_period: The number of most recent monitoring executions to consider when evaluating alert status. actions: A list of alert actions taken in response to an alert going into InAlert status. - + """ - monitoring_alert_name: str creation_time: datetime.datetime last_modified_time: datetime.datetime @@ -21674,23 +21487,23 @@ class MonitoringAlert(Base): datapoints_to_alert: int evaluation_period: int actions: shapes.MonitoringAlertActions - + def get_name(self) -> str: attributes = vars(self) - resource_name = "monitoring_alert_name" - resource_name_split = resource_name.split("_") + resource_name = 'monitoring_alert_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object monitoring_alert") return None - + @Base.add_validate_call def update( self, @@ -21700,15 +21513,15 @@ def update( ) -> Optional["MonitoringAlert"]: """ Update a MonitoringAlert resource - + Parameters: monitoring_schedule_name: The name of a monitoring schedule. - + Returns: The MonitoringAlert resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21720,28 +21533,28 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating monitoring_alert resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "MonitoringScheduleName": monitoring_schedule_name, - "MonitoringAlertName": self.monitoring_alert_name, - "DatapointsToAlert": datapoints_to_alert, - "EvaluationPeriod": evaluation_period, + 'MonitoringScheduleName': monitoring_schedule_name, + 'MonitoringAlertName': self.monitoring_alert_name, + 'DatapointsToAlert': datapoints_to_alert, + 'EvaluationPeriod': evaluation_period, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_monitoring_alert(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @classmethod @Base.add_validate_call def get_all( @@ -21752,19 +21565,19 @@ def get_all( ) -> ResourceIterator["MonitoringAlert"]: """ Get all MonitoringAlert resources - + Parameters: monitoring_schedule_name: The name of a monitoring schedule. next_token: If the result of the previous ListMonitoringAlerts request was truncated, the response includes a NextToken. To retrieve the next set of alerts in the history, use the token in the next request. max_results: The maximum number of results to display. The default is 100. session: Boto3 session. region: Region name. - + Returns: Iterator for listed MonitoringAlert resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21775,28 +21588,28 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "MonitoringScheduleName": monitoring_schedule_name, + 'MonitoringScheduleName': monitoring_schedule_name, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_monitoring_alerts", - summaries_key="MonitoringAlertSummaries", - summary_name="MonitoringAlertSummary", + list_method='list_monitoring_alerts', + summaries_key='MonitoringAlertSummaries', + summary_name='MonitoringAlertSummary', resource_cls=MonitoringAlert, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def list_history( self, @@ -21813,7 +21626,7 @@ def list_history( ) -> Optional[shapes.MonitoringAlertHistorySummary]: """ Gets a list of past alerts in a model monitoring schedule. - + Parameters: monitoring_schedule_name: The name of a monitoring schedule. sort_by: The field used to sort results. The default is CreationTime. @@ -21825,12 +21638,12 @@ def list_history( status_equals: A filter that retrieves only alerts with a specific status. session: Boto3 session. region: Region name. - + Returns: shapes.MonitoringAlertHistorySummary - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21841,38 +21654,37 @@ def list_history( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "MonitoringScheduleName": monitoring_schedule_name, - "MonitoringAlertName": self.monitoring_alert_name, - "SortBy": sort_by, - "SortOrder": sort_order, - "NextToken": next_token, - "MaxResults": max_results, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "StatusEquals": status_equals, + 'MonitoringScheduleName': monitoring_schedule_name, + 'MonitoringAlertName': self.monitoring_alert_name, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NextToken': next_token, + 'MaxResults': max_results, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'StatusEquals': status_equals, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling list_monitoring_alert_history API") response = client.list_monitoring_alert_history(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "ListMonitoringAlertHistoryResponse") + + transformed_response = transform(response, 'ListMonitoringAlertHistoryResponse') return shapes.MonitoringAlertHistorySummary(**transformed_response) class MonitoringExecution(Base): """ Class representing resource MonitoringExecution - + Attributes: monitoring_schedule_name: The name of the monitoring schedule. scheduled_time: The time the monitoring job was scheduled. @@ -21884,9 +21696,8 @@ class MonitoringExecution(Base): failure_reason: Contains the reason a monitoring job failed, if it failed. monitoring_job_definition_name: The name of the monitoring job. monitoring_type: The type of the monitoring job. - + """ - monitoring_schedule_name: str scheduled_time: datetime.datetime creation_time: datetime.datetime @@ -21897,23 +21708,23 @@ class MonitoringExecution(Base): failure_reason: Optional[str] = Unassigned() monitoring_job_definition_name: Optional[str] = Unassigned() monitoring_type: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "monitoring_execution_name" - resource_name_split = resource_name.split("_") + resource_name = 'monitoring_execution_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object monitoring_execution") return None - + @classmethod @Base.add_validate_call def get_all( @@ -21936,7 +21747,7 @@ def get_all( ) -> ResourceIterator["MonitoringExecution"]: """ Get all MonitoringExecution resources - + Parameters: monitoring_schedule_name: Name of a specific schedule to fetch jobs for. endpoint_name: Name of a specific endpoint to fetch jobs for. @@ -21955,12 +21766,12 @@ def get_all( monitoring_type_equals: A filter that returns only the monitoring job runs of the specified monitoring type. session: Boto3 session. region: Region name. - + Returns: Iterator for listed MonitoringExecution resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -21970,45 +21781,44 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "MonitoringScheduleName": monitoring_schedule_name, - "EndpointName": endpoint_name, - "SortBy": sort_by, - "SortOrder": sort_order, - "ScheduledTimeBefore": scheduled_time_before, - "ScheduledTimeAfter": scheduled_time_after, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "StatusEquals": status_equals, - "MonitoringJobDefinitionName": monitoring_job_definition_name, - "MonitoringTypeEquals": monitoring_type_equals, + 'MonitoringScheduleName': monitoring_schedule_name, + 'EndpointName': endpoint_name, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'ScheduledTimeBefore': scheduled_time_before, + 'ScheduledTimeAfter': scheduled_time_after, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'StatusEquals': status_equals, + 'MonitoringJobDefinitionName': monitoring_job_definition_name, + 'MonitoringTypeEquals': monitoring_type_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_monitoring_executions", - summaries_key="MonitoringExecutionSummaries", - summary_name="MonitoringExecutionSummary", + list_method='list_monitoring_executions', + summaries_key='MonitoringExecutionSummaries', + summary_name='MonitoringExecutionSummary', resource_cls=MonitoringExecution, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class MonitoringSchedule(Base): """ Class representing resource MonitoringSchedule - + Attributes: monitoring_schedule_arn: The Amazon Resource Name (ARN) of the monitoring schedule. monitoring_schedule_name: Name of the monitoring schedule. @@ -22016,13 +21826,12 @@ class MonitoringSchedule(Base): creation_time: The time at which the monitoring job was created. last_modified_time: The time at which the monitoring job was last modified. monitoring_schedule_config: The configuration object that specifies the monitoring schedule and defines the monitoring job. - monitoring_type: The type of the monitoring job that this schedule runs. This is one of the following values. DATA_QUALITY - The schedule is for a data quality monitoring job. MODEL_QUALITY - The schedule is for a model quality monitoring job. MODEL_BIAS - The schedule is for a bias monitoring job. MODEL_EXPLAINABILITY - The schedule is for an explainability monitoring job. + monitoring_type: The type of the monitoring job that this schedule runs. This is one of the following values. DATA_QUALITY - The schedule is for a data quality monitoring job. MODEL_QUALITY - The schedule is for a model quality monitoring job. MODEL_BIAS - The schedule is for a bias monitoring job. MODEL_EXPLAINABILITY - The schedule is for an explainability monitoring job. failure_reason: A string, up to one KB in size, that contains the reason a monitoring job failed, if it failed. endpoint_name: The name of the endpoint for the monitoring job. last_monitoring_execution_summary: Describes metadata on the last execution to run, if there was one. - + """ - monitoring_schedule_name: str monitoring_schedule_arn: Optional[str] = Unassigned() monitoring_schedule_status: Optional[str] = Unassigned() @@ -22033,59 +21842,80 @@ class MonitoringSchedule(Base): monitoring_schedule_config: Optional[shapes.MonitoringScheduleConfig] = Unassigned() endpoint_name: Optional[str] = Unassigned() last_monitoring_execution_summary: Optional[shapes.MonitoringExecutionSummary] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "monitoring_schedule_name" - resource_name_split = resource_name.split("_") + resource_name = 'monitoring_schedule_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object monitoring_schedule") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "monitoring_schedule_config": { - "monitoring_job_definition": { - "monitoring_output_config": {"kms_key_id": {"type": "string"}}, - "monitoring_resources": { - "cluster_config": {"volume_kms_key_id": {"type": "string"}} - }, - "role_arn": {"type": "string"}, - "baseline_config": { - "constraints_resource": {"s3_uri": {"type": "string"}}, - "statistics_resource": {"s3_uri": {"type": "string"}}, - }, - "network_config": { - "vpc_config": { - "security_group_ids": { - "type": "array", - "items": {"type": "string"}, - }, - "subnets": {"type": "array", "items": {"type": "string"}}, - } - }, + config_schema_for_resource = \ + { + "monitoring_schedule_config": { + "monitoring_job_definition": { + "monitoring_output_config": { + "kms_key_id": { + "type": "string" + } + }, + "monitoring_resources": { + "cluster_config": { + "volume_kms_key_id": { + "type": "string" + } + } + }, + "role_arn": { + "type": "string" + }, + "baseline_config": { + "constraints_resource": { + "s3_uri": { + "type": "string" + } + }, + "statistics_resource": { + "s3_uri": { + "type": "string" + } + } + }, + "network_config": { + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" } + } } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "MonitoringSchedule", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "MonitoringSchedule", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -22099,19 +21929,19 @@ def create( ) -> Optional["MonitoringSchedule"]: """ Create a MonitoringSchedule resource - + Parameters: monitoring_schedule_name: The name of the monitoring schedule. The name must be unique within an Amazon Web Services Region within an Amazon Web Services account. monitoring_schedule_config: The configuration object that specifies the monitoring schedule and defines the monitoring job. tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. session: Boto3 session. region: Region name. - + Returns: The MonitoringSchedule resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22126,35 +21956,29 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating monitoring_schedule resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "MonitoringScheduleName": monitoring_schedule_name, - "MonitoringScheduleConfig": monitoring_schedule_config, - "Tags": tags, + 'MonitoringScheduleName': monitoring_schedule_name, + 'MonitoringScheduleConfig': monitoring_schedule_config, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="MonitoringSchedule", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='MonitoringSchedule', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_monitoring_schedule(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - monitoring_schedule_name=monitoring_schedule_name, session=session, region=region - ) - + + return cls.get(monitoring_schedule_name=monitoring_schedule_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -22165,17 +21989,17 @@ def get( ) -> Optional["MonitoringSchedule"]: """ Get a MonitoringSchedule resource - + Parameters: monitoring_schedule_name: Name of a previously created monitoring schedule. session: Boto3 session. region: Region name. - + Returns: The MonitoringSchedule resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22186,38 +22010,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "MonitoringScheduleName": monitoring_schedule_name, + 'MonitoringScheduleName': monitoring_schedule_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_monitoring_schedule(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeMonitoringScheduleResponse") + transformed_response = transform(response, 'DescribeMonitoringScheduleResponse') monitoring_schedule = cls(**transformed_response) return monitoring_schedule - + @Base.add_validate_call def refresh( self, - ) -> Optional["MonitoringSchedule"]: + + ) -> Optional["MonitoringSchedule"]: """ Refresh a MonitoringSchedule resource - + Returns: The MonitoringSchedule resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22228,21 +22051,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "MonitoringScheduleName": self.monitoring_schedule_name, + 'MonitoringScheduleName': self.monitoring_schedule_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_monitoring_schedule(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeMonitoringScheduleResponse", self) + transform(response, 'DescribeMonitoringScheduleResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -22251,12 +22074,12 @@ def update( ) -> Optional["MonitoringSchedule"]: """ Update a MonitoringSchedule resource - + Returns: The MonitoringSchedule resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22268,35 +22091,36 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating monitoring_schedule resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "MonitoringScheduleName": self.monitoring_schedule_name, - "MonitoringScheduleConfig": monitoring_schedule_config, + 'MonitoringScheduleName': self.monitoring_schedule_name, + 'MonitoringScheduleConfig': monitoring_schedule_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_monitoring_schedule(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a MonitoringSchedule resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22307,27 +22131,27 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "MonitoringScheduleName": self.monitoring_schedule_name, + 'MonitoringScheduleName': self.monitoring_schedule_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_monitoring_schedule(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def stop(self) -> None: """ Stop a MonitoringSchedule resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22338,82 +22162,74 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "MonitoringScheduleName": self.monitoring_schedule_name, + 'MonitoringScheduleName': self.monitoring_schedule_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_monitoring_schedule(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Pending", "Failed", "Scheduled", "Stopped"], + target_status: Literal['Pending', 'Failed', 'Scheduled', 'Stopped'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a MonitoringSchedule resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) - progress.add_task( - f"Waiting for MonitoringSchedule to reach [bold]{target_status} status..." - ) + progress.add_task(f"Waiting for MonitoringSchedule to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.monitoring_schedule_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="MonitoringSchedule", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="MonitoringSchedule", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="MonitoringSchedule", status=current_status - ) + raise TimeoutExceededError(resouce_type="MonitoringSchedule", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -22434,7 +22250,7 @@ def get_all( ) -> ResourceIterator["MonitoringSchedule"]: """ Get all MonitoringSchedule resources - + Parameters: endpoint_name: Name of a specific endpoint to fetch schedules for. sort_by: Whether to sort the results by the Status, CreationTime, or ScheduledTime field. The default is CreationTime. @@ -22451,12 +22267,12 @@ def get_all( monitoring_type_equals: A filter that returns only the monitoring schedules for the specified monitoring type. session: Boto3 session. region: Region name. - + Returns: Iterator for listed MonitoringSchedule resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22466,69 +22282,67 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "EndpointName": endpoint_name, - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "StatusEquals": status_equals, - "MonitoringJobDefinitionName": monitoring_job_definition_name, - "MonitoringTypeEquals": monitoring_type_equals, + 'EndpointName': endpoint_name, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'StatusEquals': status_equals, + 'MonitoringJobDefinitionName': monitoring_job_definition_name, + 'MonitoringTypeEquals': monitoring_type_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_monitoring_schedules", - summaries_key="MonitoringScheduleSummaries", - summary_name="MonitoringScheduleSummary", + list_method='list_monitoring_schedules', + summaries_key='MonitoringScheduleSummaries', + summary_name='MonitoringScheduleSummary', resource_cls=MonitoringSchedule, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class NotebookInstance(Base): """ Class representing resource NotebookInstance - + Attributes: notebook_instance_arn: The Amazon Resource Name (ARN) of the notebook instance. - notebook_instance_name: The name of the SageMaker AI notebook instance. + notebook_instance_name: The name of the SageMaker AI notebook instance. notebook_instance_status: The status of the notebook instance. failure_reason: If status is Failed, the reason it failed. - url: The URL that you use to connect to the Jupyter notebook that is running in your notebook instance. + url: The URL that you use to connect to the Jupyter notebook that is running in your notebook instance. instance_type: The type of ML compute instance running on the notebook instance. subnet_id: The ID of the VPC subnet. security_groups: The IDs of the VPC security groups. - role_arn: The Amazon Resource Name (ARN) of the IAM role associated with the instance. - kms_key_id: The Amazon Web Services KMS key ID SageMaker AI uses to encrypt data when storing it on the ML storage volume attached to the instance. - network_interface_id: The network interface IDs that SageMaker AI created at the time of creating the instance. - last_modified_time: A timestamp. Use this parameter to retrieve the time when the notebook instance was last modified. + role_arn: The Amazon Resource Name (ARN) of the IAM role associated with the instance. + kms_key_id: The Amazon Web Services KMS key ID SageMaker AI uses to encrypt data when storing it on the ML storage volume attached to the instance. + network_interface_id: The network interface IDs that SageMaker AI created at the time of creating the instance. + last_modified_time: A timestamp. Use this parameter to retrieve the time when the notebook instance was last modified. creation_time: A timestamp. Use this parameter to return the time when the notebook instance was created - notebook_instance_lifecycle_config_name: Returns the name of a notebook instance lifecycle configuration. For information about notebook instance lifestyle configurations, see Step 2.1: (Optional) Customize a Notebook Instance + notebook_instance_lifecycle_config_name: Returns the name of a notebook instance lifecycle configuration. For information about notebook instance lifestyle configurations, see Step 2.1: (Optional) Customize a Notebook Instance direct_internet_access: Describes whether SageMaker AI provides internet access to the notebook instance. If this value is set to Disabled, the notebook instance does not have internet access, and cannot connect to SageMaker AI training and endpoint services. For more information, see Notebook Instances Are Internet-Enabled by Default. volume_size_in_gb: The size, in GB, of the ML storage volume attached to the notebook instance. accelerator_types: This parameter is no longer supported. Elastic Inference (EI) is no longer available. This parameter was used to specify a list of the EI instance types associated with this notebook instance. default_code_repository: The Git repository associated with the notebook instance as its default code repository. This can be either the name of a Git repository stored as a resource in your account, or the URL of a Git repository in Amazon Web Services CodeCommit or in any other Git repository. When you open a notebook instance, it opens in the directory that contains this repository. For more information, see Associating Git Repositories with SageMaker AI Notebook Instances. additional_code_repositories: An array of up to three Git repositories associated with the notebook instance. These can be either the names of Git repositories stored as resources in your account, or the URL of Git repositories in Amazon Web Services CodeCommit or in any other Git repository. These repositories are cloned at the same level as the default repository of your notebook instance. For more information, see Associating Git Repositories with SageMaker AI Notebook Instances. - root_access: Whether root access is enabled or disabled for users of the notebook instance. Lifecycle configurations need root access to be able to set up a notebook instance. Because of this, lifecycle configurations associated with a notebook instance always run with root access even if you disable root access for users. + root_access: Whether root access is enabled or disabled for users of the notebook instance. Lifecycle configurations need root access to be able to set up a notebook instance. Because of this, lifecycle configurations associated with a notebook instance always run with root access even if you disable root access for users. platform_identifier: The platform identifier of the notebook instance runtime environment. instance_metadata_service_configuration: Information on the IMDS configuration of the notebook instance - + """ - notebook_instance_name: str notebook_instance_arn: Optional[str] = Unassigned() notebook_instance_status: Optional[str] = Unassigned() @@ -22550,44 +22364,49 @@ class NotebookInstance(Base): additional_code_repositories: Optional[List[str]] = Unassigned() root_access: Optional[str] = Unassigned() platform_identifier: Optional[str] = Unassigned() - instance_metadata_service_configuration: Optional[ - shapes.InstanceMetadataServiceConfiguration - ] = Unassigned() - + instance_metadata_service_configuration: Optional[shapes.InstanceMetadataServiceConfiguration] = Unassigned() + def get_name(self) -> str: attributes = vars(self) - resource_name = "notebook_instance_name" - resource_name_split = resource_name.split("_") + resource_name = 'notebook_instance_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object notebook_instance") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "subnet_id": {"type": "string"}, - "security_groups": {"type": "array", "items": {"type": "string"}}, - "role_arn": {"type": "string"}, - "kms_key_id": {"type": "string"}, + config_schema_for_resource = \ + { + "subnet_id": { + "type": "string" + }, + "security_groups": { + "type": "array", + "items": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "NotebookInstance", **kwargs - ), - ) - + }, + "role_arn": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "NotebookInstance", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -22608,21 +22427,19 @@ def create( additional_code_repositories: Optional[List[str]] = Unassigned(), root_access: Optional[str] = Unassigned(), platform_identifier: Optional[str] = Unassigned(), - instance_metadata_service_configuration: Optional[ - shapes.InstanceMetadataServiceConfiguration - ] = Unassigned(), + instance_metadata_service_configuration: Optional[shapes.InstanceMetadataServiceConfiguration] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> Optional["NotebookInstance"]: """ Create a NotebookInstance resource - + Parameters: notebook_instance_name: The name of the new notebook instance. instance_type: The type of ML compute instance to launch for the notebook instance. - role_arn: When you send any requests to Amazon Web Services resources from the notebook instance, SageMaker AI assumes this role to perform tasks on your behalf. You must grant this role necessary permissions so SageMaker AI can perform these tasks. The policy must allow the SageMaker AI service principal (sagemaker.amazonaws.com) permissions to assume this role. For more information, see SageMaker AI Roles. To be able to pass this role to SageMaker AI, the caller of this API must have the iam:PassRole permission. - subnet_id: The ID of the subnet in a VPC to which you would like to have a connectivity from your ML compute instance. - security_group_ids: The VPC security group IDs, in the form sg-xxxxxxxx. The security groups must be for the same VPC as specified in the subnet. + role_arn: When you send any requests to Amazon Web Services resources from the notebook instance, SageMaker AI assumes this role to perform tasks on your behalf. You must grant this role necessary permissions so SageMaker AI can perform these tasks. The policy must allow the SageMaker AI service principal (sagemaker.amazonaws.com) permissions to assume this role. For more information, see SageMaker AI Roles. To be able to pass this role to SageMaker AI, the caller of this API must have the iam:PassRole permission. + subnet_id: The ID of the subnet in a VPC to which you would like to have a connectivity from your ML compute instance. + security_group_ids: The VPC security group IDs, in the form sg-xxxxxxxx. The security groups must be for the same VPC as specified in the subnet. kms_key_id: The Amazon Resource Name (ARN) of a Amazon Web Services Key Management Service key that SageMaker AI uses to encrypt data on the storage volume attached to your notebook instance. The KMS key you provide must be enabled. For information, see Enabling and Disabling Keys in the Amazon Web Services Key Management Service Developer Guide. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. lifecycle_config_name: The name of a lifecycle configuration to associate with the notebook instance. For information about lifestyle configurations, see Step 2.1: (Optional) Customize a Notebook Instance. @@ -22631,17 +22448,17 @@ def create( accelerator_types: This parameter is no longer supported. Elastic Inference (EI) is no longer available. This parameter was used to specify a list of EI instance types to associate with this notebook instance. default_code_repository: A Git repository to associate with the notebook instance as its default code repository. This can be either the name of a Git repository stored as a resource in your account, or the URL of a Git repository in Amazon Web Services CodeCommit or in any other Git repository. When you open a notebook instance, it opens in the directory that contains this repository. For more information, see Associating Git Repositories with SageMaker AI Notebook Instances. additional_code_repositories: An array of up to three Git repositories to associate with the notebook instance. These can be either the names of Git repositories stored as resources in your account, or the URL of Git repositories in Amazon Web Services CodeCommit or in any other Git repository. These repositories are cloned at the same level as the default repository of your notebook instance. For more information, see Associating Git Repositories with SageMaker AI Notebook Instances. - root_access: Whether root access is enabled or disabled for users of the notebook instance. The default value is Enabled. Lifecycle configurations need root access to be able to set up a notebook instance. Because of this, lifecycle configurations associated with a notebook instance always run with root access even if you disable root access for users. + root_access: Whether root access is enabled or disabled for users of the notebook instance. The default value is Enabled. Lifecycle configurations need root access to be able to set up a notebook instance. Because of this, lifecycle configurations associated with a notebook instance always run with root access even if you disable root access for users. platform_identifier: The platform identifier of the notebook instance runtime environment. instance_metadata_service_configuration: Information on the IMDS configuration of the notebook instance session: Boto3 session. region: Region name. - + Returns: The NotebookInstance resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22655,48 +22472,42 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating notebook_instance resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "NotebookInstanceName": notebook_instance_name, - "InstanceType": instance_type, - "SubnetId": subnet_id, - "SecurityGroupIds": security_group_ids, - "RoleArn": role_arn, - "KmsKeyId": kms_key_id, - "Tags": tags, - "LifecycleConfigName": lifecycle_config_name, - "DirectInternetAccess": direct_internet_access, - "VolumeSizeInGB": volume_size_in_gb, - "AcceleratorTypes": accelerator_types, - "DefaultCodeRepository": default_code_repository, - "AdditionalCodeRepositories": additional_code_repositories, - "RootAccess": root_access, - "PlatformIdentifier": platform_identifier, - "InstanceMetadataServiceConfiguration": instance_metadata_service_configuration, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="NotebookInstance", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'NotebookInstanceName': notebook_instance_name, + 'InstanceType': instance_type, + 'SubnetId': subnet_id, + 'SecurityGroupIds': security_group_ids, + 'RoleArn': role_arn, + 'KmsKeyId': kms_key_id, + 'Tags': tags, + 'LifecycleConfigName': lifecycle_config_name, + 'DirectInternetAccess': direct_internet_access, + 'VolumeSizeInGB': volume_size_in_gb, + 'AcceleratorTypes': accelerator_types, + 'DefaultCodeRepository': default_code_repository, + 'AdditionalCodeRepositories': additional_code_repositories, + 'RootAccess': root_access, + 'PlatformIdentifier': platform_identifier, + 'InstanceMetadataServiceConfiguration': instance_metadata_service_configuration, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='NotebookInstance', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_notebook_instance(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - notebook_instance_name=notebook_instance_name, session=session, region=region - ) - + + return cls.get(notebook_instance_name=notebook_instance_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -22707,17 +22518,17 @@ def get( ) -> Optional["NotebookInstance"]: """ Get a NotebookInstance resource - + Parameters: notebook_instance_name: The name of the notebook instance that you want information about. session: Boto3 session. region: Region name. - + Returns: The NotebookInstance resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22727,38 +22538,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "NotebookInstanceName": notebook_instance_name, + 'NotebookInstanceName': notebook_instance_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_notebook_instance(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeNotebookInstanceOutput") + transformed_response = transform(response, 'DescribeNotebookInstanceOutput') notebook_instance = cls(**transformed_response) return notebook_instance - + @Base.add_validate_call def refresh( self, - ) -> Optional["NotebookInstance"]: + + ) -> Optional["NotebookInstance"]: """ Refresh a NotebookInstance resource - + Returns: The NotebookInstance resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22768,21 +22578,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "NotebookInstanceName": self.notebook_instance_name, + 'NotebookInstanceName': self.notebook_instance_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_notebook_instance(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeNotebookInstanceOutput", self) + transform(response, 'DescribeNotebookInstanceOutput', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -22799,25 +22609,23 @@ def update( disassociate_default_code_repository: Optional[bool] = Unassigned(), disassociate_additional_code_repositories: Optional[bool] = Unassigned(), root_access: Optional[str] = Unassigned(), - instance_metadata_service_configuration: Optional[ - shapes.InstanceMetadataServiceConfiguration - ] = Unassigned(), + instance_metadata_service_configuration: Optional[shapes.InstanceMetadataServiceConfiguration] = Unassigned(), ) -> Optional["NotebookInstance"]: """ Update a NotebookInstance resource - + Parameters: lifecycle_config_name: The name of a lifecycle configuration to associate with the notebook instance. For information about lifestyle configurations, see Step 2.1: (Optional) Customize a Notebook Instance. disassociate_lifecycle_config: Set to true to remove the notebook instance lifecycle configuration currently associated with the notebook instance. This operation is idempotent. If you specify a lifecycle configuration that is not associated with the notebook instance when you call this method, it does not throw an error. disassociate_accelerator_types: This parameter is no longer supported. Elastic Inference (EI) is no longer available. This parameter was used to specify a list of the EI instance types to remove from this notebook instance. disassociate_default_code_repository: The name or URL of the default Git repository to remove from this notebook instance. This operation is idempotent. If you specify a Git repository that is not associated with the notebook instance when you call this method, it does not throw an error. disassociate_additional_code_repositories: A list of names or URLs of the default Git repositories to remove from this notebook instance. This operation is idempotent. If you specify a Git repository that is not associated with the notebook instance when you call this method, it does not throw an error. - + Returns: The NotebookInstance resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22828,47 +22636,48 @@ def update( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + logger.info("Updating notebook_instance resource.") client = Base.get_sagemaker_client() - - operation_input_args = { - "NotebookInstanceName": self.notebook_instance_name, - "InstanceType": instance_type, - "RoleArn": role_arn, - "LifecycleConfigName": lifecycle_config_name, - "DisassociateLifecycleConfig": disassociate_lifecycle_config, - "VolumeSizeInGB": volume_size_in_gb, - "DefaultCodeRepository": default_code_repository, - "AdditionalCodeRepositories": additional_code_repositories, - "AcceleratorTypes": accelerator_types, - "DisassociateAcceleratorTypes": disassociate_accelerator_types, - "DisassociateDefaultCodeRepository": disassociate_default_code_repository, - "DisassociateAdditionalCodeRepositories": disassociate_additional_code_repositories, - "RootAccess": root_access, - "InstanceMetadataServiceConfiguration": instance_metadata_service_configuration, + + operation_input_args = { + 'NotebookInstanceName': self.notebook_instance_name, + 'InstanceType': instance_type, + 'RoleArn': role_arn, + 'LifecycleConfigName': lifecycle_config_name, + 'DisassociateLifecycleConfig': disassociate_lifecycle_config, + 'VolumeSizeInGB': volume_size_in_gb, + 'DefaultCodeRepository': default_code_repository, + 'AdditionalCodeRepositories': additional_code_repositories, + 'AcceleratorTypes': accelerator_types, + 'DisassociateAcceleratorTypes': disassociate_accelerator_types, + 'DisassociateDefaultCodeRepository': disassociate_default_code_repository, + 'DisassociateAdditionalCodeRepositories': disassociate_additional_code_repositories, + 'RootAccess': root_access, + 'InstanceMetadataServiceConfiguration': instance_metadata_service_configuration, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_notebook_instance(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a NotebookInstance resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22878,27 +22687,27 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "NotebookInstanceName": self.notebook_instance_name, + 'NotebookInstanceName': self.notebook_instance_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_notebook_instance(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def stop(self) -> None: """ Stop a NotebookInstance resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -22908,82 +22717,74 @@ def stop(self) -> None: error_code = e.response['Error']['Code'] ``` """ - + client = SageMakerClient().client - + operation_input_args = { - "NotebookInstanceName": self.notebook_instance_name, + 'NotebookInstanceName': self.notebook_instance_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_notebook_instance(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Pending", "InService", "Stopping", "Stopped", "Failed", "Deleting", "Updating" - ], + target_status: Literal['Pending', 'InService', 'Stopping', 'Stopped', 'Failed', 'Deleting', 'Updating'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a NotebookInstance resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for NotebookInstance to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.notebook_instance_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="NotebookInstance", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="NotebookInstance", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="NotebookInstance", status=current_status - ) + raise TimeoutExceededError(resouce_type="NotebookInstance", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -22992,13 +22793,13 @@ def wait_for_delete( ) -> None: """ Wait for a NotebookInstance resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23012,41 +22813,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for NotebookInstance to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.notebook_instance_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="NotebookInstance", status=current_status - ) + raise TimeoutExceededError(resouce_type="NotebookInstance", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -23067,14 +22861,14 @@ def get_all( ) -> ResourceIterator["NotebookInstance"]: """ Get all NotebookInstance resources - + Parameters: - next_token: If the previous call to the ListNotebookInstances is truncated, the response includes a NextToken. You can use this token in your subsequent ListNotebookInstances request to fetch the next set of notebook instances. You might specify a filter or a sort order in your request. When response is truncated, you must use the same values for the filer and sort order in the next request. + next_token: If the previous call to the ListNotebookInstances is truncated, the response includes a NextToken. You can use this token in your subsequent ListNotebookInstances request to fetch the next set of notebook instances. You might specify a filter or a sort order in your request. When response is truncated, you must use the same values for the filer and sort order in the next request. max_results: The maximum number of notebook instances to return. sort_by: The field to sort results by. The default is Name. - sort_order: The sort order for results. + sort_order: The sort order for results. name_contains: A string in the notebook instances' name. This filter returns only notebook instances whose name contains the specified string. - creation_time_before: A filter that returns only notebook instances that were created before the specified time (timestamp). + creation_time_before: A filter that returns only notebook instances that were created before the specified time (timestamp). creation_time_after: A filter that returns only notebook instances that were created after the specified time (timestamp). last_modified_time_before: A filter that returns only notebook instances that were modified before the specified time (timestamp). last_modified_time_after: A filter that returns only notebook instances that were modified after the specified time (timestamp). @@ -23084,12 +22878,12 @@ def get_all( additional_code_repository_equals: A filter that returns only notebook instances with associated with the specified git repository. session: Boto3 session. region: Region name. - + Returns: Iterator for listed NotebookInstance resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23099,43 +22893,42 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "StatusEquals": status_equals, - "NotebookInstanceLifecycleConfigNameContains": notebook_instance_lifecycle_config_name_contains, - "DefaultCodeRepositoryContains": default_code_repository_contains, - "AdditionalCodeRepositoryEquals": additional_code_repository_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'StatusEquals': status_equals, + 'NotebookInstanceLifecycleConfigNameContains': notebook_instance_lifecycle_config_name_contains, + 'DefaultCodeRepositoryContains': default_code_repository_contains, + 'AdditionalCodeRepositoryEquals': additional_code_repository_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_notebook_instances", - summaries_key="NotebookInstances", - summary_name="NotebookInstanceSummary", + list_method='list_notebook_instances', + summaries_key='NotebookInstances', + summary_name='NotebookInstanceSummary', resource_cls=NotebookInstance, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class NotebookInstanceLifecycleConfig(Base): """ Class representing resource NotebookInstanceLifecycleConfig - + Attributes: notebook_instance_lifecycle_config_arn: The Amazon Resource Name (ARN) of the lifecycle configuration. notebook_instance_lifecycle_config_name: The name of the lifecycle configuration. @@ -23143,32 +22936,31 @@ class NotebookInstanceLifecycleConfig(Base): on_start: The shell script that runs every time you start a notebook instance, including when you create the notebook instance. last_modified_time: A timestamp that tells when the lifecycle configuration was last modified. creation_time: A timestamp that tells when the lifecycle configuration was created. - + """ - notebook_instance_lifecycle_config_name: str notebook_instance_lifecycle_config_arn: Optional[str] = Unassigned() on_create: Optional[List[shapes.NotebookInstanceLifecycleHook]] = Unassigned() on_start: Optional[List[shapes.NotebookInstanceLifecycleHook]] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "notebook_instance_lifecycle_config_name" - resource_name_split = resource_name.split("_") + resource_name = 'notebook_instance_lifecycle_config_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object notebook_instance_lifecycle_config") return None - + @classmethod @Base.add_validate_call def create( @@ -23182,7 +22974,7 @@ def create( ) -> Optional["NotebookInstanceLifecycleConfig"]: """ Create a NotebookInstanceLifecycleConfig resource - + Parameters: notebook_instance_lifecycle_config_name: The name of the lifecycle configuration. on_create: A shell script that runs only once, when you create a notebook instance. The shell script must be a base64-encoded string. @@ -23190,12 +22982,12 @@ def create( tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. session: Boto3 session. region: Region name. - + Returns: The NotebookInstanceLifecycleConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23209,39 +23001,30 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating notebook_instance_lifecycle_config resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "NotebookInstanceLifecycleConfigName": notebook_instance_lifecycle_config_name, - "OnCreate": on_create, - "OnStart": on_start, - "Tags": tags, + 'NotebookInstanceLifecycleConfigName': notebook_instance_lifecycle_config_name, + 'OnCreate': on_create, + 'OnStart': on_start, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="NotebookInstanceLifecycleConfig", - operation_input_args=operation_input_args, - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='NotebookInstanceLifecycleConfig', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_notebook_instance_lifecycle_config(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - notebook_instance_lifecycle_config_name=notebook_instance_lifecycle_config_name, - session=session, - region=region, - ) - + + return cls.get(notebook_instance_lifecycle_config_name=notebook_instance_lifecycle_config_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -23252,17 +23035,17 @@ def get( ) -> Optional["NotebookInstanceLifecycleConfig"]: """ Get a NotebookInstanceLifecycleConfig resource - + Parameters: notebook_instance_lifecycle_config_name: The name of the lifecycle configuration to describe. session: Boto3 session. region: Region name. - + Returns: The NotebookInstanceLifecycleConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23272,38 +23055,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "NotebookInstanceLifecycleConfigName": notebook_instance_lifecycle_config_name, + 'NotebookInstanceLifecycleConfigName': notebook_instance_lifecycle_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_notebook_instance_lifecycle_config(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeNotebookInstanceLifecycleConfigOutput") + transformed_response = transform(response, 'DescribeNotebookInstanceLifecycleConfigOutput') notebook_instance_lifecycle_config = cls(**transformed_response) return notebook_instance_lifecycle_config - + @Base.add_validate_call def refresh( self, - ) -> Optional["NotebookInstanceLifecycleConfig"]: + + ) -> Optional["NotebookInstanceLifecycleConfig"]: """ Refresh a NotebookInstanceLifecycleConfig resource - + Returns: The NotebookInstanceLifecycleConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23313,21 +23095,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "NotebookInstanceLifecycleConfigName": self.notebook_instance_lifecycle_config_name, + 'NotebookInstanceLifecycleConfigName': self.notebook_instance_lifecycle_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_notebook_instance_lifecycle_config(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeNotebookInstanceLifecycleConfigOutput", self) + transform(response, 'DescribeNotebookInstanceLifecycleConfigOutput', self) return self - + @Base.add_validate_call def update( self, @@ -23336,12 +23118,12 @@ def update( ) -> Optional["NotebookInstanceLifecycleConfig"]: """ Update a NotebookInstanceLifecycleConfig resource - + Returns: The NotebookInstanceLifecycleConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23352,36 +23134,37 @@ def update( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + logger.info("Updating notebook_instance_lifecycle_config resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "NotebookInstanceLifecycleConfigName": self.notebook_instance_lifecycle_config_name, - "OnCreate": on_create, - "OnStart": on_start, + 'NotebookInstanceLifecycleConfigName': self.notebook_instance_lifecycle_config_name, + 'OnCreate': on_create, + 'OnStart': on_start, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_notebook_instance_lifecycle_config(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a NotebookInstanceLifecycleConfig resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23391,20 +23174,20 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "NotebookInstanceLifecycleConfigName": self.notebook_instance_lifecycle_config_name, + 'NotebookInstanceLifecycleConfigName': self.notebook_instance_lifecycle_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_notebook_instance_lifecycle_config(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -23421,7 +23204,7 @@ def get_all( ) -> ResourceIterator["NotebookInstanceLifecycleConfig"]: """ Get all NotebookInstanceLifecycleConfig resources - + Parameters: next_token: If the result of a ListNotebookInstanceLifecycleConfigs request was truncated, the response includes a NextToken. To get the next set of lifecycle configurations, use the token in the next request. max_results: The maximum number of lifecycle configurations to return in the response. @@ -23434,12 +23217,12 @@ def get_all( last_modified_time_after: A filter that returns only lifecycle configurations that were modified after the specified time (timestamp). session: Boto3 session. region: Region name. - + Returns: Iterator for listed NotebookInstanceLifecycleConfig resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23449,39 +23232,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "LastModifiedTimeAfter": last_modified_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_notebook_instance_lifecycle_configs", - summaries_key="NotebookInstanceLifecycleConfigs", - summary_name="NotebookInstanceLifecycleConfigSummary", + list_method='list_notebook_instance_lifecycle_configs', + summaries_key='NotebookInstanceLifecycleConfigs', + summary_name='NotebookInstanceLifecycleConfigSummary', resource_cls=NotebookInstanceLifecycleConfig, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class OptimizationJob(Base): """ Class representing resource OptimizationJob - + Attributes: optimization_job_arn: The Amazon Resource Name (ARN) of the optimization job. optimization_job_status: The current status of the optimization job. @@ -23493,16 +23275,15 @@ class OptimizationJob(Base): optimization_configs: Settings for each of the optimization techniques that the job applies. output_config: Details for where to store the optimized model that you create with the optimization job. role_arn: The ARN of the IAM role that you assigned to the optimization job. - stopping_condition: + stopping_condition: optimization_start_time: The time when the optimization job started. optimization_end_time: The time when the optimization job finished processing. failure_reason: If the optimization job status is FAILED, the reason for the failure. optimization_environment: The environment variables to set in the model container. optimization_output: Output values produced by an optimization job. vpc_config: A VPC in Amazon VPC that your optimized model has access to. - + """ - optimization_job_name: str optimization_job_arn: Optional[str] = Unassigned() optimization_job_status: Optional[str] = Unassigned() @@ -23520,47 +23301,65 @@ class OptimizationJob(Base): role_arn: Optional[str] = Unassigned() stopping_condition: Optional[shapes.StoppingCondition] = Unassigned() vpc_config: Optional[shapes.OptimizationVpcConfig] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "optimization_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'optimization_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object optimization_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "model_source": {"s3": {"s3_uri": {"type": "string"}}}, - "output_config": { - "s3_output_location": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "role_arn": {"type": "string"}, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, + config_schema_for_resource = \ + { + "model_source": { + "s3": { + "s3_uri": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "OptimizationJob", **kwargs - ), - ) - + }, + "output_config": { + "s3_output_location": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + }, + "role_arn": { + "type": "string" + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "OptimizationJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -23581,26 +23380,26 @@ def create( ) -> Optional["OptimizationJob"]: """ Create a OptimizationJob resource - + Parameters: optimization_job_name: A custom name for the new optimization job. - role_arn: The Amazon Resource Name (ARN) of an IAM role that enables Amazon SageMaker AI to perform tasks on your behalf. During model optimization, Amazon SageMaker AI needs your permission to: Read input data from an S3 bucket Write model artifacts to an S3 bucket Write logs to Amazon CloudWatch Logs Publish metrics to Amazon CloudWatch You grant permissions for all of these tasks to an IAM role. To pass this role to Amazon SageMaker AI, the caller of this API must have the iam:PassRole permission. For more information, see Amazon SageMaker AI Roles. + role_arn: The Amazon Resource Name (ARN) of an IAM role that enables Amazon SageMaker AI to perform tasks on your behalf. During model optimization, Amazon SageMaker AI needs your permission to: Read input data from an S3 bucket Write model artifacts to an S3 bucket Write logs to Amazon CloudWatch Logs Publish metrics to Amazon CloudWatch You grant permissions for all of these tasks to an IAM role. To pass this role to Amazon SageMaker AI, the caller of this API must have the iam:PassRole permission. For more information, see Amazon SageMaker AI Roles. model_source: The location of the source model to optimize with an optimization job. deployment_instance_type: The type of instance that hosts the optimized model that you create with the optimization job. optimization_configs: Settings for each of the optimization techniques that the job applies. output_config: Details for where to store the optimized model that you create with the optimization job. - stopping_condition: + stopping_condition: optimization_environment: The environment variables to set in the model container. tags: A list of key-value pairs associated with the optimization job. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference Guide. vpc_config: A VPC in Amazon VPC that your optimized model has access to. session: Boto3 session. region: Region name. - + Returns: The OptimizationJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23615,40 +23414,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating optimization_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "OptimizationJobName": optimization_job_name, - "RoleArn": role_arn, - "ModelSource": model_source, - "DeploymentInstanceType": deployment_instance_type, - "OptimizationEnvironment": optimization_environment, - "OptimizationConfigs": optimization_configs, - "OutputConfig": output_config, - "StoppingCondition": stopping_condition, - "Tags": tags, - "VpcConfig": vpc_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="OptimizationJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'OptimizationJobName': optimization_job_name, + 'RoleArn': role_arn, + 'ModelSource': model_source, + 'DeploymentInstanceType': deployment_instance_type, + 'OptimizationEnvironment': optimization_environment, + 'OptimizationConfigs': optimization_configs, + 'OutputConfig': output_config, + 'StoppingCondition': stopping_condition, + 'Tags': tags, + 'VpcConfig': vpc_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='OptimizationJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_optimization_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(optimization_job_name=optimization_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -23659,17 +23454,17 @@ def get( ) -> Optional["OptimizationJob"]: """ Get a OptimizationJob resource - + Parameters: optimization_job_name: The name that you assigned to the optimization job. session: Boto3 session. region: Region name. - + Returns: The OptimizationJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23680,38 +23475,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "OptimizationJobName": optimization_job_name, + 'OptimizationJobName': optimization_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_optimization_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeOptimizationJobResponse") + transformed_response = transform(response, 'DescribeOptimizationJobResponse') optimization_job = cls(**transformed_response) return optimization_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["OptimizationJob"]: + + ) -> Optional["OptimizationJob"]: """ Refresh a OptimizationJob resource - + Returns: The OptimizationJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23722,30 +23516,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "OptimizationJobName": self.optimization_job_name, + 'OptimizationJobName': self.optimization_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_optimization_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeOptimizationJobResponse", self) + transform(response, 'DescribeOptimizationJobResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a OptimizationJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23756,27 +23551,27 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "OptimizationJobName": self.optimization_job_name, + 'OptimizationJobName': self.optimization_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_optimization_job(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def stop(self) -> None: """ Stop a OptimizationJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23787,81 +23582,77 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "OptimizationJobName": self.optimization_job_name, + 'OptimizationJobName': self.optimization_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_optimization_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, poll: int = 5, timeout: Optional[int] = None, + ) -> None: """ Wait for a OptimizationJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["COMPLETED", "FAILED", "STOPPED"] + terminal_states = ['COMPLETED', 'FAILED', 'STOPPED'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for OptimizationJob...") status = Status("Current status:") - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.optimization_job_status status.update(f"Current status: [bold]{current_status}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="OptimizationJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="OptimizationJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="OptimizationJob", status=current_status - ) + raise TimeoutExceededError(resouce_type="OptimizationJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -23880,7 +23671,7 @@ def get_all( ) -> ResourceIterator["OptimizationJob"]: """ Get all OptimizationJob resources - + Parameters: next_token: A token that you use to get the next set of results following a truncated response. If the response to the previous request was truncated, that response provides the value for this token. max_results: The maximum number of optimization jobs to return in the response. The default is 50. @@ -23891,16 +23682,16 @@ def get_all( optimization_contains: Filters the results to only those optimization jobs that apply the specified optimization techniques. You can specify either Quantization or Compilation. name_contains: Filters the results to only those optimization jobs with a name that contains the specified string. status_equals: Filters the results to only those optimization jobs with the specified status. - sort_by: The field by which to sort the optimization jobs in the response. The default is CreationTime - sort_order: The sort order for results. The default is Ascending + sort_by: The field by which to sort the optimization jobs in the response. The default is CreationTime + sort_order: The sort order for results. The default is Ascending session: Boto3 session. region: Region name. - + Returns: Iterator for listed OptimizationJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -23910,41 +23701,40 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "OptimizationContains": optimization_contains, - "NameContains": name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'OptimizationContains': optimization_contains, + 'NameContains': name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_optimization_jobs", - summaries_key="OptimizationJobSummaries", - summary_name="OptimizationJobSummary", + list_method='list_optimization_jobs', + summaries_key='OptimizationJobSummaries', + summary_name='OptimizationJobSummary', resource_cls=OptimizationJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class PartnerApp(Base): """ Class representing resource PartnerApp - + Attributes: arn: The ARN of the SageMaker Partner AI App that was described. name: The name of the SageMaker Partner AI App. @@ -23962,9 +23752,8 @@ class PartnerApp(Base): auth_type: The authorization type that users use to access the SageMaker Partner AI App. enable_iam_session_based_identity: When set to TRUE, the SageMaker Partner AI App sets the Amazon Web Services IAM session name or the authenticated IAM user as the identity of the SageMaker Partner AI App user. error: This is an error field object that contains the error code and the reason for an operation failure. - + """ - arn: str name: Optional[str] = Unassigned() type: Optional[str] = Unassigned() @@ -23981,39 +23770,39 @@ class PartnerApp(Base): auth_type: Optional[str] = Unassigned() enable_iam_session_based_identity: Optional[bool] = Unassigned() error: Optional[shapes.ErrorInfo] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "partner_app_name" - resource_name_split = resource_name.split("_") + resource_name = 'partner_app_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object partner_app") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "execution_role_arn": {"type": "string"}, - "kms_key_id": {"type": "string"}, - } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "PartnerApp", **kwargs - ), - ) - + config_schema_for_resource = \ + { + "execution_role_arn": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "PartnerApp", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -24035,7 +23824,7 @@ def create( ) -> Optional["PartnerApp"]: """ Create a PartnerApp resource - + Parameters: name: The name to give the SageMaker Partner AI App. type: The type of SageMaker Partner AI App to create. Must be one of the following: lakera-guard, comet, deepchecks-llm-evaluation, or fiddler. @@ -24050,12 +23839,12 @@ def create( tags: Each tag consists of a key and an optional value. Tag keys must be unique per resource. session: Boto3 session. region: Region name. - + Returns: The PartnerApp resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24070,41 +23859,37 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating partner_app resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "Name": name, - "Type": type, - "ExecutionRoleArn": execution_role_arn, - "KmsKeyId": kms_key_id, - "MaintenanceConfig": maintenance_config, - "Tier": tier, - "ApplicationConfig": application_config, - "AuthType": auth_type, - "EnableIamSessionBasedIdentity": enable_iam_session_based_identity, - "ClientToken": client_token, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="PartnerApp", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'Name': name, + 'Type': type, + 'ExecutionRoleArn': execution_role_arn, + 'KmsKeyId': kms_key_id, + 'MaintenanceConfig': maintenance_config, + 'Tier': tier, + 'ApplicationConfig': application_config, + 'AuthType': auth_type, + 'EnableIamSessionBasedIdentity': enable_iam_session_based_identity, + 'ClientToken': client_token, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='PartnerApp', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_partner_app(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get(arn=response["Arn"], session=session, region=region) - + + return cls.get(arn=response['Arn'], session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -24115,17 +23900,17 @@ def get( ) -> Optional["PartnerApp"]: """ Get a PartnerApp resource - + Parameters: arn: The ARN of the SageMaker Partner AI App to describe. session: Boto3 session. region: Region name. - + Returns: The PartnerApp resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24136,38 +23921,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "Arn": arn, + 'Arn': arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_partner_app(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribePartnerAppResponse") + transformed_response = transform(response, 'DescribePartnerAppResponse') partner_app = cls(**transformed_response) return partner_app - + @Base.add_validate_call def refresh( self, - ) -> Optional["PartnerApp"]: + + ) -> Optional["PartnerApp"]: """ Refresh a PartnerApp resource - + Returns: The PartnerApp resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24178,21 +23962,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "Arn": self.arn, + 'Arn': self.arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_partner_app(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribePartnerAppResponse", self) + transform(response, 'DescribePartnerAppResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -24206,16 +23990,16 @@ def update( ) -> Optional["PartnerApp"]: """ Update a PartnerApp resource - + Parameters: client_token: A unique token that guarantees that the call to this API is idempotent. tags: Each tag consists of a key and an optional value. Tag keys must be unique per resource. - + Returns: The PartnerApp resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24227,41 +24011,41 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating partner_app resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "Arn": self.arn, - "MaintenanceConfig": maintenance_config, - "Tier": tier, - "ApplicationConfig": application_config, - "EnableIamSessionBasedIdentity": enable_iam_session_based_identity, - "ClientToken": client_token, - "Tags": tags, + 'Arn': self.arn, + 'MaintenanceConfig': maintenance_config, + 'Tier': tier, + 'ApplicationConfig': application_config, + 'EnableIamSessionBasedIdentity': enable_iam_session_based_identity, + 'ClientToken': client_token, + 'Tags': tags, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_partner_app(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, client_token: Optional[str] = Unassigned(), - ) -> None: + ) -> None: """ Delete a PartnerApp resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24273,79 +24057,75 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "Arn": self.arn, - "ClientToken": client_token, + 'Arn': self.arn, + 'ClientToken': client_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_partner_app(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Creating", "Updating", "Deleting", "Available", "Failed", "UpdateFailed", "Deleted" - ], + target_status: Literal['Creating', 'Updating', 'Deleting', 'Available', 'Failed', 'UpdateFailed', 'Deleted'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a PartnerApp resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for PartnerApp to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="PartnerApp", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="PartnerApp", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="PartnerApp", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -24354,13 +24134,13 @@ def wait_for_delete( ) -> None: """ Wait for a PartnerApp resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24374,43 +24154,38 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for PartnerApp to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + + if current_status.lower() == "deleted": print("Resource was deleted.") return - + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="PartnerApp", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -24420,61 +24195,59 @@ def get_all( ) -> ResourceIterator["PartnerApp"]: """ Get all PartnerApp resources. - + Parameters: session: Boto3 session. region: Region name. - + Returns: Iterator for listed PartnerApp resources. - + """ - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + + return ResourceIterator( client=client, - list_method="list_partner_apps", - summaries_key="Summaries", - summary_name="PartnerAppSummary", - resource_cls=PartnerApp, + list_method='list_partner_apps', + summaries_key='Summaries', + summary_name='PartnerAppSummary', + resource_cls=PartnerApp ) class PartnerAppPresignedUrl(Base): """ Class representing resource PartnerAppPresignedUrl - + Attributes: arn: The ARN of the SageMaker Partner AI App to create the presigned URL for. expires_in_seconds: The time that will pass before the presigned URL expires. session_expiration_duration_in_seconds: Indicates how long the Amazon SageMaker Partner AI App session can be accessed for after logging in. url: The presigned URL that you can use to access the SageMaker Partner AI App. - + """ - arn: str expires_in_seconds: Optional[int] = Unassigned() session_expiration_duration_in_seconds: Optional[int] = Unassigned() url: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "partner_app_presigned_url_name" - resource_name_split = resource_name.split("_") + resource_name = 'partner_app_presigned_url_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object partner_app_presigned_url") return None - + @classmethod @Base.add_validate_call def create( @@ -24485,19 +24258,19 @@ def create( ) -> Optional["PartnerAppPresignedUrl"]: """ Create a PartnerAppPresignedUrl resource - + Parameters: arn: The ARN of the SageMaker Partner AI App to create the presigned URL for. expires_in_seconds: The time that will pass before the presigned URL expires. session_expiration_duration_in_seconds: Indicates how long the Amazon SageMaker Partner AI App session can be accessed for after logging in. session: Boto3 session. region: Region name. - + Returns: The PartnerAppPresignedUrl resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24511,32 +24284,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + + operation_input_args = { - "Arn": arn, - "ExpiresInSeconds": expires_in_seconds, - "SessionExpirationDurationInSeconds": session_expiration_duration_in_seconds, + 'Arn': arn, + 'ExpiresInSeconds': expires_in_seconds, + 'SessionExpirationDurationInSeconds': session_expiration_duration_in_seconds, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling create_partner_app_presigned_url API") response = client.create_partner_app_presigned_url(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "CreatePartnerAppPresignedUrlResponse") + + transformed_response = transform(response, 'CreatePartnerAppPresignedUrlResponse') return cls(**operation_input_args, **transformed_response) class Pipeline(Base): """ Class representing resource Pipeline - + Attributes: pipeline_arn: The Amazon Resource Name (ARN) of the pipeline. pipeline_name: The name of the pipeline. @@ -24548,14 +24320,13 @@ class Pipeline(Base): creation_time: The time when the pipeline was created. last_modified_time: The time when the pipeline was last modified. last_run_time: The time when the pipeline was last run. - created_by: - last_modified_by: + created_by: + last_modified_by: parallelism_configuration: Lists the parallelism configuration applied to the pipeline. pipeline_version_display_name: The display name of the pipeline version. pipeline_version_description: The description of the pipeline version. - + """ - pipeline_name: str pipeline_arn: Optional[str] = Unassigned() pipeline_display_name: Optional[str] = Unassigned() @@ -24571,36 +24342,36 @@ class Pipeline(Base): parallelism_configuration: Optional[shapes.ParallelismConfiguration] = Unassigned() pipeline_version_display_name: Optional[str] = Unassigned() pipeline_version_description: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "pipeline_name" - resource_name_split = resource_name.split("_") + resource_name = 'pipeline_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object pipeline") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = {"role_arn": {"type": "string"}} - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Pipeline", **kwargs - ), - ) - + config_schema_for_resource = \ + { + "role_arn": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Pipeline", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -24611,9 +24382,7 @@ def create( role_arn: str, pipeline_display_name: Optional[str] = Unassigned(), pipeline_definition: Optional[str] = Unassigned(), - pipeline_definition_s3_location: Optional[ - shapes.PipelineDefinitionS3Location - ] = Unassigned(), + pipeline_definition_s3_location: Optional[shapes.PipelineDefinitionS3Location] = Unassigned(), pipeline_description: Optional[str] = Unassigned(), tags: Optional[List[shapes.Tag]] = Unassigned(), parallelism_configuration: Optional[shapes.ParallelismConfiguration] = Unassigned(), @@ -24622,7 +24391,7 @@ def create( ) -> Optional["Pipeline"]: """ Create a Pipeline resource - + Parameters: pipeline_name: The name of the pipeline. client_request_token: A unique, case-sensitive identifier that you provide to ensure the idempotency of the operation. An idempotent operation completes no more than one time. @@ -24635,12 +24404,12 @@ def create( parallelism_configuration: This is the configuration that controls the parallelism of the pipeline. If specified, it applies to all runs of this pipeline by default. session: Boto3 session. region: Region name. - + Returns: The Pipeline resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24656,39 +24425,35 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating pipeline resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "PipelineName": pipeline_name, - "PipelineDisplayName": pipeline_display_name, - "PipelineDefinition": pipeline_definition, - "PipelineDefinitionS3Location": pipeline_definition_s3_location, - "PipelineDescription": pipeline_description, - "ClientRequestToken": client_request_token, - "RoleArn": role_arn, - "Tags": tags, - "ParallelismConfiguration": parallelism_configuration, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Pipeline", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'PipelineName': pipeline_name, + 'PipelineDisplayName': pipeline_display_name, + 'PipelineDefinition': pipeline_definition, + 'PipelineDefinitionS3Location': pipeline_definition_s3_location, + 'PipelineDescription': pipeline_description, + 'ClientRequestToken': client_request_token, + 'RoleArn': role_arn, + 'Tags': tags, + 'ParallelismConfiguration': parallelism_configuration, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Pipeline', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_pipeline(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(pipeline_name=pipeline_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -24700,18 +24465,18 @@ def get( ) -> Optional["Pipeline"]: """ Get a Pipeline resource - + Parameters: pipeline_name: The name or Amazon Resource Name (ARN) of the pipeline to describe. pipeline_version_id: The ID of the pipeline version to describe. session: Boto3 session. region: Region name. - + Returns: The Pipeline resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24722,40 +24487,38 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "PipelineName": pipeline_name, - "PipelineVersionId": pipeline_version_id, + 'PipelineName': pipeline_name, + 'PipelineVersionId': pipeline_version_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_pipeline(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribePipelineResponse") + transformed_response = transform(response, 'DescribePipelineResponse') pipeline = cls(**transformed_response) return pipeline - + @Base.add_validate_call def refresh( self, - pipeline_version_id: Optional[int] = Unassigned(), - ) -> Optional["Pipeline"]: + pipeline_version_id: Optional[int] = Unassigned(), + ) -> Optional["Pipeline"]: """ Refresh a Pipeline resource - + Returns: The Pipeline resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24766,46 +24529,44 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "PipelineName": self.pipeline_name, - "PipelineVersionId": pipeline_version_id, + 'PipelineName': self.pipeline_name, + 'PipelineVersionId': pipeline_version_id, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_pipeline(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribePipelineResponse", self) + transform(response, 'DescribePipelineResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( self, pipeline_display_name: Optional[str] = Unassigned(), pipeline_definition: Optional[str] = Unassigned(), - pipeline_definition_s3_location: Optional[ - shapes.PipelineDefinitionS3Location - ] = Unassigned(), + pipeline_definition_s3_location: Optional[shapes.PipelineDefinitionS3Location] = Unassigned(), pipeline_description: Optional[str] = Unassigned(), role_arn: Optional[str] = Unassigned(), parallelism_configuration: Optional[shapes.ParallelismConfiguration] = Unassigned(), ) -> Optional["Pipeline"]: """ Update a Pipeline resource - + Parameters: pipeline_definition_s3_location: The location of the pipeline definition stored in Amazon S3. If specified, SageMaker will retrieve the pipeline definition from this location. - + Returns: The Pipeline resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24817,41 +24578,41 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating pipeline resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "PipelineName": self.pipeline_name, - "PipelineDisplayName": pipeline_display_name, - "PipelineDefinition": pipeline_definition, - "PipelineDefinitionS3Location": pipeline_definition_s3_location, - "PipelineDescription": pipeline_description, - "RoleArn": role_arn, - "ParallelismConfiguration": parallelism_configuration, + 'PipelineName': self.pipeline_name, + 'PipelineDisplayName': pipeline_display_name, + 'PipelineDefinition': pipeline_definition, + 'PipelineDefinitionS3Location': pipeline_definition_s3_location, + 'PipelineDescription': pipeline_description, + 'RoleArn': role_arn, + 'ParallelismConfiguration': parallelism_configuration, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_pipeline(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, client_request_token: str, - ) -> None: + ) -> None: """ Delete a Pipeline resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24863,72 +24624,72 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "PipelineName": self.pipeline_name, - "ClientRequestToken": client_request_token, + 'PipelineName': self.pipeline_name, + 'ClientRequestToken': client_request_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_pipeline(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Active", "Deleting"], + target_status: Literal['Active', 'Deleting'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Pipeline resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Pipeline to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.pipeline_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Pipeline", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -24937,13 +24698,13 @@ def wait_for_delete( ) -> None: """ Wait for a Pipeline resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -24957,39 +24718,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Pipeline to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.pipeline_status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Pipeline", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -25004,7 +24760,7 @@ def get_all( ) -> ResourceIterator["Pipeline"]: """ Get all Pipeline resources - + Parameters: pipeline_name_prefix: The prefix of the pipeline name. created_after: A filter that returns the pipelines that were created after a specified time. @@ -25015,12 +24771,12 @@ def get_all( max_results: The maximum number of pipelines to return in the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Pipeline resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25030,55 +24786,53 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "PipelineNamePrefix": pipeline_name_prefix, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'PipelineNamePrefix': pipeline_name_prefix, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_pipelines", - summaries_key="PipelineSummaries", - summary_name="PipelineSummary", + list_method='list_pipelines', + summaries_key='PipelineSummaries', + summary_name='PipelineSummary', resource_cls=Pipeline, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class PipelineExecution(Base): """ Class representing resource PipelineExecution - + Attributes: pipeline_arn: The Amazon Resource Name (ARN) of the pipeline. pipeline_execution_arn: The Amazon Resource Name (ARN) of the pipeline execution. pipeline_execution_display_name: The display name of the pipeline execution. pipeline_execution_status: The status of the pipeline execution. pipeline_execution_description: The description of the pipeline execution. - pipeline_experiment_config: + pipeline_experiment_config: failure_reason: If the execution failed, a message describing why. creation_time: The time when the pipeline execution was created. last_modified_time: The time when the pipeline execution was modified last. - created_by: - last_modified_by: + created_by: + last_modified_by: parallelism_configuration: The parallelism configuration applied to the pipeline. selective_execution_config: The selective execution configuration applied to the pipeline run. pipeline_version_id: The ID of the pipeline version. - + """ - pipeline_execution_arn: str pipeline_arn: Optional[str] = Unassigned() pipeline_execution_display_name: Optional[str] = Unassigned() @@ -25093,23 +24847,23 @@ class PipelineExecution(Base): parallelism_configuration: Optional[shapes.ParallelismConfiguration] = Unassigned() selective_execution_config: Optional[shapes.SelectiveExecutionConfig] = Unassigned() pipeline_version_id: Optional[int] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "pipeline_execution_name" - resource_name_split = resource_name.split("_") + resource_name = 'pipeline_execution_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object pipeline_execution") return None - + @classmethod @Base.add_validate_call def get( @@ -25120,17 +24874,17 @@ def get( ) -> Optional["PipelineExecution"]: """ Get a PipelineExecution resource - + Parameters: pipeline_execution_arn: The Amazon Resource Name (ARN) of the pipeline execution. session: Boto3 session. region: Region name. - + Returns: The PipelineExecution resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25141,38 +24895,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "PipelineExecutionArn": pipeline_execution_arn, + 'PipelineExecutionArn': pipeline_execution_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_pipeline_execution(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribePipelineExecutionResponse") + transformed_response = transform(response, 'DescribePipelineExecutionResponse') pipeline_execution = cls(**transformed_response) return pipeline_execution - + @Base.add_validate_call def refresh( self, - ) -> Optional["PipelineExecution"]: + + ) -> Optional["PipelineExecution"]: """ Refresh a PipelineExecution resource - + Returns: The PipelineExecution resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25183,21 +24936,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "PipelineExecutionArn": self.pipeline_execution_arn, + 'PipelineExecutionArn': self.pipeline_execution_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_pipeline_execution(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribePipelineExecutionResponse", self) + transform(response, 'DescribePipelineExecutionResponse', self) return self - + @Base.add_validate_call def update( self, @@ -25207,12 +24960,12 @@ def update( ) -> Optional["PipelineExecution"]: """ Update a PipelineExecution resource - + Returns: The PipelineExecution resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25224,35 +24977,35 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating pipeline_execution resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "PipelineExecutionArn": self.pipeline_execution_arn, - "PipelineExecutionDescription": pipeline_execution_description, - "PipelineExecutionDisplayName": pipeline_execution_display_name, - "ParallelismConfiguration": parallelism_configuration, + 'PipelineExecutionArn': self.pipeline_execution_arn, + 'PipelineExecutionDescription': pipeline_execution_description, + 'PipelineExecutionDisplayName': pipeline_execution_display_name, + 'ParallelismConfiguration': parallelism_configuration, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_pipeline_execution(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a PipelineExecution resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25264,81 +25017,75 @@ def stop(self) -> None: ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "PipelineExecutionArn": self.pipeline_execution_arn, - "ClientRequestToken": self.client_request_token, + 'PipelineExecutionArn': self.pipeline_execution_arn, + 'ClientRequestToken': self.client_request_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_pipeline_execution(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Executing", "Stopping", "Stopped", "Failed", "Succeeded"], + target_status: Literal['Executing', 'Stopping', 'Stopped', 'Failed', 'Succeeded'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a PipelineExecution resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for PipelineExecution to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.pipeline_execution_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="PipelineExecution", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="PipelineExecution", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="PipelineExecution", status=current_status - ) + raise TimeoutExceededError(resouce_type="PipelineExecution", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -25353,7 +25100,7 @@ def get_all( ) -> ResourceIterator["PipelineExecution"]: """ Get all PipelineExecution resources - + Parameters: pipeline_name: The name or Amazon Resource Name (ARN) of the pipeline. created_after: A filter that returns the pipeline executions that were created after a specified time. @@ -25364,12 +25111,12 @@ def get_all( max_results: The maximum number of pipeline executions to return in the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed PipelineExecution resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25380,50 +25127,51 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "PipelineName": pipeline_name, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'PipelineName': pipeline_name, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_pipeline_executions", - summaries_key="PipelineExecutionSummaries", - summary_name="PipelineExecutionSummary", + list_method='list_pipeline_executions', + summaries_key='PipelineExecutionSummaries', + summary_name='PipelineExecutionSummary', resource_cls=PipelineExecution, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_pipeline_definition( self, + session: Optional[Session] = None, region: Optional[str] = None, ) -> Optional[shapes.DescribePipelineDefinitionForExecutionResponse]: """ Describes the details of an execution's pipeline definition. - + Parameters: session: Boto3 session. region: Region name. - + Returns: shapes.DescribePipelineDefinitionForExecutionResponse - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25434,47 +25182,46 @@ def get_pipeline_definition( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "PipelineExecutionArn": self.pipeline_execution_arn, + 'PipelineExecutionArn': self.pipeline_execution_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling describe_pipeline_definition_for_execution API") response = client.describe_pipeline_definition_for_execution(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "DescribePipelineDefinitionForExecutionResponse") + + transformed_response = transform(response, 'DescribePipelineDefinitionForExecutionResponse') return shapes.DescribePipelineDefinitionForExecutionResponse(**transformed_response) - + + @Base.add_validate_call def get_all_steps( self, - sort_order: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_order: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[shapes.PipelineExecutionStep]: """ Gets a list of PipeLineExecutionStep objects. - + Parameters: next_token: If the result of the previous ListPipelineExecutionSteps request was truncated, the response includes a NextToken. To retrieve the next set of pipeline execution steps, use the token in the next request. max_results: The maximum number of pipeline execution steps to return in the response. sort_order: The field by which to sort results. The default is CreatedTime. session: Boto3 session. region: Region name. - + Returns: Iterator for listed PipelineExecutionStep. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25485,28 +25232,29 @@ def get_all_steps( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "PipelineExecutionArn": self.pipeline_execution_arn, - "SortOrder": sort_order, + 'PipelineExecutionArn': self.pipeline_execution_arn, + 'SortOrder': sort_order, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_pipeline_execution_steps", - summaries_key="PipelineExecutionSteps", - summary_name="PipelineExecutionStep", + list_method='list_pipeline_execution_steps', + summaries_key='PipelineExecutionSteps', + summary_name='PipelineExecutionStep', resource_cls=shapes.PipelineExecutionStep, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_parameters( self, @@ -25515,18 +25263,18 @@ def get_all_parameters( ) -> ResourceIterator[shapes.Parameter]: """ Gets a list of parameters for a pipeline execution. - + Parameters: next_token: If the result of the previous ListPipelineParametersForExecution request was truncated, the response includes a NextToken. To retrieve the next set of parameters, use the token in the next request. max_results: The maximum number of parameters to return in the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Parameter. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25537,27 +25285,28 @@ def get_all_parameters( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "PipelineExecutionArn": self.pipeline_execution_arn, + 'PipelineExecutionArn': self.pipeline_execution_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_pipeline_parameters_for_execution", - summaries_key="PipelineParameters", - summary_name="Parameter", + list_method='list_pipeline_parameters_for_execution', + summaries_key='PipelineParameters', + summary_name='Parameter', resource_cls=shapes.Parameter, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def retry( self, @@ -25567,14 +25316,14 @@ def retry( ) -> None: """ Retry the execution of the pipeline. - + Parameters: client_request_token: A unique, case-sensitive identifier that you provide to ensure the idempotency of the operation. An idempotent operation completes no more than once. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25587,24 +25336,25 @@ def retry( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "PipelineExecutionArn": self.pipeline_execution_arn, - "ClientRequestToken": client_request_token, - "ParallelismConfiguration": self.parallelism_configuration, + 'PipelineExecutionArn': self.pipeline_execution_arn, + 'ClientRequestToken': client_request_token, + 'ParallelismConfiguration': self.parallelism_configuration, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling retry_pipeline_execution API") response = client.retry_pipeline_execution(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def send_execution_step_failure( self, @@ -25615,15 +25365,15 @@ def send_execution_step_failure( ) -> None: """ Notifies the pipeline that the execution of a callback step failed, along with a message describing why. - + Parameters: callback_token: The pipeline generated token from the Amazon SQS queue. client_request_token: A unique, case-sensitive identifier that you provide to ensure the idempotency of the operation. An idempotent operation completes no more than one time. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25636,24 +25386,25 @@ def send_execution_step_failure( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "CallbackToken": callback_token, - "FailureReason": self.failure_reason, - "ClientRequestToken": client_request_token, + 'CallbackToken': callback_token, + 'FailureReason': self.failure_reason, + 'ClientRequestToken': client_request_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling send_pipeline_execution_step_failure API") response = client.send_pipeline_execution_step_failure(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def send_execution_step_success( self, @@ -25665,16 +25416,16 @@ def send_execution_step_success( ) -> None: """ Notifies the pipeline that the execution of a callback step succeeded and provides a list of the step's output parameters. - + Parameters: callback_token: The pipeline generated token from the Amazon SQS queue. output_parameters: A list of the output parameters of the callback step. client_request_token: A unique, case-sensitive identifier that you provide to ensure the idempotency of the operation. An idempotent operation completes no more than one time. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25687,40 +25438,39 @@ def send_execution_step_success( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "CallbackToken": callback_token, - "OutputParameters": output_parameters, - "ClientRequestToken": client_request_token, + 'CallbackToken': callback_token, + 'OutputParameters': output_parameters, + 'ClientRequestToken': client_request_token, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling send_pipeline_execution_step_success API") response = client.send_pipeline_execution_step_success(**operation_input_args) logger.debug(f"Response: {response}") + class PresignedDomainUrl(Base): """ Class representing resource PresignedDomainUrl - + Attributes: domain_id: The domain ID. user_profile_name: The name of the UserProfile to sign-in as. session_expiration_duration_in_seconds: The session expiration duration in seconds. This value defaults to 43200. expires_in_seconds: The number of seconds until the pre-signed URL expires. This value defaults to 300. space_name: The name of the space. - landing_uri: The landing page that the user is directed to when accessing the presigned URL. Using this value, users can access Studio or Studio Classic, even if it is not the default experience for the domain. The supported values are: studio::relative/path: Directs users to the relative path in Studio. app:JupyterServer:relative/path: Directs users to the relative path in the Studio Classic application. app:JupyterLab:relative/path: Directs users to the relative path in the JupyterLab application. app:RStudioServerPro:relative/path: Directs users to the relative path in the RStudio application. app:CodeEditor:relative/path: Directs users to the relative path in the Code Editor, based on Code-OSS, Visual Studio Code - Open Source application. app:Canvas:relative/path: Directs users to the relative path in the Canvas application. + landing_uri: The landing page that the user is directed to when accessing the presigned URL. Using this value, users can access Studio or Studio Classic, even if it is not the default experience for the domain. The supported values are: studio::relative/path: Directs users to the relative path in Studio. app:JupyterServer:relative/path: Directs users to the relative path in the Studio Classic application. app:JupyterLab:relative/path: Directs users to the relative path in the JupyterLab application. app:RStudioServerPro:relative/path: Directs users to the relative path in the RStudio application. app:CodeEditor:relative/path: Directs users to the relative path in the Code Editor, based on Code-OSS, Visual Studio Code - Open Source application. app:Canvas:relative/path: Directs users to the relative path in the Canvas application. authorized_url: The presigned URL. - + """ - domain_id: str user_profile_name: Union[str, object] session_expiration_duration_in_seconds: Optional[int] = Unassigned() @@ -25728,23 +25478,23 @@ class PresignedDomainUrl(Base): space_name: Optional[Union[str, object]] = Unassigned() landing_uri: Optional[str] = Unassigned() authorized_url: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "presigned_domain_url_name" - resource_name_split = resource_name.split("_") + resource_name = 'presigned_domain_url_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object presigned_domain_url") return None - + @classmethod @Base.add_validate_call def create( @@ -25758,22 +25508,22 @@ def create( ) -> Optional["PresignedDomainUrl"]: """ Create a PresignedDomainUrl resource - + Parameters: domain_id: The domain ID. user_profile_name: The name of the UserProfile to sign-in as. session_expiration_duration_in_seconds: The session expiration duration in seconds. This value defaults to 43200. expires_in_seconds: The number of seconds until the pre-signed URL expires. This value defaults to 300. space_name: The name of the space. - landing_uri: The landing page that the user is directed to when accessing the presigned URL. Using this value, users can access Studio or Studio Classic, even if it is not the default experience for the domain. The supported values are: studio::relative/path: Directs users to the relative path in Studio. app:JupyterServer:relative/path: Directs users to the relative path in the Studio Classic application. app:JupyterLab:relative/path: Directs users to the relative path in the JupyterLab application. app:RStudioServerPro:relative/path: Directs users to the relative path in the RStudio application. app:CodeEditor:relative/path: Directs users to the relative path in the Code Editor, based on Code-OSS, Visual Studio Code - Open Source application. app:Canvas:relative/path: Directs users to the relative path in the Canvas application. + landing_uri: The landing page that the user is directed to when accessing the presigned URL. Using this value, users can access Studio or Studio Classic, even if it is not the default experience for the domain. The supported values are: studio::relative/path: Directs users to the relative path in Studio. app:JupyterServer:relative/path: Directs users to the relative path in the Studio Classic application. app:JupyterLab:relative/path: Directs users to the relative path in the JupyterLab application. app:RStudioServerPro:relative/path: Directs users to the relative path in the RStudio application. app:CodeEditor:relative/path: Directs users to the relative path in the Code Editor, based on Code-OSS, Visual Studio Code - Open Source application. app:Canvas:relative/path: Directs users to the relative path in the Canvas application. session: Boto3 session. region: Region name. - + Returns: The PresignedDomainUrl resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25787,64 +25537,62 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + + operation_input_args = { - "DomainId": domain_id, - "UserProfileName": user_profile_name, - "SessionExpirationDurationInSeconds": session_expiration_duration_in_seconds, - "ExpiresInSeconds": expires_in_seconds, - "SpaceName": space_name, - "LandingUri": landing_uri, + 'DomainId': domain_id, + 'UserProfileName': user_profile_name, + 'SessionExpirationDurationInSeconds': session_expiration_duration_in_seconds, + 'ExpiresInSeconds': expires_in_seconds, + 'SpaceName': space_name, + 'LandingUri': landing_uri, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling create_presigned_domain_url API") response = client.create_presigned_domain_url(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "CreatePresignedDomainUrlResponse") + + transformed_response = transform(response, 'CreatePresignedDomainUrlResponse') return cls(**operation_input_args, **transformed_response) class PresignedMlflowTrackingServerUrl(Base): """ Class representing resource PresignedMlflowTrackingServerUrl - + Attributes: tracking_server_name: The name of the tracking server to connect to your MLflow UI. expires_in_seconds: The duration in seconds that your presigned URL is valid. The presigned URL can be used only once. session_expiration_duration_in_seconds: The duration in seconds that your MLflow UI session is valid. authorized_url: A presigned URL with an authorization token. - + """ - tracking_server_name: str expires_in_seconds: Optional[int] = Unassigned() session_expiration_duration_in_seconds: Optional[int] = Unassigned() authorized_url: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "presigned_mlflow_tracking_server_url_name" - resource_name_split = resource_name.split("_") + resource_name = 'presigned_mlflow_tracking_server_url_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object presigned_mlflow_tracking_server_url") return None - + @classmethod @Base.add_validate_call def create( @@ -25855,19 +25603,19 @@ def create( ) -> Optional["PresignedMlflowTrackingServerUrl"]: """ Create a PresignedMlflowTrackingServerUrl resource - + Parameters: tracking_server_name: The name of the tracking server to connect to your MLflow UI. expires_in_seconds: The duration in seconds that your presigned URL is valid. The presigned URL can be used only once. session_expiration_duration_in_seconds: The duration in seconds that your MLflow UI session is valid. session: Boto3 session. region: Region name. - + Returns: The PresignedMlflowTrackingServerUrl resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25881,59 +25629,57 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + + operation_input_args = { - "TrackingServerName": tracking_server_name, - "ExpiresInSeconds": expires_in_seconds, - "SessionExpirationDurationInSeconds": session_expiration_duration_in_seconds, + 'TrackingServerName': tracking_server_name, + 'ExpiresInSeconds': expires_in_seconds, + 'SessionExpirationDurationInSeconds': session_expiration_duration_in_seconds, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling create_presigned_mlflow_tracking_server_url API") response = client.create_presigned_mlflow_tracking_server_url(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "CreatePresignedMlflowTrackingServerUrlResponse") + + transformed_response = transform(response, 'CreatePresignedMlflowTrackingServerUrlResponse') return cls(**operation_input_args, **transformed_response) class PresignedNotebookInstanceUrl(Base): """ Class representing resource PresignedNotebookInstanceUrl - + Attributes: notebook_instance_name: The name of the notebook instance. session_expiration_duration_in_seconds: The duration of the session, in seconds. The default is 12 hours. - authorized_url: A JSON object that contains the URL string. - + authorized_url: A JSON object that contains the URL string. + """ - notebook_instance_name: Union[str, object] session_expiration_duration_in_seconds: Optional[int] = Unassigned() authorized_url: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "presigned_notebook_instance_url_name" - resource_name_split = resource_name.split("_") + resource_name = 'presigned_notebook_instance_url_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object presigned_notebook_instance_url") return None - + @classmethod @Base.add_validate_call def create( @@ -25943,18 +25689,18 @@ def create( ) -> Optional["PresignedNotebookInstanceUrl"]: """ Create a PresignedNotebookInstanceUrl resource - + Parameters: notebook_instance_name: The name of the notebook instance. session_expiration_duration_in_seconds: The duration of the session, in seconds. The default is 12 hours. session: Boto3 session. region: Region name. - + Returns: The PresignedNotebookInstanceUrl resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -25967,31 +25713,30 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + + operation_input_args = { - "NotebookInstanceName": notebook_instance_name, - "SessionExpirationDurationInSeconds": session_expiration_duration_in_seconds, + 'NotebookInstanceName': notebook_instance_name, + 'SessionExpirationDurationInSeconds': session_expiration_duration_in_seconds, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling create_presigned_notebook_instance_url API") response = client.create_presigned_notebook_instance_url(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "CreatePresignedNotebookInstanceUrlOutput") + + transformed_response = transform(response, 'CreatePresignedNotebookInstanceUrlOutput') return cls(**operation_input_args, **transformed_response) class ProcessingJob(Base): """ Class representing resource ProcessingJob - + Attributes: processing_job_name: The name of the processing job. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. processing_resources: Identifies the resources, ML compute instances, and ML storage volumes to deploy for a processing job. In distributed training, you specify more than one instance. @@ -26014,9 +25759,8 @@ class ProcessingJob(Base): monitoring_schedule_arn: The ARN of a monitoring schedule for an endpoint associated with this processing job. auto_ml_job_arn: The ARN of an AutoML job associated with this processing job. training_job_arn: The ARN of a training job associated with this processing job. - + """ - processing_job_name: str processing_inputs: Optional[List[shapes.ProcessingInput]] = Unassigned() processing_output_config: Optional[shapes.ProcessingOutputConfig] = Unassigned() @@ -26038,48 +25782,64 @@ class ProcessingJob(Base): monitoring_schedule_arn: Optional[str] = Unassigned() auto_ml_job_arn: Optional[str] = Unassigned() training_job_arn: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "processing_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'processing_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object processing_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "processing_resources": { - "cluster_config": {"volume_kms_key_id": {"type": "string"}} - }, - "processing_output_config": {"kms_key_id": {"type": "string"}}, - "network_config": { - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - } - }, - "role_arn": {"type": "string"}, + config_schema_for_resource = \ + { + "processing_resources": { + "cluster_config": { + "volume_kms_key_id": { + "type": "string" + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "ProcessingJob", **kwargs - ), - ) - + }, + "processing_output_config": { + "kms_key_id": { + "type": "string" + } + }, + "network_config": { + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "role_arn": { + "type": "string" + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "ProcessingJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -26101,7 +25861,7 @@ def create( ) -> Optional["ProcessingJob"]: """ Create a ProcessingJob resource - + Parameters: processing_job_name: The name of the processing job. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. processing_resources: Identifies the resources, ML compute instances, and ML storage volumes to deploy for a processing job. In distributed training, you specify more than one instance. @@ -26110,18 +25870,18 @@ def create( processing_inputs: An array of inputs configuring the data to download into the processing container. processing_output_config: Output configuration for the processing job. stopping_condition: The time limit for how long the processing job is allowed to run. - environment: The environment variables to set in the Docker container. Up to 100 key and values entries in the map are supported. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any environment fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request environment variable or plain text fields. + environment: The environment variables to set in the Docker container. Up to 100 key and values entries in the map are supported. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any environment fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request environment variable or plain text fields. network_config: Networking options for a processing job, such as whether to allow inbound and outbound network calls to and from processing containers, and the VPC subnets and security groups to use for VPC-enabled processing jobs. - tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any tags. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request tag variable or plain text fields. - experiment_config: + tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any tags. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request tag variable or plain text fields. + experiment_config: session: Boto3 session. region: Region name. - + Returns: The ProcessingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26137,41 +25897,37 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating processing_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ProcessingInputs": processing_inputs, - "ProcessingOutputConfig": processing_output_config, - "ProcessingJobName": processing_job_name, - "ProcessingResources": processing_resources, - "StoppingCondition": stopping_condition, - "AppSpecification": app_specification, - "Environment": environment, - "NetworkConfig": network_config, - "RoleArn": role_arn, - "Tags": tags, - "ExperimentConfig": experiment_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="ProcessingJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ProcessingInputs': processing_inputs, + 'ProcessingOutputConfig': processing_output_config, + 'ProcessingJobName': processing_job_name, + 'ProcessingResources': processing_resources, + 'StoppingCondition': stopping_condition, + 'AppSpecification': app_specification, + 'Environment': environment, + 'NetworkConfig': network_config, + 'RoleArn': role_arn, + 'Tags': tags, + 'ExperimentConfig': experiment_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='ProcessingJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_processing_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(processing_job_name=processing_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -26182,17 +25938,17 @@ def get( ) -> Optional["ProcessingJob"]: """ Get a ProcessingJob resource - + Parameters: processing_job_name: The name of the processing job. The name must be unique within an Amazon Web Services Region in the Amazon Web Services account. session: Boto3 session. region: Region name. - + Returns: The ProcessingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26203,38 +25959,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ProcessingJobName": processing_job_name, + 'ProcessingJobName': processing_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_processing_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeProcessingJobResponse") + transformed_response = transform(response, 'DescribeProcessingJobResponse') processing_job = cls(**transformed_response) return processing_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["ProcessingJob"]: + + ) -> Optional["ProcessingJob"]: """ Refresh a ProcessingJob resource - + Returns: The ProcessingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26245,28 +26000,28 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "ProcessingJobName": self.processing_job_name, + 'ProcessingJobName': self.processing_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_processing_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeProcessingJobResponse", self) + transform(response, 'DescribeProcessingJobResponse', self) return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a ProcessingJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26277,20 +26032,20 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "ProcessingJobName": self.processing_job_name, + 'ProcessingJobName': self.processing_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_processing_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, @@ -26300,71 +26055,68 @@ def wait( ) -> None: """ Wait for a ProcessingJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. logs: Whether to print logs while waiting. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed", "Stopped"] + terminal_states = ['Completed', 'Failed', 'Stopped'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for ProcessingJob...") status = Status("Current status:") - + instance_count = self.processing_resources.cluster_config.instance_count if logs: multi_stream_logger = MultiLogStreamHandler( log_group_name=f"/aws/sagemaker/ProcessingJobs", log_stream_name_prefix=self.get_name(), - expected_stream_count=instance_count, + expected_stream_count=instance_count ) - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.processing_job_status status.update(f"Current status: [bold]{current_status}") - + if logs and multi_stream_logger.ready(): stream_log_events = multi_stream_logger.get_latest_log_events() for stream_id, event in stream_log_events: logger.info(f"{stream_id}:\n{event['message']}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="ProcessingJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="ProcessingJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="ProcessingJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -26382,7 +26134,7 @@ def get_all( ) -> ResourceIterator["ProcessingJob"]: """ Get all ProcessingJob resources - + Parameters: creation_time_after: A filter that returns only processing jobs created after the specified time. creation_time_before: A filter that returns only processing jobs created after the specified time. @@ -26396,12 +26148,12 @@ def get_all( max_results: The maximum number of processing jobs to return in the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ProcessingJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26411,40 +26163,39 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_processing_jobs", - summaries_key="ProcessingJobSummaries", - summary_name="ProcessingJobSummary", + list_method='list_processing_jobs', + summaries_key='ProcessingJobSummaries', + summary_name='ProcessingJobSummary', resource_cls=ProcessingJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Project(Base): """ Class representing resource Project - + Attributes: project_arn: The Amazon Resource Name (ARN) of the project. project_name: The name of the project. @@ -26454,55 +26205,48 @@ class Project(Base): project_description: The description of the project. service_catalog_provisioning_details: Information used to provision a service catalog product. For information, see What is Amazon Web Services Service Catalog. service_catalog_provisioned_product_details: Information about a provisioned service catalog product. - template_provider_details: An array of template providers associated with the project. - created_by: + template_provider_details: An array of template providers associated with the project. + created_by: last_modified_time: The timestamp when project was last modified. - last_modified_by: - + last_modified_by: + """ - project_name: str project_arn: Optional[str] = Unassigned() project_id: Optional[str] = Unassigned() project_description: Optional[str] = Unassigned() - service_catalog_provisioning_details: Optional[shapes.ServiceCatalogProvisioningDetails] = ( - Unassigned() - ) - service_catalog_provisioned_product_details: Optional[ - shapes.ServiceCatalogProvisionedProductDetails - ] = Unassigned() + service_catalog_provisioning_details: Optional[shapes.ServiceCatalogProvisioningDetails] = Unassigned() + service_catalog_provisioned_product_details: Optional[shapes.ServiceCatalogProvisionedProductDetails] = Unassigned() project_status: Optional[str] = Unassigned() template_provider_details: Optional[List[shapes.TemplateProviderDetail]] = Unassigned() created_by: Optional[shapes.UserContext] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "project_name" - resource_name_split = resource_name.split("_") + resource_name = 'project_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object project") return None - + @classmethod @Base.add_validate_call def create( cls, project_name: str, project_description: Optional[str] = Unassigned(), - service_catalog_provisioning_details: Optional[ - shapes.ServiceCatalogProvisioningDetails - ] = Unassigned(), + service_catalog_provisioning_details: Optional[shapes.ServiceCatalogProvisioningDetails] = Unassigned(), tags: Optional[List[shapes.Tag]] = Unassigned(), template_providers: Optional[List[shapes.CreateTemplateProvider]] = Unassigned(), session: Optional[Session] = None, @@ -26510,21 +26254,21 @@ def create( ) -> Optional["Project"]: """ Create a Project resource - + Parameters: project_name: The name of the project. project_description: A description for the project. service_catalog_provisioning_details: The product ID and provisioning artifact ID to provision a service catalog. The provisioning artifact ID will default to the latest provisioning artifact ID of the product, if you don't provide the provisioning artifact ID. For more information, see What is Amazon Web Services Service Catalog. tags: An array of key-value pairs that you want to use to organize and track your Amazon Web Services resource costs. For more information, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference Guide. - template_providers: An array of template provider configurations for creating infrastructure resources for the project. + template_providers: An array of template provider configurations for creating infrastructure resources for the project. session: Boto3 session. region: Region name. - + Returns: The Project resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26538,35 +26282,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating project resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "ProjectName": project_name, - "ProjectDescription": project_description, - "ServiceCatalogProvisioningDetails": service_catalog_provisioning_details, - "Tags": tags, - "TemplateProviders": template_providers, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Project", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'ProjectName': project_name, + 'ProjectDescription': project_description, + 'ServiceCatalogProvisioningDetails': service_catalog_provisioning_details, + 'Tags': tags, + 'TemplateProviders': template_providers, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Project', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_project(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(project_name=project_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -26577,17 +26317,17 @@ def get( ) -> Optional["Project"]: """ Get a Project resource - + Parameters: project_name: The name of the project to describe. session: Boto3 session. region: Region name. - + Returns: The Project resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26597,38 +26337,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ProjectName": project_name, + 'ProjectName': project_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_project(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeProjectOutput") + transformed_response = transform(response, 'DescribeProjectOutput') project = cls(**transformed_response) return project - + @Base.add_validate_call def refresh( self, - ) -> Optional["Project"]: + + ) -> Optional["Project"]: """ Refresh a Project resource - + Returns: The Project resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26638,44 +26377,42 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "ProjectName": self.project_name, + 'ProjectName': self.project_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_project(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeProjectOutput", self) + transform(response, 'DescribeProjectOutput', self) return self - + @Base.add_validate_call def update( self, project_description: Optional[str] = Unassigned(), - service_catalog_provisioning_update_details: Optional[ - shapes.ServiceCatalogProvisioningUpdateDetails - ] = Unassigned(), + service_catalog_provisioning_update_details: Optional[shapes.ServiceCatalogProvisioningUpdateDetails] = Unassigned(), tags: Optional[List[shapes.Tag]] = Unassigned(), template_providers_to_update: Optional[List[shapes.UpdateTemplateProvider]] = Unassigned(), ) -> Optional["Project"]: """ Update a Project resource - + Parameters: - service_catalog_provisioning_update_details: The product ID and provisioning artifact ID to provision a service catalog. The provisioning artifact ID will default to the latest provisioning artifact ID of the product, if you don't provide the provisioning artifact ID. For more information, see What is Amazon Web Services Service Catalog. + service_catalog_provisioning_update_details: The product ID and provisioning artifact ID to provision a service catalog. The provisioning artifact ID will default to the latest provisioning artifact ID of the product, if you don't provide the provisioning artifact ID. For more information, see What is Amazon Web Services Service Catalog. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. In addition, the project must have tag update constraints set in order to include this parameter in the request. For more information, see Amazon Web Services Service Catalog Tag Update Constraints. - template_providers_to_update: The template providers to update in the project. - + template_providers_to_update: The template providers to update in the project. + Returns: The Project resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26686,38 +26423,39 @@ def update( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + logger.info("Updating project resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "ProjectName": self.project_name, - "ProjectDescription": project_description, - "ServiceCatalogProvisioningUpdateDetails": service_catalog_provisioning_update_details, - "Tags": tags, - "TemplateProvidersToUpdate": template_providers_to_update, + 'ProjectName': self.project_name, + 'ProjectDescription': project_description, + 'ServiceCatalogProvisioningUpdateDetails': service_catalog_provisioning_update_details, + 'Tags': tags, + 'TemplateProvidersToUpdate': template_providers_to_update, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_project(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Project resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26728,87 +26466,74 @@ def delete( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "ProjectName": self.project_name, + 'ProjectName': self.project_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_project(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Pending", - "CreateInProgress", - "CreateCompleted", - "CreateFailed", - "DeleteInProgress", - "DeleteFailed", - "DeleteCompleted", - "UpdateInProgress", - "UpdateCompleted", - "UpdateFailed", - ], + target_status: Literal['Pending', 'CreateInProgress', 'CreateCompleted', 'CreateFailed', 'DeleteInProgress', 'DeleteFailed', 'DeleteCompleted', 'UpdateInProgress', 'UpdateCompleted', 'UpdateFailed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Project resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Project to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.project_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Project", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="Project", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Project", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -26823,7 +26548,7 @@ def get_all( ) -> ResourceIterator["Project"]: """ Get all Project resources - + Parameters: creation_time_after: A filter that returns the projects that were created after a specified time. creation_time_before: A filter that returns the projects that were created before a specified time. @@ -26834,12 +26559,12 @@ def get_all( sort_order: The sort order for results. The default is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Project resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26849,66 +26574,64 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "NameContains": name_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'NameContains': name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_projects", - summaries_key="ProjectSummaryList", - summary_name="ProjectSummary", + list_method='list_projects', + summaries_key='ProjectSummaryList', + summary_name='ProjectSummary', resource_cls=Project, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class ResourceCatalog(Base): """ Class representing resource ResourceCatalog - + Attributes: - resource_catalog_arn: The Amazon Resource Name (ARN) of the ResourceCatalog. - resource_catalog_name: The name of the ResourceCatalog. - description: A free form description of the ResourceCatalog. - creation_time: The time the ResourceCatalog was created. - + resource_catalog_arn: The Amazon Resource Name (ARN) of the ResourceCatalog. + resource_catalog_name: The name of the ResourceCatalog. + description: A free form description of the ResourceCatalog. + creation_time: The time the ResourceCatalog was created. + """ - resource_catalog_arn: str resource_catalog_name: str description: str creation_time: datetime.datetime - + def get_name(self) -> str: attributes = vars(self) - resource_name = "resource_catalog_name" - resource_name_split = resource_name.split("_") + resource_name = 'resource_catalog_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object resource_catalog") return None - + @classmethod @Base.add_validate_call def get_all( @@ -26923,23 +26646,23 @@ def get_all( ) -> ResourceIterator["ResourceCatalog"]: """ Get all ResourceCatalog resources - - Parameters: - name_contains: A string that partially matches one or more ResourceCatalogs names. Filters ResourceCatalog by name. - creation_time_after: Use this parameter to search for ResourceCatalogs created after a specific date and time. - creation_time_before: Use this parameter to search for ResourceCatalogs created before a specific date and time. - sort_order: The order in which the resource catalogs are listed. - sort_by: The value on which the resource catalog list is sorted. - max_results: The maximum number of results returned by ListResourceCatalogs. - next_token: A token to resume pagination of ListResourceCatalogs results. + + Parameters: + name_contains: A string that partially matches one or more ResourceCatalogs names. Filters ResourceCatalog by name. + creation_time_after: Use this parameter to search for ResourceCatalogs created after a specific date and time. + creation_time_before: Use this parameter to search for ResourceCatalogs created before a specific date and time. + sort_order: The order in which the resource catalogs are listed. + sort_by: The value on which the resource catalog list is sorted. + max_results: The maximum number of results returned by ListResourceCatalogs. + next_token: A token to resume pagination of ListResourceCatalogs results. session: Boto3 session. region: Region name. - + Returns: Iterator for listed ResourceCatalog resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -26949,39 +26672,38 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "NameContains": name_contains, - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "SortOrder": sort_order, - "SortBy": sort_by, + 'NameContains': name_contains, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'SortOrder': sort_order, + 'SortBy': sort_by, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_resource_catalogs", - summaries_key="ResourceCatalogs", - summary_name="ResourceCatalog", + list_method='list_resource_catalogs', + summaries_key='ResourceCatalogs', + summary_name='ResourceCatalog', resource_cls=ResourceCatalog, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class SagemakerServicecatalogPortfolio(Base): """ Class representing resource SagemakerServicecatalogPortfolio - + """ - + @staticmethod @Base.add_validate_call def disable( @@ -26990,13 +26712,13 @@ def disable( ) -> None: """ Disables using Service Catalog in SageMaker. - + Parameters: session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27006,15 +26728,16 @@ def disable( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling disable_sagemaker_servicecatalog_portfolio API") response = client.disable_sagemaker_servicecatalog_portfolio() logger.debug(f"Response: {response}") - + + @staticmethod @Base.add_validate_call def enable( @@ -27023,13 +26746,13 @@ def enable( ) -> None: """ Enables using Service Catalog in SageMaker. - + Parameters: session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27039,15 +26762,16 @@ def enable( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling enable_sagemaker_servicecatalog_portfolio API") response = client.enable_sagemaker_servicecatalog_portfolio() logger.debug(f"Response: {response}") - + + @staticmethod @Base.add_validate_call def get_status( @@ -27056,16 +26780,16 @@ def get_status( ) -> Optional[str]: """ Gets the status of Service Catalog in SageMaker. - + Parameters: session: Boto3 session. region: Region name. - + Returns: str - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27075,29 +26799,22 @@ def get_status( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling get_sagemaker_servicecatalog_portfolio_status API") response = client.get_sagemaker_servicecatalog_portfolio_status() logger.debug(f"Response: {response}") - + return list(response.values())[0] -class Session(Base): - """ - Class representing resource Session - - """ - - class Space(Base): """ Class representing resource Space - + Attributes: domain_id: The ID of the associated domain. space_arn: The space's Amazon Resource Name (ARN). @@ -27111,10 +26828,9 @@ class Space(Base): ownership_settings: The collection of ownership settings for a space. space_sharing_settings: The collection of space sharing settings for a space. space_display_name: The name of the space that appears in the Amazon SageMaker Studio UI. - url: Returns the URL of the space. If the space is created with Amazon Web Services IAM Identity Center (Successor to Amazon Web Services Single Sign-On) authentication, users can navigate to the URL after appending the respective redirect parameter for the application type to be federated through Amazon Web Services IAM Identity Center. The following application types are supported: Studio Classic: &redirect=JupyterServer JupyterLab: &redirect=JupyterLab Code Editor, based on Code-OSS, Visual Studio Code - Open Source: &redirect=CodeEditor - + url: Returns the URL of the space. If the space is created with Amazon Web Services IAM Identity Center (Successor to Amazon Web Services Single Sign-On) authentication, users can navigate to the URL after appending the respective redirect parameter for the application type to be federated through Amazon Web Services IAM Identity Center. The following application types are supported: Studio Classic: &redirect=JupyterServer JupyterLab: &redirect=JupyterLab Code Editor, based on Code-OSS, Visual Studio Code - Open Source: &redirect=CodeEditor + """ - domain_id: str space_name: str space_arn: Optional[str] = Unassigned() @@ -27128,23 +26844,23 @@ class Space(Base): space_sharing_settings: Optional[shapes.SpaceSharingSettings] = Unassigned() space_display_name: Optional[str] = Unassigned() url: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "space_name" - resource_name_split = resource_name.split("_") + resource_name = 'space_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object space") return None - + @classmethod @Base.add_validate_call def create( @@ -27161,7 +26877,7 @@ def create( ) -> Optional["Space"]: """ Create a Space resource - + Parameters: domain_id: The ID of the associated domain. space_name: The name of the space. @@ -27172,12 +26888,12 @@ def create( space_display_name: The name of the space that appears in the SageMaker Studio UI. session: Boto3 session. region: Region name. - + Returns: The Space resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27192,37 +26908,33 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating space resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "DomainId": domain_id, - "SpaceName": space_name, - "Tags": tags, - "SpaceSettings": space_settings, - "OwnershipSettings": ownership_settings, - "SpaceSharingSettings": space_sharing_settings, - "SpaceDisplayName": space_display_name, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Space", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'DomainId': domain_id, + 'SpaceName': space_name, + 'Tags': tags, + 'SpaceSettings': space_settings, + 'OwnershipSettings': ownership_settings, + 'SpaceSharingSettings': space_sharing_settings, + 'SpaceDisplayName': space_display_name, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Space', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_space(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(domain_id=domain_id, space_name=space_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -27234,18 +26946,18 @@ def get( ) -> Optional["Space"]: """ Get a Space resource - + Parameters: domain_id: The ID of the associated domain. space_name: The name of the space. session: Boto3 session. region: Region name. - + Returns: The Space resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27256,39 +26968,38 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": domain_id, - "SpaceName": space_name, + 'DomainId': domain_id, + 'SpaceName': space_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_space(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeSpaceResponse") + transformed_response = transform(response, 'DescribeSpaceResponse') space = cls(**transformed_response) return space - + @Base.add_validate_call def refresh( self, - ) -> Optional["Space"]: + + ) -> Optional["Space"]: """ Refresh a Space resource - + Returns: The Space resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27299,22 +27010,22 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": self.domain_id, - "SpaceName": self.space_name, + 'DomainId': self.domain_id, + 'SpaceName': self.space_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_space(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeSpaceResponse", self) + transform(response, 'DescribeSpaceResponse', self) return self - + @Base.add_validate_call def update( self, @@ -27323,12 +27034,12 @@ def update( ) -> Optional["Space"]: """ Update a Space resource - + Returns: The Space resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27341,37 +27052,38 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating space resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "DomainId": self.domain_id, - "SpaceName": self.space_name, - "SpaceSettings": space_settings, - "SpaceDisplayName": space_display_name, + 'DomainId': self.domain_id, + 'SpaceName': self.space_name, + 'SpaceSettings': space_settings, + 'SpaceDisplayName': space_display_name, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_space(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Space resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27383,85 +27095,75 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "DomainId": self.domain_id, - "SpaceName": self.space_name, + 'DomainId': self.domain_id, + 'SpaceName': self.space_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_space(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Deleting", - "Failed", - "InService", - "Pending", - "Updating", - "Update_Failed", - "Delete_Failed", - ], + target_status: Literal['Deleting', 'Failed', 'InService', 'Pending', 'Updating', 'Update_Failed', 'Delete_Failed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Space resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Space to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Space", status=current_status, reason=self.failure_reason - ) - + raise FailedStatusError(resource_type="Space", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Space", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -27470,13 +27172,13 @@ def wait_for_delete( ) -> None: """ Wait for a Space resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27490,47 +27192,37 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Space to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - - if ( - "delete_failed" in current_status.lower() - or "deletefailed" in current_status.lower() - ): - raise DeleteFailedStatusError( - resource_type="Space", reason=self.failure_reason - ) - + + if "delete_failed" in current_status.lower() or "deletefailed" in current_status.lower(): + raise DeleteFailedStatusError(resource_type="Space", reason=self.failure_reason) + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Space", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -27544,7 +27236,7 @@ def get_all( ) -> ResourceIterator["Space"]: """ Get all Space resources - + Parameters: next_token: If the previous response was truncated, you will receive this token. Use it in your next request to receive the next set of results. max_results: This parameter defines the maximum number of results that can be return in a single response. The MaxResults parameter is an upper bound, not a target. If there are more results available than the value specified, a NextToken is provided in the response. The NextToken indicates that the user should get the next set of results by providing this token as a part of a subsequent call. The default value for MaxResults is 10. @@ -27554,12 +27246,12 @@ def get_all( space_name_contains: A parameter by which to filter the results. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Space resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27569,36 +27261,35 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortOrder": sort_order, - "SortBy": sort_by, - "DomainIdEquals": domain_id_equals, - "SpaceNameContains": space_name_contains, + 'SortOrder': sort_order, + 'SortBy': sort_by, + 'DomainIdEquals': domain_id_equals, + 'SpaceNameContains': space_name_contains, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_spaces", - summaries_key="Spaces", - summary_name="SpaceDetails", + list_method='list_spaces', + summaries_key='Spaces', + summary_name='SpaceDetails', resource_cls=Space, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class StudioLifecycleConfig(Base): """ Class representing resource StudioLifecycleConfig - + Attributes: studio_lifecycle_config_arn: The ARN of the Lifecycle Configuration to describe. studio_lifecycle_config_name: The name of the Amazon SageMaker AI Studio Lifecycle Configuration that is described. @@ -27606,32 +27297,31 @@ class StudioLifecycleConfig(Base): last_modified_time: This value is equivalent to CreationTime because Amazon SageMaker AI Studio Lifecycle Configurations are immutable. studio_lifecycle_config_content: The content of your Amazon SageMaker AI Studio Lifecycle Configuration script. studio_lifecycle_config_app_type: The App type that the Lifecycle Configuration is attached to. - + """ - studio_lifecycle_config_name: str studio_lifecycle_config_arn: Optional[str] = Unassigned() creation_time: Optional[datetime.datetime] = Unassigned() last_modified_time: Optional[datetime.datetime] = Unassigned() studio_lifecycle_config_content: Optional[str] = Unassigned() studio_lifecycle_config_app_type: Optional[str] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "studio_lifecycle_config_name" - resource_name_split = resource_name.split("_") + resource_name = 'studio_lifecycle_config_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object studio_lifecycle_config") return None - + @classmethod @Base.add_validate_call def create( @@ -27645,20 +27335,20 @@ def create( ) -> Optional["StudioLifecycleConfig"]: """ Create a StudioLifecycleConfig resource - + Parameters: studio_lifecycle_config_name: The name of the Amazon SageMaker AI Studio Lifecycle Configuration to create. studio_lifecycle_config_content: The content of your Amazon SageMaker AI Studio Lifecycle Configuration script. This content must be base64 encoded. studio_lifecycle_config_app_type: The App type that the Lifecycle Configuration is attached to. - tags: Tags to be associated with the Lifecycle Configuration. Each tag consists of a key and an optional value. Tag keys must be unique per resource. Tags are searchable using the Search API. + tags: Tags to be associated with the Lifecycle Configuration. Each tag consists of a key and an optional value. Tag keys must be unique per resource. Tags are searchable using the Search API. session: Boto3 session. region: Region name. - + Returns: The StudioLifecycleConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27672,38 +27362,30 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating studio_lifecycle_config resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "StudioLifecycleConfigName": studio_lifecycle_config_name, - "StudioLifecycleConfigContent": studio_lifecycle_config_content, - "StudioLifecycleConfigAppType": studio_lifecycle_config_app_type, - "Tags": tags, + 'StudioLifecycleConfigName': studio_lifecycle_config_name, + 'StudioLifecycleConfigContent': studio_lifecycle_config_content, + 'StudioLifecycleConfigAppType': studio_lifecycle_config_app_type, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="StudioLifecycleConfig", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='StudioLifecycleConfig', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_studio_lifecycle_config(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - studio_lifecycle_config_name=studio_lifecycle_config_name, - session=session, - region=region, - ) - + + return cls.get(studio_lifecycle_config_name=studio_lifecycle_config_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -27714,17 +27396,17 @@ def get( ) -> Optional["StudioLifecycleConfig"]: """ Get a StudioLifecycleConfig resource - + Parameters: studio_lifecycle_config_name: The name of the Amazon SageMaker AI Studio Lifecycle Configuration to describe. session: Boto3 session. region: Region name. - + Returns: The StudioLifecycleConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27735,38 +27417,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "StudioLifecycleConfigName": studio_lifecycle_config_name, + 'StudioLifecycleConfigName': studio_lifecycle_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_studio_lifecycle_config(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeStudioLifecycleConfigResponse") + transformed_response = transform(response, 'DescribeStudioLifecycleConfigResponse') studio_lifecycle_config = cls(**transformed_response) return studio_lifecycle_config - + @Base.add_validate_call def refresh( self, - ) -> Optional["StudioLifecycleConfig"]: + + ) -> Optional["StudioLifecycleConfig"]: """ Refresh a StudioLifecycleConfig resource - + Returns: The StudioLifecycleConfig resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27777,30 +27458,31 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "StudioLifecycleConfigName": self.studio_lifecycle_config_name, + 'StudioLifecycleConfigName': self.studio_lifecycle_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_studio_lifecycle_config(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeStudioLifecycleConfigResponse", self) + transform(response, 'DescribeStudioLifecycleConfigResponse', self) return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a StudioLifecycleConfig resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27812,20 +27494,20 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "StudioLifecycleConfigName": self.studio_lifecycle_config_name, + 'StudioLifecycleConfigName': self.studio_lifecycle_config_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_studio_lifecycle_config(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -27843,7 +27525,7 @@ def get_all( ) -> ResourceIterator["StudioLifecycleConfig"]: """ Get all StudioLifecycleConfig resources - + Parameters: max_results: The total number of items to return in the response. If the total number of items available is more than the value specified, a NextToken is provided in the response. To resume pagination, provide the NextToken value in the as part of a subsequent call. The default value is 10. next_token: If the previous call to ListStudioLifecycleConfigs didn't return the full set of Lifecycle Configurations, the call returns a token for getting the next set of Lifecycle Configurations. @@ -27857,12 +27539,12 @@ def get_all( sort_order: The sort order. The default value is Descending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed StudioLifecycleConfig resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27873,64 +27555,62 @@ def get_all( ``` ResourceInUse: Resource being accessed is in use. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "NameContains": name_contains, - "AppTypeEquals": app_type_equals, - "CreationTimeBefore": creation_time_before, - "CreationTimeAfter": creation_time_after, - "ModifiedTimeBefore": modified_time_before, - "ModifiedTimeAfter": modified_time_after, - "SortBy": sort_by, - "SortOrder": sort_order, + 'NameContains': name_contains, + 'AppTypeEquals': app_type_equals, + 'CreationTimeBefore': creation_time_before, + 'CreationTimeAfter': creation_time_after, + 'ModifiedTimeBefore': modified_time_before, + 'ModifiedTimeAfter': modified_time_after, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_studio_lifecycle_configs", - summaries_key="StudioLifecycleConfigs", - summary_name="StudioLifecycleConfigDetails", + list_method='list_studio_lifecycle_configs', + summaries_key='StudioLifecycleConfigs', + summary_name='StudioLifecycleConfigDetails', resource_cls=StudioLifecycleConfig, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class SubscribedWorkteam(Base): """ Class representing resource SubscribedWorkteam - + Attributes: subscribed_workteam: A Workteam instance that contains information about the work team. - + """ - workteam_arn: str subscribed_workteam: Optional[shapes.SubscribedWorkteam] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "subscribed_workteam_name" - resource_name_split = resource_name.split("_") + resource_name = 'subscribed_workteam_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object subscribed_workteam") return None - + @classmethod @Base.add_validate_call def get( @@ -27941,17 +27621,17 @@ def get( ) -> Optional["SubscribedWorkteam"]: """ Get a SubscribedWorkteam resource - + Parameters: workteam_arn: The Amazon Resource Name (ARN) of the subscribed work team to describe. session: Boto3 session. region: Region name. - + Returns: The SubscribedWorkteam resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -27961,38 +27641,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "WorkteamArn": workteam_arn, + 'WorkteamArn': workteam_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_subscribed_workteam(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeSubscribedWorkteamResponse") + transformed_response = transform(response, 'DescribeSubscribedWorkteamResponse') subscribed_workteam = cls(**transformed_response) return subscribed_workteam - + @Base.add_validate_call def refresh( self, - ) -> Optional["SubscribedWorkteam"]: + + ) -> Optional["SubscribedWorkteam"]: """ Refresh a SubscribedWorkteam resource - + Returns: The SubscribedWorkteam resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28002,21 +27681,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "WorkteamArn": self.workteam_arn, + 'WorkteamArn': self.workteam_arn, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_subscribed_workteam(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeSubscribedWorkteamResponse", self) + transform(response, 'DescribeSubscribedWorkteamResponse', self) return self - + @classmethod @Base.add_validate_call def get_all( @@ -28027,19 +27706,19 @@ def get_all( ) -> ResourceIterator["SubscribedWorkteam"]: """ Get all SubscribedWorkteam resources - + Parameters: name_contains: A string in the work team name. This filter returns only work teams whose name contains the specified string. next_token: If the result of the previous ListSubscribedWorkteams request was truncated, the response includes a NextToken. To retrieve the next set of labeling jobs, use the token in the next request. max_results: The maximum number of work teams to return in each page of the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed SubscribedWorkteam resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28049,58 +27728,56 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "NameContains": name_contains, + 'NameContains': name_contains, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_subscribed_workteams", - summaries_key="SubscribedWorkteams", - summary_name="SubscribedWorkteam", + list_method='list_subscribed_workteams', + summaries_key='SubscribedWorkteams', + summary_name='SubscribedWorkteam', resource_cls=SubscribedWorkteam, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Tag(Base): """ Class representing resource Tag - + Attributes: key: The tag key. Tag keys must be unique per resource. value: The tag value. - + """ - key: str value: str - + def get_name(self) -> str: attributes = vars(self) - resource_name = "tag_name" - resource_name_split = resource_name.split("_") + resource_name = 'tag_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object tag") return None - + @classmethod @Base.add_validate_call def get_all( @@ -28111,19 +27788,19 @@ def get_all( ) -> ResourceIterator["Tag"]: """ Get all Tag resources - + Parameters: resource_arn: The Amazon Resource Name (ARN) of the resource whose tags you want to retrieve. - next_token: If the response to the previous ListTags request is truncated, SageMaker returns this token. To retrieve the next set of tags, use it in the subsequent request. + next_token: If the response to the previous ListTags request is truncated, SageMaker returns this token. To retrieve the next set of tags, use it in the subsequent request. max_results: Maximum number of tags to return. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Tag resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28133,48 +27810,46 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "ResourceArn": resource_arn, + 'ResourceArn': resource_arn, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_tags", - summaries_key="Tags", - summary_name="Tag", + list_method='list_tags', + summaries_key='Tags', + summary_name='Tag', resource_cls=Tag, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + @classmethod @Base.add_validate_call def add_tags( cls, resource_arn: str, - tags: List[shapes.Tag], - session: Optional[Session] = None, + tags: List[shapes.Tag], session: Optional[Session] = None, region: Optional[str] = None, ) -> None: """ Adds or overwrites one or more tags for the specified SageMaker resource. - + Parameters: resource_arn: The Amazon Resource Name (ARN) of the resource that you want to tag. tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28184,43 +27859,42 @@ def add_tags( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "ResourceArn": resource_arn, - "Tags": tags, + 'ResourceArn': resource_arn, + 'Tags': tags, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling add_tags API") response = client.add_tags(**operation_input_args) logger.debug(f"Response: {response}") - + + @classmethod @Base.add_validate_call def delete_tags( cls, resource_arn: str, - tag_keys: List[str], - session: Optional[Session] = None, + tag_keys: List[str], session: Optional[Session] = None, region: Optional[str] = None, ) -> None: """ Deletes the specified tags from an SageMaker resource. - + Parameters: resource_arn: The Amazon Resource Name (ARN) of the resource whose tags you want to delete. tag_keys: An array or one or more tag keys to delete. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28230,46 +27904,46 @@ def delete_tags( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "ResourceArn": resource_arn, - "TagKeys": tag_keys, + 'ResourceArn': resource_arn, + 'TagKeys': tag_keys, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling delete_tags API") response = client.delete_tags(**operation_input_args) logger.debug(f"Response: {response}") + class TrainingJob(Base): """ Class representing resource TrainingJob - + Attributes: - training_job_name: Name of the model training job. + training_job_name: Name of the model training job. training_job_arn: The Amazon Resource Name (ARN) of the training job. - model_artifacts: Information about the Amazon S3 location that is configured for storing model artifacts. - training_job_status: The status of the training job. SageMaker provides the following training job statuses: InProgress - The training is in progress. Completed - The training job has completed. Failed - The training job has failed. To see the reason for the failure, see the FailureReason field in the response to a DescribeTrainingJobResponse call. Stopping - The training job is stopping. Stopped - The training job has stopped. For more detailed information, see SecondaryStatus. - secondary_status: Provides detailed information about the state of the training job. For detailed information on the secondary status of the training job, see StatusMessage under SecondaryStatusTransition. SageMaker provides primary statuses and secondary statuses that apply to each of them: InProgress Starting - Starting the training job. Downloading - An optional stage for algorithms that support File training input mode. It indicates that data is being downloaded to the ML storage volumes. Training - Training is in progress. Interrupted - The job stopped because the managed spot training instances were interrupted. Uploading - Training is complete and the model artifacts are being uploaded to the S3 location. Completed Completed - The training job has completed. Failed Failed - The training job has failed. The reason for the failure is returned in the FailureReason field of DescribeTrainingJobResponse. Stopped MaxRuntimeExceeded - The job stopped because it exceeded the maximum allowed runtime. MaxWaitTimeExceeded - The job stopped because it exceeded the maximum allowed wait time. Stopped - The training job has stopped. Stopping Stopping - Stopping the training job. Valid values for SecondaryStatus are subject to change. We no longer support the following secondary statuses: LaunchingMLInstances PreparingTraining DownloadingTrainingImage - algorithm_specification: Information about the algorithm used for training, and algorithm metadata. - resource_config: Resources, including ML compute instances and ML storage volumes, that are configured for model training. - stopping_condition: Specifies a limit to how long a model training job can run. It also specifies how long a managed Spot training job has to complete. When the job reaches the time limit, SageMaker ends the training job. Use this API to cap model training costs. To stop a job, SageMaker sends the algorithm the SIGTERM signal, which delays job termination for 120 seconds. Algorithms can use this 120-second window to save the model artifacts, so the results of training are not lost. + model_artifacts: Information about the Amazon S3 location that is configured for storing model artifacts. + training_job_status: The status of the training job. SageMaker provides the following training job statuses: InProgress - The training is in progress. Completed - The training job has completed. Failed - The training job has failed. To see the reason for the failure, see the FailureReason field in the response to a DescribeTrainingJobResponse call. Stopping - The training job is stopping. Stopped - The training job has stopped. For more detailed information, see SecondaryStatus. + secondary_status: Provides detailed information about the state of the training job. For detailed information on the secondary status of the training job, see StatusMessage under SecondaryStatusTransition. SageMaker provides primary statuses and secondary statuses that apply to each of them: InProgress Starting - Starting the training job. Downloading - An optional stage for algorithms that support File training input mode. It indicates that data is being downloaded to the ML storage volumes. Training - Training is in progress. Interrupted - The job stopped because the managed spot training instances were interrupted. Uploading - Training is complete and the model artifacts are being uploaded to the S3 location. Completed Completed - The training job has completed. Failed Failed - The training job has failed. The reason for the failure is returned in the FailureReason field of DescribeTrainingJobResponse. Stopped MaxRuntimeExceeded - The job stopped because it exceeded the maximum allowed runtime. MaxWaitTimeExceeded - The job stopped because it exceeded the maximum allowed wait time. Stopped - The training job has stopped. Stopping Stopping - Stopping the training job. Valid values for SecondaryStatus are subject to change. We no longer support the following secondary statuses: LaunchingMLInstances PreparingTraining DownloadingTrainingImage + algorithm_specification: Information about the algorithm used for training, and algorithm metadata. + resource_config: Resources, including ML compute instances and ML storage volumes, that are configured for model training. + stopping_condition: Specifies a limit to how long a model training job can run. It also specifies how long a managed Spot training job has to complete. When the job reaches the time limit, SageMaker ends the training job. Use this API to cap model training costs. To stop a job, SageMaker sends the algorithm the SIGTERM signal, which delays job termination for 120 seconds. Algorithms can use this 120-second window to save the model artifacts, so the results of training are not lost. creation_time: A timestamp that indicates when the training job was created. tuning_job_arn: The Amazon Resource Name (ARN) of the associated hyperparameter tuning job if the training job was launched by a hyperparameter tuning job. labeling_job_arn: The Amazon Resource Name (ARN) of the SageMaker Ground Truth labeling job that created the transform or training job. auto_ml_job_arn: The Amazon Resource Name (ARN) of an AutoML job. - failure_reason: If the training job failed, the reason it failed. - hyper_parameters: Algorithm-specific parameters. - role_arn: The Amazon Web Services Identity and Access Management (IAM) role configured for the training job. - input_data_config: An array of Channel objects that describes each data input channel. - output_data_config: The S3 path where model artifacts that you configured when creating the job are stored. SageMaker creates subfolders for model artifacts. + failure_reason: If the training job failed, the reason it failed. + hyper_parameters: Algorithm-specific parameters. + role_arn: The Amazon Web Services Identity and Access Management (IAM) role configured for the training job. + input_data_config: An array of Channel objects that describes each data input channel. + output_data_config: The S3 path where model artifacts that you configured when creating the job are stored. SageMaker creates subfolders for model artifacts. warm_pool_status: The status of the warm pool associated with the training job. vpc_config: A VpcConfig object that specifies the VPC that this training job has access to. For more information, see Protect Training Jobs by Using an Amazon Virtual Private Cloud. training_start_time: Indicates the time when the training job starts on training instances. You are billed for the time interval between this time and the value of TrainingEndTime. The start time in CloudWatch Logs might be later than this time. The difference is due to the time it takes to download the training data and to the size of the training container. @@ -28280,25 +27954,24 @@ class TrainingJob(Base): enable_network_isolation: If you want to allow inbound or outbound network calls, except for calls between peers within a training cluster for distributed training, choose True. If you enable network isolation for training jobs that are configured to use a VPC, SageMaker downloads and uploads customer data and model artifacts through the specified VPC, but the training container does not have network access. enable_inter_container_traffic_encryption: To encrypt all communications between ML compute instances in distributed training, choose True. Encryption provides greater security for distributed training, but training might take longer. How long it takes depends on the amount of communication between compute instances, especially if you use a deep learning algorithms in distributed training. enable_managed_spot_training: A Boolean indicating whether managed spot training is enabled (True) or not (False). - checkpoint_config: + checkpoint_config: training_time_in_seconds: The training time in seconds. billable_time_in_seconds: The billable time in seconds. Billable time refers to the absolute wall-clock time. Multiply BillableTimeInSeconds by the number of instances (InstanceCount) in your training cluster to get the total compute time SageMaker bills you if you run distributed training. The formula is as follows: BillableTimeInSeconds \* InstanceCount . You can calculate the savings from using managed spot training using the formula (1 - BillableTimeInSeconds / TrainingTimeInSeconds) \* 100. For example, if BillableTimeInSeconds is 100 and TrainingTimeInSeconds is 500, the savings is 80%. - debug_hook_config: - experiment_config: + debug_hook_config: + experiment_config: debug_rule_configurations: Configuration information for Amazon SageMaker Debugger rules for debugging output tensors. - tensor_board_output_config: + tensor_board_output_config: debug_rule_evaluation_statuses: Evaluation status of Amazon SageMaker Debugger rules for debugging on a training job. - profiler_config: + profiler_config: profiler_rule_configurations: Configuration information for Amazon SageMaker Debugger rules for profiling system and framework metrics. profiler_rule_evaluation_statuses: Evaluation status of Amazon SageMaker Debugger rules for profiling on a training job. profiling_status: Profiling status of a training job. - environment: The environment variables to set in the Docker container. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any environment fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request environment variable or plain text fields. + environment: The environment variables to set in the Docker container. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any environment fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request environment variable or plain text fields. retry_strategy: The number of times to retry the job when the job fails due to an InternalServerError. remote_debug_config: Configuration for remote debugging. To learn more about the remote debugging functionality of SageMaker, see Access a training container through Amazon Web Services Systems Manager (SSM) for remote debugging. infra_check_config: Contains information about the infrastructure health check configuration for the training job. - + """ - training_job_name: str training_job_arn: Optional[str] = Unassigned() tuning_job_arn: Optional[str] = Unassigned() @@ -28336,60 +28009,94 @@ class TrainingJob(Base): debug_rule_evaluation_statuses: Optional[List[shapes.DebugRuleEvaluationStatus]] = Unassigned() profiler_config: Optional[shapes.ProfilerConfig] = Unassigned() profiler_rule_configurations: Optional[List[shapes.ProfilerRuleConfiguration]] = Unassigned() - profiler_rule_evaluation_statuses: Optional[List[shapes.ProfilerRuleEvaluationStatus]] = ( - Unassigned() - ) + profiler_rule_evaluation_statuses: Optional[List[shapes.ProfilerRuleEvaluationStatus]] = Unassigned() profiling_status: Optional[str] = Unassigned() environment: Optional[Dict[str, str]] = Unassigned() retry_strategy: Optional[shapes.RetryStrategy] = Unassigned() remote_debug_config: Optional[shapes.RemoteDebugConfig] = Unassigned() infra_check_config: Optional[shapes.InfraCheckConfig] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "training_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'training_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object training_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "model_artifacts": {"s3_model_artifacts": {"type": "string"}}, - "resource_config": {"volume_kms_key_id": {"type": "string"}}, - "role_arn": {"type": "string"}, - "output_data_config": { - "s3_output_path": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - }, - "checkpoint_config": {"s3_uri": {"type": "string"}}, - "debug_hook_config": {"s3_output_path": {"type": "string"}}, - "tensor_board_output_config": {"s3_output_path": {"type": "string"}}, - "profiler_config": {"s3_output_path": {"type": "string"}}, + config_schema_for_resource = \ + { + "model_artifacts": { + "s3_model_artifacts": { + "type": "string" } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "TrainingJob", **kwargs - ), - ) - + }, + "resource_config": { + "volume_kms_key_id": { + "type": "string" + } + }, + "role_arn": { + "type": "string" + }, + "output_data_config": { + "s3_output_path": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + }, + "vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" + } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "checkpoint_config": { + "s3_uri": { + "type": "string" + } + }, + "debug_hook_config": { + "s3_output_path": { + "type": "string" + } + }, + "tensor_board_output_config": { + "s3_output_path": { + "type": "string" + } + }, + "profiler_config": { + "s3_output_path": { + "type": "string" + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "TrainingJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -28414,9 +28121,7 @@ def create( tensor_board_output_config: Optional[shapes.TensorBoardOutputConfig] = Unassigned(), experiment_config: Optional[shapes.ExperimentConfig] = Unassigned(), profiler_config: Optional[shapes.ProfilerConfig] = Unassigned(), - profiler_rule_configurations: Optional[ - List[shapes.ProfilerRuleConfiguration] - ] = Unassigned(), + profiler_rule_configurations: Optional[List[shapes.ProfilerRuleConfiguration]] = Unassigned(), environment: Optional[Dict[str, str]] = Unassigned(), retry_strategy: Optional[shapes.RetryStrategy] = Unassigned(), remote_debug_config: Optional[shapes.RemoteDebugConfig] = Unassigned(), @@ -28427,41 +28132,41 @@ def create( ) -> Optional["TrainingJob"]: """ Create a TrainingJob resource - + Parameters: - training_job_name: The name of the training job. The name must be unique within an Amazon Web Services Region in an Amazon Web Services account. - algorithm_specification: The registry path of the Docker image that contains the training algorithm and algorithm-specific metadata, including the input mode. For more information about algorithms provided by SageMaker, see Algorithms. For information about providing your own algorithms, see Using Your Own Algorithms with Amazon SageMaker. - role_arn: The Amazon Resource Name (ARN) of an IAM role that SageMaker can assume to perform tasks on your behalf. During model training, SageMaker needs your permission to read input data from an S3 bucket, download a Docker image that contains training code, write model artifacts to an S3 bucket, write logs to Amazon CloudWatch Logs, and publish metrics to Amazon CloudWatch. You grant permissions for all of these tasks to an IAM role. For more information, see SageMaker Roles. To be able to pass this role to SageMaker, the caller of this API must have the iam:PassRole permission. - output_data_config: Specifies the path to the S3 location where you want to store model artifacts. SageMaker creates subfolders for the artifacts. + training_job_name: The name of the training job. The name must be unique within an Amazon Web Services Region in an Amazon Web Services account. + algorithm_specification: The registry path of the Docker image that contains the training algorithm and algorithm-specific metadata, including the input mode. For more information about algorithms provided by SageMaker, see Algorithms. For information about providing your own algorithms, see Using Your Own Algorithms with Amazon SageMaker. + role_arn: The Amazon Resource Name (ARN) of an IAM role that SageMaker can assume to perform tasks on your behalf. During model training, SageMaker needs your permission to read input data from an S3 bucket, download a Docker image that contains training code, write model artifacts to an S3 bucket, write logs to Amazon CloudWatch Logs, and publish metrics to Amazon CloudWatch. You grant permissions for all of these tasks to an IAM role. For more information, see SageMaker Roles. To be able to pass this role to SageMaker, the caller of this API must have the iam:PassRole permission. + output_data_config: Specifies the path to the S3 location where you want to store model artifacts. SageMaker creates subfolders for the artifacts. resource_config: The resources, including the ML compute instances and ML storage volumes, to use for model training. ML storage volumes store model artifacts and incremental states. Training algorithms might also use ML storage volumes for scratch space. If you want SageMaker to use the ML storage volume to store the training data, choose File as the TrainingInputMode in the algorithm specification. For distributed training algorithms, specify an instance count greater than 1. - stopping_condition: Specifies a limit to how long a model training job can run. It also specifies how long a managed Spot training job has to complete. When the job reaches the time limit, SageMaker ends the training job. Use this API to cap model training costs. To stop a job, SageMaker sends the algorithm the SIGTERM signal, which delays job termination for 120 seconds. Algorithms can use this 120-second window to save the model artifacts, so the results of training are not lost. - hyper_parameters: Algorithm-specific parameters that influence the quality of the model. You set hyperparameters before you start the learning process. For a list of hyperparameters for each training algorithm provided by SageMaker, see Algorithms. You can specify a maximum of 100 hyperparameters. Each hyperparameter is a key-value pair. Each key and value is limited to 256 characters, as specified by the Length Constraint. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any hyperparameter fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by any security-sensitive information included in the request hyperparameter variable or plain text fields. + stopping_condition: Specifies a limit to how long a model training job can run. It also specifies how long a managed Spot training job has to complete. When the job reaches the time limit, SageMaker ends the training job. Use this API to cap model training costs. To stop a job, SageMaker sends the algorithm the SIGTERM signal, which delays job termination for 120 seconds. Algorithms can use this 120-second window to save the model artifacts, so the results of training are not lost. + hyper_parameters: Algorithm-specific parameters that influence the quality of the model. You set hyperparameters before you start the learning process. For a list of hyperparameters for each training algorithm provided by SageMaker, see Algorithms. You can specify a maximum of 100 hyperparameters. Each hyperparameter is a key-value pair. Each key and value is limited to 256 characters, as specified by the Length Constraint. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any hyperparameter fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by any security-sensitive information included in the request hyperparameter variable or plain text fields. input_data_config: An array of Channel objects. Each channel is a named input source. InputDataConfig describes the input data and its location. Algorithms can accept input data from one or more channels. For example, an algorithm might have two channels of input data, training_data and validation_data. The configuration for each channel provides the S3, EFS, or FSx location where the input data is stored. It also provides information about the stored data: the MIME type, compression method, and whether the data is wrapped in RecordIO format. Depending on the input mode that the algorithm supports, SageMaker either copies input data files from an S3 bucket to a local directory in the Docker container, or makes it available as input streams. For example, if you specify an EFS location, input data files are available as input streams. They do not need to be downloaded. Your input must be in the same Amazon Web Services region as your training job. vpc_config: A VpcConfig object that specifies the VPC that you want your training job to connect to. Control access to and from your training container by configuring the VPC. For more information, see Protect Training Jobs by Using an Amazon Virtual Private Cloud. - tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any tags. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by any security-sensitive information included in the request tag variable or plain text fields. + tags: An array of key-value pairs. You can use tags to categorize your Amazon Web Services resources in different ways, for example, by purpose, owner, or environment. For more information, see Tagging Amazon Web Services Resources. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any tags. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by any security-sensitive information included in the request tag variable or plain text fields. enable_network_isolation: Isolates the training container. No inbound or outbound network calls can be made, except for calls between peers within a training cluster for distributed training. If you enable network isolation for training jobs that are configured to use a VPC, SageMaker downloads and uploads customer data and model artifacts through the specified VPC, but the training container does not have network access. enable_inter_container_traffic_encryption: To encrypt all communications between ML compute instances in distributed training, choose True. Encryption provides greater security for distributed training, but training might take longer. How long it takes depends on the amount of communication between compute instances, especially if you use a deep learning algorithm in distributed training. For more information, see Protect Communications Between ML Compute Instances in a Distributed Training Job. - enable_managed_spot_training: To train models using managed spot training, choose True. Managed spot training provides a fully managed and scalable infrastructure for training machine learning models. this option is useful when training jobs can be interrupted and when there is flexibility when the training job is run. The complete and intermediate results of jobs are stored in an Amazon S3 bucket, and can be used as a starting point to train models incrementally. Amazon SageMaker provides metrics and logs in CloudWatch. They can be used to see when managed spot training jobs are running, interrupted, resumed, or completed. + enable_managed_spot_training: To train models using managed spot training, choose True. Managed spot training provides a fully managed and scalable infrastructure for training machine learning models. this option is useful when training jobs can be interrupted and when there is flexibility when the training job is run. The complete and intermediate results of jobs are stored in an Amazon S3 bucket, and can be used as a starting point to train models incrementally. Amazon SageMaker provides metrics and logs in CloudWatch. They can be used to see when managed spot training jobs are running, interrupted, resumed, or completed. checkpoint_config: Contains information about the output location for managed spot training checkpoint data. - debug_hook_config: + debug_hook_config: debug_rule_configurations: Configuration information for Amazon SageMaker Debugger rules for debugging output tensors. - tensor_board_output_config: - experiment_config: - profiler_config: + tensor_board_output_config: + experiment_config: + profiler_config: profiler_rule_configurations: Configuration information for Amazon SageMaker Debugger rules for profiling system and framework metrics. - environment: The environment variables to set in the Docker container. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any environment fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request environment variable or plain text fields. + environment: The environment variables to set in the Docker container. Do not include any security-sensitive information including account access IDs, secrets, or tokens in any environment fields. As part of the shared responsibility model, you are responsible for any potential exposure, unauthorized access, or compromise of your sensitive data if caused by security-sensitive information included in the request environment variable or plain text fields. retry_strategy: The number of times to retry the job when the job fails due to an InternalServerError. remote_debug_config: Configuration for remote debugging. To learn more about the remote debugging functionality of SageMaker, see Access a training container through Amazon Web Services Systems Manager (SSM) for remote debugging. infra_check_config: Contains information about the infrastructure health check configuration for the training job. session_chaining_config: Contains information about attribute-based access control (ABAC) for the training job. session: Boto3 session. region: Region name. - + Returns: The TrainingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28477,55 +28182,51 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating training_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "TrainingJobName": training_job_name, - "HyperParameters": hyper_parameters, - "AlgorithmSpecification": algorithm_specification, - "RoleArn": role_arn, - "InputDataConfig": input_data_config, - "OutputDataConfig": output_data_config, - "ResourceConfig": resource_config, - "VpcConfig": vpc_config, - "StoppingCondition": stopping_condition, - "Tags": tags, - "EnableNetworkIsolation": enable_network_isolation, - "EnableInterContainerTrafficEncryption": enable_inter_container_traffic_encryption, - "EnableManagedSpotTraining": enable_managed_spot_training, - "CheckpointConfig": checkpoint_config, - "DebugHookConfig": debug_hook_config, - "DebugRuleConfigurations": debug_rule_configurations, - "TensorBoardOutputConfig": tensor_board_output_config, - "ExperimentConfig": experiment_config, - "ProfilerConfig": profiler_config, - "ProfilerRuleConfigurations": profiler_rule_configurations, - "Environment": environment, - "RetryStrategy": retry_strategy, - "RemoteDebugConfig": remote_debug_config, - "InfraCheckConfig": infra_check_config, - "SessionChainingConfig": session_chaining_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="TrainingJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'TrainingJobName': training_job_name, + 'HyperParameters': hyper_parameters, + 'AlgorithmSpecification': algorithm_specification, + 'RoleArn': role_arn, + 'InputDataConfig': input_data_config, + 'OutputDataConfig': output_data_config, + 'ResourceConfig': resource_config, + 'VpcConfig': vpc_config, + 'StoppingCondition': stopping_condition, + 'Tags': tags, + 'EnableNetworkIsolation': enable_network_isolation, + 'EnableInterContainerTrafficEncryption': enable_inter_container_traffic_encryption, + 'EnableManagedSpotTraining': enable_managed_spot_training, + 'CheckpointConfig': checkpoint_config, + 'DebugHookConfig': debug_hook_config, + 'DebugRuleConfigurations': debug_rule_configurations, + 'TensorBoardOutputConfig': tensor_board_output_config, + 'ExperimentConfig': experiment_config, + 'ProfilerConfig': profiler_config, + 'ProfilerRuleConfigurations': profiler_rule_configurations, + 'Environment': environment, + 'RetryStrategy': retry_strategy, + 'RemoteDebugConfig': remote_debug_config, + 'InfraCheckConfig': infra_check_config, + 'SessionChainingConfig': session_chaining_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='TrainingJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_training_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(training_job_name=training_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -28536,17 +28237,17 @@ def get( ) -> Optional["TrainingJob"]: """ Get a TrainingJob resource - + Parameters: training_job_name: The name of the training job. session: Boto3 session. region: Region name. - + Returns: The TrainingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28557,38 +28258,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrainingJobName": training_job_name, + 'TrainingJobName': training_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_training_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeTrainingJobResponse") + transformed_response = transform(response, 'DescribeTrainingJobResponse') training_job = cls(**transformed_response) return training_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["TrainingJob"]: + + ) -> Optional["TrainingJob"]: """ Refresh a TrainingJob resource - + Returns: The TrainingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28599,40 +28299,38 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrainingJobName": self.training_job_name, + 'TrainingJobName': self.training_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_training_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeTrainingJobResponse", self) + transform(response, 'DescribeTrainingJobResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( self, profiler_config: Optional[shapes.ProfilerConfigForUpdate] = Unassigned(), - profiler_rule_configurations: Optional[ - List[shapes.ProfilerRuleConfiguration] - ] = Unassigned(), + profiler_rule_configurations: Optional[List[shapes.ProfilerRuleConfiguration]] = Unassigned(), resource_config: Optional[shapes.ResourceConfigForUpdate] = Unassigned(), remote_debug_config: Optional[shapes.RemoteDebugConfigForUpdate] = Unassigned(), ) -> Optional["TrainingJob"]: """ Update a TrainingJob resource - + Returns: The TrainingJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28644,36 +28342,36 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating training_job resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "TrainingJobName": self.training_job_name, - "ProfilerConfig": profiler_config, - "ProfilerRuleConfigurations": profiler_rule_configurations, - "ResourceConfig": resource_config, - "RemoteDebugConfig": remote_debug_config, + 'TrainingJobName': self.training_job_name, + 'ProfilerConfig': profiler_config, + 'ProfilerRuleConfigurations': profiler_rule_configurations, + 'ResourceConfig': resource_config, + 'RemoteDebugConfig': remote_debug_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_training_job(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a TrainingJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28684,20 +28382,20 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "TrainingJobName": self.training_job_name, + 'TrainingJobName': self.training_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_training_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, @@ -28707,80 +28405,73 @@ def wait( ) -> None: """ Wait for a TrainingJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. logs: Whether to print logs while waiting. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed", "Stopped"] + terminal_states = ['Completed', 'Failed', 'Stopped'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for TrainingJob...") status = Status("Current status:") - + instance_count = ( - sum( - instance_group.instance_count - for instance_group in self.resource_config.instance_groups - ) - if self.resource_config.instance_groups - and not isinstance(self.resource_config.instance_groups, Unassigned) - else self.resource_config.instance_count - ) - + sum(instance_group.instance_count for instance_group in self.resource_config.instance_groups) + if self.resource_config.instance_groups and not isinstance(self.resource_config.instance_groups, Unassigned) + else self.resource_config.instance_count + ) + if logs: multi_stream_logger = MultiLogStreamHandler( log_group_name=f"/aws/sagemaker/TrainingJobs", log_stream_name_prefix=self.get_name(), - expected_stream_count=instance_count, + expected_stream_count=instance_count ) - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.training_job_status status.update(f"Current status: [bold]{current_status}") - + if logs and multi_stream_logger.ready(): stream_log_events = multi_stream_logger.get_latest_log_events() for stream_id, event in stream_log_events: logger.info(f"{stream_id}:\n{event['message']}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="TrainingJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="TrainingJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="TrainingJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -28800,9 +28491,9 @@ def get_all( ) -> ResourceIterator["TrainingJob"]: """ Get all TrainingJob resources - + Parameters: - next_token: If the result of the previous ListTrainingJobs request was truncated, the response includes a NextToken. To retrieve the next set of training jobs, use the token in the next request. + next_token: If the result of the previous ListTrainingJobs request was truncated, the response includes a NextToken. To retrieve the next set of training jobs, use the token in the next request. max_results: The maximum number of training jobs to return in the response. creation_time_after: A filter that returns only training jobs created after the specified time (timestamp). creation_time_before: A filter that returns only training jobs created before the specified time (timestamp). @@ -28816,12 +28507,12 @@ def get_all( training_plan_arn_equals: The Amazon Resource Name (ARN); of the training plan to filter training jobs by. For more information about reserving GPU capacity for your SageMaker training jobs using Amazon SageMaker Training Plan, see CreateTrainingPlan . session: Boto3 session. region: Region name. - + Returns: Iterator for listed TrainingJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28831,42 +28522,41 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, - "WarmPoolStatusEquals": warm_pool_status_equals, - "TrainingPlanArnEquals": training_plan_arn_equals, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'WarmPoolStatusEquals': warm_pool_status_equals, + 'TrainingPlanArnEquals': training_plan_arn_equals, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_training_jobs", - summaries_key="TrainingJobSummaries", - summary_name="TrainingJobSummary", + list_method='list_training_jobs', + summaries_key='TrainingJobSummaries', + summary_name='TrainingJobSummary', resource_cls=TrainingJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class TrainingPlan(Base): """ Class representing resource TrainingPlan - + Attributes: training_plan_arn: The Amazon Resource Name (ARN); of the training plan. training_plan_name: The name of the training plan. @@ -28881,11 +28571,10 @@ class TrainingPlan(Base): total_instance_count: The total number of instances reserved in this training plan. available_instance_count: The number of instances currently available for use in this training plan. in_use_instance_count: The number of instances currently in use from this training plan. - target_resources: The target resources (e.g., SageMaker Training Jobs, SageMaker HyperPod) that can use this training plan. Training plans are specific to their target resource. A training plan designed for SageMaker training jobs can only be used to schedule and run training jobs. A training plan for HyperPod clusters can be used exclusively to provide compute resources to a cluster's instance group. - reserved_capacity_summaries: The list of Reserved Capacity providing the underlying compute resources of the plan. - + target_resources: The target resources (e.g., SageMaker Training Jobs, SageMaker HyperPod) that can use this training plan. Training plans are specific to their target resource. A training plan designed for SageMaker training jobs can only be used to schedule and run training jobs. A training plan for HyperPod clusters can be used exclusively to provide compute resources to a cluster's instance group. + reserved_capacity_summaries: The list of Reserved Capacity providing the underlying compute resources of the plan. + """ - training_plan_name: str training_plan_arn: Optional[str] = Unassigned() status: Optional[str] = Unassigned() @@ -28901,23 +28590,23 @@ class TrainingPlan(Base): in_use_instance_count: Optional[int] = Unassigned() target_resources: Optional[List[str]] = Unassigned() reserved_capacity_summaries: Optional[List[shapes.ReservedCapacitySummary]] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "training_plan_name" - resource_name_split = resource_name.split("_") + resource_name = 'training_plan_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object training_plan") return None - + @classmethod @Base.add_validate_call def create( @@ -28930,19 +28619,19 @@ def create( ) -> Optional["TrainingPlan"]: """ Create a TrainingPlan resource - + Parameters: training_plan_name: The name of the training plan to create. training_plan_offering_id: The unique identifier of the training plan offering to use for creating this plan. tags: An array of key-value pairs to apply to this training plan. session: Boto3 session. region: Region name. - + Returns: The TrainingPlan resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -28958,33 +28647,29 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating training_plan resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + operation_input_args = { - "TrainingPlanName": training_plan_name, - "TrainingPlanOfferingId": training_plan_offering_id, - "Tags": tags, + 'TrainingPlanName': training_plan_name, + 'TrainingPlanOfferingId': training_plan_offering_id, + 'Tags': tags, } - - operation_input_args = Base.populate_chained_attributes( - resource_name="TrainingPlan", operation_input_args=operation_input_args - ) - + + operation_input_args = Base.populate_chained_attributes(resource_name='TrainingPlan', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_training_plan(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(training_plan_name=training_plan_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -28995,17 +28680,17 @@ def get( ) -> Optional["TrainingPlan"]: """ Get a TrainingPlan resource - + Parameters: training_plan_name: The name of the training plan to describe. session: Boto3 session. region: Region name. - + Returns: The TrainingPlan resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29016,38 +28701,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrainingPlanName": training_plan_name, + 'TrainingPlanName': training_plan_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_training_plan(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeTrainingPlanResponse") + transformed_response = transform(response, 'DescribeTrainingPlanResponse') training_plan = cls(**transformed_response) return training_plan - + @Base.add_validate_call def refresh( self, - ) -> Optional["TrainingPlan"]: + + ) -> Optional["TrainingPlan"]: """ Refresh a TrainingPlan resource - + Returns: The TrainingPlan resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29058,79 +28742,75 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrainingPlanName": self.training_plan_name, + 'TrainingPlanName': self.training_plan_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_training_plan(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeTrainingPlanResponse", self) + transform(response, 'DescribeTrainingPlanResponse', self) return self - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Pending", "Active", "Scheduled", "Expired", "Failed"], + target_status: Literal['Pending', 'Active', 'Scheduled', 'Expired', 'Failed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a TrainingPlan resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for TrainingPlan to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="TrainingPlan", - status=current_status, - reason=self.status_message, - ) - + raise FailedStatusError(resource_type="TrainingPlan", status=current_status, reason=self.status_message) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="TrainingPlan", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -29145,7 +28825,7 @@ def get_all( ) -> ResourceIterator["TrainingPlan"]: """ Get all TrainingPlan resources - + Parameters: next_token: A token to continue pagination if more results are available. max_results: The maximum number of results to return in the response. @@ -29156,12 +28836,12 @@ def get_all( filters: Additional filters to apply to the list of training plans. session: Boto3 session. region: Region name. - + Returns: Iterator for listed TrainingPlan resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29171,37 +28851,36 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "StartTimeAfter": start_time_after, - "StartTimeBefore": start_time_before, - "SortBy": sort_by, - "SortOrder": sort_order, - "Filters": filters, + 'StartTimeAfter': start_time_after, + 'StartTimeBefore': start_time_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'Filters': filters, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_training_plans", - summaries_key="TrainingPlanSummaries", - summary_name="TrainingPlanSummary", + list_method='list_training_plans', + summaries_key='TrainingPlanSummaries', + summary_name='TrainingPlanSummary', resource_cls=TrainingPlan, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class TransformJob(Base): """ Class representing resource TransformJob - + Attributes: transform_job_name: The name of the transform job. transform_job_arn: The Amazon Resource Name (ARN) of the transform job. @@ -29222,11 +28901,10 @@ class TransformJob(Base): transform_end_time: Indicates when the transform job has been completed, or has stopped or failed. You are billed for the time interval between this time and the value of TransformStartTime. labeling_job_arn: The Amazon Resource Name (ARN) of the Amazon SageMaker Ground Truth labeling job that created the transform or training job. auto_ml_job_arn: The Amazon Resource Name (ARN) of the AutoML transform job. - data_processing: - experiment_config: - + data_processing: + experiment_config: + """ - transform_job_name: str transform_job_arn: Optional[str] = Unassigned() transform_job_status: Optional[str] = Unassigned() @@ -29248,54 +28926,66 @@ class TransformJob(Base): auto_ml_job_arn: Optional[str] = Unassigned() data_processing: Optional[shapes.DataProcessing] = Unassigned() experiment_config: Optional[shapes.ExperimentConfig] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "transform_job_name" - resource_name_split = resource_name.split("_") + resource_name = 'transform_job_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object transform_job") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "transform_input": { - "data_source": { - "s3_data_source": { - "s3_data_type": {"type": "string"}, - "s3_uri": {"type": "string"}, - } - } - }, - "transform_resources": {"volume_kms_key_id": {"type": "string"}}, - "transform_output": { - "s3_output_path": {"type": "string"}, - "kms_key_id": {"type": "string"}, - }, - "data_capture_config": { - "destination_s3_uri": {"type": "string"}, - "kms_key_id": {"type": "string"}, + config_schema_for_resource = \ + { + "transform_input": { + "data_source": { + "s3_data_source": { + "s3_data_type": { + "type": "string" }, + "s3_uri": { + "type": "string" + } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "TransformJob", **kwargs - ), - ) - + }, + "transform_resources": { + "volume_kms_key_id": { + "type": "string" + } + }, + "transform_output": { + "s3_output_path": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + }, + "data_capture_config": { + "destination_s3_uri": { + "type": "string" + }, + "kms_key_id": { + "type": "string" + } + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "TransformJob", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -29320,9 +29010,9 @@ def create( ) -> Optional["TransformJob"]: """ Create a TransformJob resource - + Parameters: - transform_job_name: The name of the transform job. The name must be unique within an Amazon Web Services Region in an Amazon Web Services account. + transform_job_name: The name of the transform job. The name must be unique within an Amazon Web Services Region in an Amazon Web Services account. model_name: The name of the model that you want to use for the transform job. ModelName must be the name of an existing Amazon SageMaker model within an Amazon Web Services Region in an Amazon Web Services account. transform_input: Describes the input source and the way the transform job consumes it. transform_output: Describes the results of the transform job. @@ -29335,15 +29025,15 @@ def create( data_capture_config: Configuration to control how SageMaker captures inference data. data_processing: The data structure used to specify the data to be used for inference in a batch transform job and to associate the data that is relevant to the prediction results in the output. The input filter provided allows you to exclude input data that is not needed for inference in a batch transform job. The output filter provided allows you to include input data relevant to interpreting the predictions in the output from the job. For more information, see Associate Prediction Results with their Corresponding Input Records. tags: (Optional) An array of key-value pairs. For more information, see Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. - experiment_config: + experiment_config: session: Boto3 session. region: Region name. - + Returns: The TransformJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29359,44 +29049,40 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating transform_job resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "TransformJobName": transform_job_name, - "ModelName": model_name, - "MaxConcurrentTransforms": max_concurrent_transforms, - "ModelClientConfig": model_client_config, - "MaxPayloadInMB": max_payload_in_mb, - "BatchStrategy": batch_strategy, - "Environment": environment, - "TransformInput": transform_input, - "TransformOutput": transform_output, - "DataCaptureConfig": data_capture_config, - "TransformResources": transform_resources, - "DataProcessing": data_processing, - "Tags": tags, - "ExperimentConfig": experiment_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="TransformJob", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'TransformJobName': transform_job_name, + 'ModelName': model_name, + 'MaxConcurrentTransforms': max_concurrent_transforms, + 'ModelClientConfig': model_client_config, + 'MaxPayloadInMB': max_payload_in_mb, + 'BatchStrategy': batch_strategy, + 'Environment': environment, + 'TransformInput': transform_input, + 'TransformOutput': transform_output, + 'DataCaptureConfig': data_capture_config, + 'TransformResources': transform_resources, + 'DataProcessing': data_processing, + 'Tags': tags, + 'ExperimentConfig': experiment_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='TransformJob', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_transform_job(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(transform_job_name=transform_job_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -29407,17 +29093,17 @@ def get( ) -> Optional["TransformJob"]: """ Get a TransformJob resource - + Parameters: transform_job_name: The name of the transform job that you want to view details of. session: Boto3 session. region: Region name. - + Returns: The TransformJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29428,38 +29114,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TransformJobName": transform_job_name, + 'TransformJobName': transform_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_transform_job(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeTransformJobResponse") + transformed_response = transform(response, 'DescribeTransformJobResponse') transform_job = cls(**transformed_response) return transform_job - + @Base.add_validate_call def refresh( self, - ) -> Optional["TransformJob"]: + + ) -> Optional["TransformJob"]: """ Refresh a TransformJob resource - + Returns: The TransformJob resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29470,28 +29155,28 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TransformJobName": self.transform_job_name, + 'TransformJobName': self.transform_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_transform_job(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeTransformJobResponse", self) + transform(response, 'DescribeTransformJobResponse', self) return self - + @Base.add_validate_call def stop(self) -> None: """ Stop a TransformJob resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29502,20 +29187,20 @@ def stop(self) -> None: ``` ResourceNotFound: Resource being access is not found. """ - + client = SageMakerClient().client - + operation_input_args = { - "TransformJobName": self.transform_job_name, + 'TransformJobName': self.transform_job_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.stop_transform_job(**operation_input_args) - + logger.info(f"Stopping {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait( self, @@ -29525,71 +29210,68 @@ def wait( ) -> None: """ Wait for a TransformJob resource. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. logs: Whether to print logs while waiting. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. - + """ - terminal_states = ["Completed", "Failed", "Stopped"] + terminal_states = ['Completed', 'Failed', 'Stopped'] start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for TransformJob...") status = Status("Current status:") - + instance_count = self.transform_resources.instance_count if logs: multi_stream_logger = MultiLogStreamHandler( log_group_name=f"/aws/sagemaker/TransformJobs", log_stream_name_prefix=self.get_name(), - expected_stream_count=instance_count, + expected_stream_count=instance_count ) - + + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.transform_job_status status.update(f"Current status: [bold]{current_status}") - + if logs and multi_stream_logger.ready(): stream_log_events = multi_stream_logger.get_latest_log_events() for stream_id, event in stream_log_events: logger.info(f"{stream_id}:\n{event['message']}") - + if current_status in terminal_states: logger.info(f"Final Resource Status: [bold]{current_status}") - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="TransformJob", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="TransformJob", status=current_status, reason=self.failure_reason) + return - + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="TransformJob", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -29607,7 +29289,7 @@ def get_all( ) -> ResourceIterator["TransformJob"]: """ Get all TransformJob resources - + Parameters: creation_time_after: A filter that returns only transform jobs created after the specified time. creation_time_before: A filter that returns only transform jobs created before the specified time. @@ -29621,12 +29303,12 @@ def get_all( max_results: The maximum number of transform jobs to return in the response. The default value is 10. session: Boto3 session. region: Region name. - + Returns: Iterator for listed TransformJob resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29636,40 +29318,39 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "LastModifiedTimeAfter": last_modified_time_after, - "LastModifiedTimeBefore": last_modified_time_before, - "NameContains": name_contains, - "StatusEquals": status_equals, - "SortBy": sort_by, - "SortOrder": sort_order, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'LastModifiedTimeAfter': last_modified_time_after, + 'LastModifiedTimeBefore': last_modified_time_before, + 'NameContains': name_contains, + 'StatusEquals': status_equals, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_transform_jobs", - summaries_key="TransformJobSummaries", - summary_name="TransformJobSummary", + list_method='list_transform_jobs', + summaries_key='TransformJobSummaries', + summary_name='TransformJobSummary', resource_cls=TransformJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Trial(Base): """ Class representing resource Trial - + Attributes: trial_name: The name of the trial. trial_arn: The Amazon Resource Name (ARN) of the trial. @@ -29680,10 +29361,9 @@ class Trial(Base): created_by: Who created the trial. last_modified_time: When the trial was last modified. last_modified_by: Who last modified the trial. - metadata_properties: - + metadata_properties: + """ - trial_name: str trial_arn: Optional[str] = Unassigned() display_name: Optional[str] = Unassigned() @@ -29694,23 +29374,23 @@ class Trial(Base): last_modified_time: Optional[datetime.datetime] = Unassigned() last_modified_by: Optional[shapes.UserContext] = Unassigned() metadata_properties: Optional[shapes.MetadataProperties] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "trial_name" - resource_name_split = resource_name.split("_") + resource_name = 'trial_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object trial") return None - + @classmethod @Base.add_validate_call def create( @@ -29725,21 +29405,21 @@ def create( ) -> Optional["Trial"]: """ Create a Trial resource - + Parameters: trial_name: The name of the trial. The name must be unique in your Amazon Web Services account and is not case-sensitive. experiment_name: The name of the experiment to associate the trial with. display_name: The name of the trial as displayed. The name doesn't need to be unique. If DisplayName isn't specified, TrialName is displayed. - metadata_properties: + metadata_properties: tags: A list of tags to associate with the trial. You can use Search API to search on the tags. session: Boto3 session. region: Region name. - + Returns: The Trial resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29754,35 +29434,31 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating trial resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "TrialName": trial_name, - "DisplayName": display_name, - "ExperimentName": experiment_name, - "MetadataProperties": metadata_properties, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Trial", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'TrialName': trial_name, + 'DisplayName': display_name, + 'ExperimentName': experiment_name, + 'MetadataProperties': metadata_properties, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Trial', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_trial(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(trial_name=trial_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -29793,17 +29469,17 @@ def get( ) -> Optional["Trial"]: """ Get a Trial resource - + Parameters: trial_name: The name of the trial to describe. session: Boto3 session. region: Region name. - + Returns: The Trial resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29814,38 +29490,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrialName": trial_name, + 'TrialName': trial_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_trial(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeTrialResponse") + transformed_response = transform(response, 'DescribeTrialResponse') trial = cls(**transformed_response) return trial - + @Base.add_validate_call def refresh( self, - ) -> Optional["Trial"]: + + ) -> Optional["Trial"]: """ Refresh a Trial resource - + Returns: The Trial resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29856,21 +29531,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrialName": self.trial_name, + 'TrialName': self.trial_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_trial(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeTrialResponse", self) + transform(response, 'DescribeTrialResponse', self) return self - + @Base.add_validate_call def update( self, @@ -29878,12 +29553,12 @@ def update( ) -> Optional["Trial"]: """ Update a Trial resource - + Returns: The Trial resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29895,35 +29570,36 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating trial resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "TrialName": self.trial_name, - "DisplayName": display_name, + 'TrialName': self.trial_name, + 'DisplayName': display_name, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_trial(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Trial resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29934,20 +29610,20 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "TrialName": self.trial_name, + 'TrialName': self.trial_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_trial(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -29963,7 +29639,7 @@ def get_all( ) -> ResourceIterator["Trial"]: """ Get all Trial resources - + Parameters: experiment_name: A filter that returns only trials that are part of the specified experiment. trial_component_name: A filter that returns only trials that are associated with the specified trial component. @@ -29975,12 +29651,12 @@ def get_all( next_token: If the previous call to ListTrials didn't return the full set of trials, the call returns a token for getting the next set of trials. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Trial resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -29991,44 +29667,43 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "ExperimentName": experiment_name, - "TrialComponentName": trial_component_name, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'ExperimentName': experiment_name, + 'TrialComponentName': trial_component_name, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_trials", - summaries_key="TrialSummaries", - summary_name="TrialSummary", + list_method='list_trials', + summaries_key='TrialSummaries', + summary_name='TrialSummary', resource_cls=Trial, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class TrialComponent(Base): """ Class representing resource TrialComponent - + Attributes: trial_component_name: The name of the trial component. trial_component_arn: The Amazon Resource Name (ARN) of the trial component. display_name: The name of the component as displayed. If DisplayName isn't specified, TrialComponentName is displayed. source: The Amazon Resource Name (ARN) of the source and, optionally, the job type. - status: The status of the component. States include: InProgress Completed Failed + status: The status of the component. States include: InProgress Completed Failed start_time: When the component started. end_time: When the component ended. creation_time: When the component was created. @@ -30038,13 +29713,12 @@ class TrialComponent(Base): parameters: The hyperparameters of the component. input_artifacts: The input artifacts of the component. output_artifacts: The output artifacts of the component. - metadata_properties: + metadata_properties: metrics: The metrics for the component. lineage_group_arn: The Amazon Resource Name (ARN) of the lineage group. sources: A list of ARNs and, if applicable, job types for multiple sources of an experiment run. - + """ - trial_component_name: str trial_component_arn: Optional[str] = Unassigned() display_name: Optional[str] = Unassigned() @@ -30063,23 +29737,23 @@ class TrialComponent(Base): metrics: Optional[List[shapes.TrialComponentMetricSummary]] = Unassigned() lineage_group_arn: Optional[str] = Unassigned() sources: Optional[List[shapes.TrialComponentSource]] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "trial_component_name" - resource_name_split = resource_name.split("_") + resource_name = 'trial_component_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object trial_component") return None - + @classmethod @Base.add_validate_call def create( @@ -30099,26 +29773,26 @@ def create( ) -> Optional["TrialComponent"]: """ Create a TrialComponent resource - + Parameters: trial_component_name: The name of the component. The name must be unique in your Amazon Web Services account and is not case-sensitive. display_name: The name of the component as displayed. The name doesn't need to be unique. If DisplayName isn't specified, TrialComponentName is displayed. - status: The status of the component. States include: InProgress Completed Failed + status: The status of the component. States include: InProgress Completed Failed start_time: When the component started. end_time: When the component ended. parameters: The hyperparameters for the component. input_artifacts: The input artifacts for the component. Examples of input artifacts are datasets, algorithms, hyperparameters, source code, and instance types. output_artifacts: The output artifacts for the component. Examples of output artifacts are metrics, snapshots, logs, and images. - metadata_properties: + metadata_properties: tags: A list of tags to associate with the component. You can use Search API to search on the tags. session: Boto3 session. region: Region name. - + Returns: The TrialComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30132,40 +29806,36 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating trial_component resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "TrialComponentName": trial_component_name, - "DisplayName": display_name, - "Status": status, - "StartTime": start_time, - "EndTime": end_time, - "Parameters": parameters, - "InputArtifacts": input_artifacts, - "OutputArtifacts": output_artifacts, - "MetadataProperties": metadata_properties, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="TrialComponent", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'TrialComponentName': trial_component_name, + 'DisplayName': display_name, + 'Status': status, + 'StartTime': start_time, + 'EndTime': end_time, + 'Parameters': parameters, + 'InputArtifacts': input_artifacts, + 'OutputArtifacts': output_artifacts, + 'MetadataProperties': metadata_properties, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='TrialComponent', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_trial_component(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(trial_component_name=trial_component_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -30176,17 +29846,17 @@ def get( ) -> Optional["TrialComponent"]: """ Get a TrialComponent resource - + Parameters: trial_component_name: The name of the trial component to describe. session: Boto3 session. region: Region name. - + Returns: The TrialComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30197,38 +29867,37 @@ def get( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrialComponentName": trial_component_name, + 'TrialComponentName': trial_component_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_trial_component(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeTrialComponentResponse") + transformed_response = transform(response, 'DescribeTrialComponentResponse') trial_component = cls(**transformed_response) return trial_component - + @Base.add_validate_call def refresh( self, - ) -> Optional["TrialComponent"]: + + ) -> Optional["TrialComponent"]: """ Refresh a TrialComponent resource - + Returns: The TrialComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30239,21 +29908,21 @@ def refresh( ``` ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "TrialComponentName": self.trial_component_name, + 'TrialComponentName': self.trial_component_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_trial_component(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeTrialComponentResponse", self) + transform(response, 'DescribeTrialComponentResponse', self) return self - + @Base.add_validate_call def update( self, @@ -30270,17 +29939,17 @@ def update( ) -> Optional["TrialComponent"]: """ Update a TrialComponent resource - + Parameters: parameters_to_remove: The hyperparameters to remove from the component. input_artifacts_to_remove: The input artifacts to remove from the component. output_artifacts_to_remove: The output artifacts to remove from the component. - + Returns: The TrialComponent resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30292,44 +29961,45 @@ def update( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating trial_component resource.") client = Base.get_sagemaker_client() - - operation_input_args = { - "TrialComponentName": self.trial_component_name, - "DisplayName": display_name, - "Status": status, - "StartTime": start_time, - "EndTime": end_time, - "Parameters": parameters, - "ParametersToRemove": parameters_to_remove, - "InputArtifacts": input_artifacts, - "InputArtifactsToRemove": input_artifacts_to_remove, - "OutputArtifacts": output_artifacts, - "OutputArtifactsToRemove": output_artifacts_to_remove, + + operation_input_args = { + 'TrialComponentName': self.trial_component_name, + 'DisplayName': display_name, + 'Status': status, + 'StartTime': start_time, + 'EndTime': end_time, + 'Parameters': parameters, + 'ParametersToRemove': parameters_to_remove, + 'InputArtifacts': input_artifacts, + 'InputArtifactsToRemove': input_artifacts_to_remove, + 'OutputArtifacts': output_artifacts, + 'OutputArtifactsToRemove': output_artifacts_to_remove, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_trial_component(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a TrialComponent resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30340,76 +30010,74 @@ def delete( ``` ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "TrialComponentName": self.trial_component_name, + 'TrialComponentName': self.trial_component_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_trial_component(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["InProgress", "Completed", "Failed", "Stopping", "Stopped"], + target_status: Literal['InProgress', 'Completed', 'Failed', 'Stopping', 'Stopped'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a TrialComponent resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for TrialComponent to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status.primary_status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="TrialComponent", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="TrialComponent", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="TrialComponent", status=current_status) time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -30426,7 +30094,7 @@ def get_all( ) -> ResourceIterator["TrialComponent"]: """ Get all TrialComponent resources - + Parameters: experiment_name: A filter that returns only components that are part of the specified experiment. If you specify ExperimentName, you can't filter by SourceArn or TrialName. trial_name: A filter that returns only components that are part of the specified trial. If you specify TrialName, you can't filter by ExperimentName or SourceArn. @@ -30439,12 +30107,12 @@ def get_all( next_token: If the previous call to ListTrialComponents didn't return the full set of components, the call returns a token for getting the next set of components. session: Boto3 session. region: Region name. - + Returns: Iterator for listed TrialComponent resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30455,34 +30123,34 @@ def get_all( ``` ResourceNotFound: Resource being access is not found. """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "ExperimentName": experiment_name, - "TrialName": trial_name, - "SourceArn": source_arn, - "CreatedAfter": created_after, - "CreatedBefore": created_before, - "SortBy": sort_by, - "SortOrder": sort_order, + 'ExperimentName': experiment_name, + 'TrialName': trial_name, + 'SourceArn': source_arn, + 'CreatedAfter': created_after, + 'CreatedBefore': created_before, + 'SortBy': sort_by, + 'SortOrder': sort_order, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_trial_components", - summaries_key="TrialComponentSummaries", - summary_name="TrialComponentSummary", + list_method='list_trial_components', + summaries_key='TrialComponentSummaries', + summary_name='TrialComponentSummary', resource_cls=TrialComponent, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def associate_trail( self, @@ -30492,14 +30160,14 @@ def associate_trail( ) -> None: """ Associates a trial component with a trial. - + Parameters: trial_name: The name of the trial to associate with. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30511,23 +30179,24 @@ def associate_trail( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "TrialComponentName": self.trial_component_name, - "TrialName": trial_name, + 'TrialComponentName': self.trial_component_name, + 'TrialName': trial_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling associate_trial_component API") response = client.associate_trial_component(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def disassociate_trail( self, @@ -30537,14 +30206,14 @@ def disassociate_trail( ) -> None: """ Disassociates a trial component from a trial. - + Parameters: trial_name: The name of the trial to disassociate from. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30555,23 +30224,24 @@ def disassociate_trail( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "TrialComponentName": self.trial_component_name, - "TrialName": trial_name, + 'TrialComponentName': self.trial_component_name, + 'TrialName': trial_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + logger.debug(f"Calling disassociate_trial_component API") response = client.disassociate_trial_component(**operation_input_args) logger.debug(f"Response: {response}") - + + + @Base.add_validate_call def batch_put_metrics( self, @@ -30581,14 +30251,14 @@ def batch_put_metrics( ) -> None: """ Used to ingest training metrics into SageMaker. - + Parameters: metric_data: A list of raw metric values to put. session: Boto3 session. region: Region name. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30598,44 +30268,43 @@ def batch_put_metrics( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "TrialComponentName": self.trial_component_name, - "MetricData": metric_data, + 'TrialComponentName': self.trial_component_name, + 'MetricData': metric_data, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-metrics" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-metrics') + logger.debug(f"Calling batch_put_metrics API") response = client.batch_put_metrics(**operation_input_args) logger.debug(f"Response: {response}") - + + @classmethod @Base.add_validate_call def batch_get_metrics( cls, - metric_queries: List[shapes.MetricQuery], - session: Optional[Session] = None, + metric_queries: List[shapes.MetricQuery], session: Optional[Session] = None, region: Optional[str] = None, ) -> Optional[shapes.BatchGetMetricsResponse]: """ Used to retrieve training metrics from SageMaker. - + Parameters: metric_queries: Queries made to retrieve training metrics from SageMaker. session: Boto3 session. region: Region name. - + Returns: shapes.BatchGetMetricsResponse - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30645,30 +30314,29 @@ def batch_get_metrics( error_code = e.response['Error']['Code'] ``` """ - + + operation_input_args = { - "MetricQueries": metric_queries, + 'MetricQueries': metric_queries, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-metrics" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker-metrics') + logger.debug(f"Calling batch_get_metrics API") response = client.batch_get_metrics(**operation_input_args) logger.debug(f"Response: {response}") - - transformed_response = transform(response, "BatchGetMetricsResponse") + + transformed_response = transform(response, 'BatchGetMetricsResponse') return shapes.BatchGetMetricsResponse(**transformed_response) class UserProfile(Base): """ Class representing resource UserProfile - + Attributes: domain_id: The ID of the domain that contains the profile. user_profile_arn: The user profile Amazon Resource Name (ARN). @@ -30681,9 +30349,8 @@ class UserProfile(Base): single_sign_on_user_identifier: The IAM Identity Center user identifier. single_sign_on_user_value: The IAM Identity Center user value. user_settings: A collection of settings. - + """ - domain_id: str user_profile_name: str user_profile_arn: Optional[str] = Unassigned() @@ -30695,65 +30362,98 @@ class UserProfile(Base): single_sign_on_user_identifier: Optional[str] = Unassigned() single_sign_on_user_value: Optional[str] = Unassigned() user_settings: Optional[shapes.UserSettings] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "user_profile_name" - resource_name_split = resource_name.split("_") + resource_name = 'user_profile_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object user_profile") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "user_settings": { - "execution_role": {"type": "string"}, - "security_groups": {"type": "array", "items": {"type": "string"}}, - "sharing_settings": { - "s3_output_path": {"type": "string"}, - "s3_kms_key_id": {"type": "string"}, - }, - "canvas_app_settings": { - "time_series_forecasting_settings": { - "amazon_forecast_role_arn": {"type": "string"} - }, - "model_register_settings": { - "cross_account_model_register_role_arn": {"type": "string"} - }, - "workspace_settings": { - "s3_artifact_path": {"type": "string"}, - "s3_kms_key_id": {"type": "string"}, - }, - "generative_ai_settings": {"amazon_bedrock_role_arn": {"type": "string"}}, - "emr_serverless_settings": {"execution_role_arn": {"type": "string"}}, - }, - "jupyter_lab_app_settings": { - "emr_settings": { - "assumable_role_arns": {"type": "array", "items": {"type": "string"}}, - "execution_role_arns": {"type": "array", "items": {"type": "string"}}, - } - }, + config_schema_for_resource = \ + { + "user_settings": { + "execution_role": { + "type": "string" + }, + "security_groups": { + "type": "array", + "items": { + "type": "string" + } + }, + "sharing_settings": { + "s3_output_path": { + "type": "string" + }, + "s3_kms_key_id": { + "type": "string" + } + }, + "canvas_app_settings": { + "time_series_forecasting_settings": { + "amazon_forecast_role_arn": { + "type": "string" + } + }, + "model_register_settings": { + "cross_account_model_register_role_arn": { + "type": "string" + } + }, + "workspace_settings": { + "s3_artifact_path": { + "type": "string" + }, + "s3_kms_key_id": { + "type": "string" + } + }, + "generative_ai_settings": { + "amazon_bedrock_role_arn": { + "type": "string" + } + }, + "emr_serverless_settings": { + "execution_role_arn": { + "type": "string" + } + } + }, + "jupyter_lab_app_settings": { + "emr_settings": { + "assumable_role_arns": { + "type": "array", + "items": { + "type": "string" + } + }, + "execution_role_arns": { + "type": "array", + "items": { + "type": "string" + } } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "UserProfile", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "UserProfile", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -30770,22 +30470,22 @@ def create( ) -> Optional["UserProfile"]: """ Create a UserProfile resource - + Parameters: domain_id: The ID of the associated Domain. user_profile_name: A name for the UserProfile. This value is not case sensitive. - single_sign_on_user_identifier: A specifier for the type of value specified in SingleSignOnUserValue. Currently, the only supported value is "UserName". If the Domain's AuthMode is IAM Identity Center, this field is required. If the Domain's AuthMode is not IAM Identity Center, this field cannot be specified. - single_sign_on_user_value: The username of the associated Amazon Web Services Single Sign-On User for this UserProfile. If the Domain's AuthMode is IAM Identity Center, this field is required, and must match a valid username of a user in your directory. If the Domain's AuthMode is not IAM Identity Center, this field cannot be specified. + single_sign_on_user_identifier: A specifier for the type of value specified in SingleSignOnUserValue. Currently, the only supported value is "UserName". If the Domain's AuthMode is IAM Identity Center, this field is required. If the Domain's AuthMode is not IAM Identity Center, this field cannot be specified. + single_sign_on_user_value: The username of the associated Amazon Web Services Single Sign-On User for this UserProfile. If the Domain's AuthMode is IAM Identity Center, this field is required, and must match a valid username of a user in your directory. If the Domain's AuthMode is not IAM Identity Center, this field cannot be specified. tags: Each tag consists of a key and an optional value. Tag keys must be unique per resource. Tags that you specify for the User Profile are also added to all Apps that the User Profile launches. user_settings: A collection of settings. session: Boto3 session. region: Region name. - + Returns: The UserProfile resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30800,38 +30500,32 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating user_profile resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "DomainId": domain_id, - "UserProfileName": user_profile_name, - "SingleSignOnUserIdentifier": single_sign_on_user_identifier, - "SingleSignOnUserValue": single_sign_on_user_value, - "Tags": tags, - "UserSettings": user_settings, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="UserProfile", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'DomainId': domain_id, + 'UserProfileName': user_profile_name, + 'SingleSignOnUserIdentifier': single_sign_on_user_identifier, + 'SingleSignOnUserValue': single_sign_on_user_value, + 'Tags': tags, + 'UserSettings': user_settings, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='UserProfile', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_user_profile(**operation_input_args) logger.debug(f"Response: {response}") - - return cls.get( - domain_id=domain_id, user_profile_name=user_profile_name, session=session, region=region - ) - + + return cls.get(domain_id=domain_id, user_profile_name=user_profile_name, session=session, region=region) + @classmethod @Base.add_validate_call def get( @@ -30843,18 +30537,18 @@ def get( ) -> Optional["UserProfile"]: """ Get a UserProfile resource - + Parameters: domain_id: The domain ID. user_profile_name: The user profile name. This value is not case sensitive. session: Boto3 session. region: Region name. - + Returns: The UserProfile resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30866,39 +30560,38 @@ def get( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": domain_id, - "UserProfileName": user_profile_name, + 'DomainId': domain_id, + 'UserProfileName': user_profile_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_user_profile(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeUserProfileResponse") + transformed_response = transform(response, 'DescribeUserProfileResponse') user_profile = cls(**transformed_response) return user_profile - + @Base.add_validate_call def refresh( self, - ) -> Optional["UserProfile"]: + + ) -> Optional["UserProfile"]: """ Refresh a UserProfile resource - + Returns: The UserProfile resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30910,22 +30603,22 @@ def refresh( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + operation_input_args = { - "DomainId": self.domain_id, - "UserProfileName": self.user_profile_name, + 'DomainId': self.domain_id, + 'UserProfileName': self.user_profile_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_user_profile(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeUserProfileResponse", self) + transform(response, 'DescribeUserProfileResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -30934,12 +30627,12 @@ def update( ) -> Optional["UserProfile"]: """ Update a UserProfile resource - + Returns: The UserProfile resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30952,36 +30645,37 @@ def update( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. ResourceNotFound: Resource being access is not found. """ - + logger.info("Updating user_profile resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "DomainId": self.domain_id, - "UserProfileName": self.user_profile_name, - "UserSettings": user_settings, + 'DomainId': self.domain_id, + 'UserProfileName': self.user_profile_name, + 'UserSettings': user_settings, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_user_profile(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a UserProfile resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -30993,87 +30687,75 @@ def delete( ResourceInUse: Resource being accessed is in use. ResourceNotFound: Resource being access is not found. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "DomainId": self.domain_id, - "UserProfileName": self.user_profile_name, + 'DomainId': self.domain_id, + 'UserProfileName': self.user_profile_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_user_profile(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal[ - "Deleting", - "Failed", - "InService", - "Pending", - "Updating", - "Update_Failed", - "Delete_Failed", - ], + target_status: Literal['Deleting', 'Failed', 'InService', 'Pending', 'Updating', 'Update_Failed', 'Delete_Failed'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a UserProfile resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for UserProfile to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="UserProfile", - status=current_status, - reason=self.failure_reason, - ) - + raise FailedStatusError(resource_type="UserProfile", status=current_status, reason=self.failure_reason) + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="UserProfile", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -31082,13 +30764,13 @@ def wait_for_delete( ) -> None: """ Wait for a UserProfile resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31102,49 +30784,37 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for UserProfile to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.status status.update(f"Current status: [bold]{current_status}") - - if ( - "delete_failed" in current_status.lower() - or "deletefailed" in current_status.lower() - ): - raise DeleteFailedStatusError( - resource_type="UserProfile", reason=self.failure_reason - ) - + + if "delete_failed" in current_status.lower() or "deletefailed" in current_status.lower(): + raise DeleteFailedStatusError(resource_type="UserProfile", reason=self.failure_reason) + + + if timeout is not None and time.time() - start_time >= timeout: - raise TimeoutExceededError( - resouce_type="UserProfile", status=current_status - ) + raise TimeoutExceededError(resouce_type="UserProfile", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -31158,7 +30828,7 @@ def get_all( ) -> ResourceIterator["UserProfile"]: """ Get all UserProfile resources - + Parameters: next_token: If the previous response was truncated, you will receive this token. Use it in your next request to receive the next set of results. max_results: This parameter defines the maximum number of results that can be return in a single response. The MaxResults parameter is an upper bound, not a target. If there are more results available than the value specified, a NextToken is provided in the response. The NextToken indicates that the user should get the next set of results by providing this token as a part of a subsequent call. The default value for MaxResults is 10. @@ -31168,12 +30838,12 @@ def get_all( user_profile_name_contains: A parameter by which to filter the results. session: Boto3 session. region: Region name. - + Returns: Iterator for listed UserProfile resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31183,80 +30853,84 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortOrder": sort_order, - "SortBy": sort_by, - "DomainIdEquals": domain_id_equals, - "UserProfileNameContains": user_profile_name_contains, + 'SortOrder': sort_order, + 'SortBy': sort_by, + 'DomainIdEquals': domain_id_equals, + 'UserProfileNameContains': user_profile_name_contains, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_user_profiles", - summaries_key="UserProfiles", - summary_name="UserProfileDetails", + list_method='list_user_profiles', + summaries_key='UserProfiles', + summary_name='UserProfileDetails', resource_cls=UserProfile, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Workforce(Base): """ Class representing resource Workforce - + Attributes: workforce: A single private workforce, which is automatically created when you create your first private work team. You can create one private work force in each Amazon Web Services Region. By default, any workforce-related API operation used in a specific region will apply to the workforce created in that region. To learn how to create a private workforce, see Create a Private Workforce. - + """ - workforce_name: str workforce: Optional[shapes.Workforce] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "workforce_name" - resource_name_split = resource_name.split("_") + resource_name = 'workforce_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object workforce") return None + def populate_inputs_decorator(create_func): @functools.wraps(create_func) def wrapper(*args, **kwargs): - config_schema_for_resource = { - "workforce": { - "workforce_vpc_config": { - "security_group_ids": {"type": "array", "items": {"type": "string"}}, - "subnets": {"type": "array", "items": {"type": "string"}}, - } + config_schema_for_resource = \ + { + "workforce": { + "workforce_vpc_config": { + "security_group_ids": { + "type": "array", + "items": { + "type": "string" } + }, + "subnets": { + "type": "array", + "items": { + "type": "string" + } + } } - return create_func( - *args, - **Base.get_updated_kwargs_with_configured_attributes( - config_schema_for_resource, "Workforce", **kwargs - ), - ) - + } + } + return create_func(*args, **Base.get_updated_kwargs_with_configured_attributes(config_schema_for_resource, "Workforce", **kwargs)) return wrapper - + @classmethod @populate_inputs_decorator @Base.add_validate_call @@ -31273,22 +30947,22 @@ def create( ) -> Optional["Workforce"]: """ Create a Workforce resource - + Parameters: workforce_name: The name of the private workforce. cognito_config: Use this parameter to configure an Amazon Cognito private workforce. A single Cognito workforce is created using and corresponds to a single Amazon Cognito user pool. Do not use OidcConfig if you specify values for CognitoConfig. oidc_config: Use this parameter to configure a private workforce using your own OIDC Identity Provider. Do not use CognitoConfig if you specify values for OidcConfig. - source_ip_config: + source_ip_config: tags: An array of key-value pairs that contain metadata to help you categorize and organize our workforce. Each tag consists of a key and a value, both of which you define. workforce_vpc_config: Use this parameter to configure a workforce using VPC. session: Boto3 session. region: Region name. - + Returns: The Workforce resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31301,36 +30975,32 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating workforce resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "CognitoConfig": cognito_config, - "OidcConfig": oidc_config, - "SourceIpConfig": source_ip_config, - "WorkforceName": workforce_name, - "Tags": tags, - "WorkforceVpcConfig": workforce_vpc_config, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Workforce", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'CognitoConfig': cognito_config, + 'OidcConfig': oidc_config, + 'SourceIpConfig': source_ip_config, + 'WorkforceName': workforce_name, + 'Tags': tags, + 'WorkforceVpcConfig': workforce_vpc_config, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Workforce', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_workforce(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(workforce_name=workforce_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -31341,17 +31011,17 @@ def get( ) -> Optional["Workforce"]: """ Get a Workforce resource - + Parameters: - workforce_name: The name of the private workforce whose access you want to restrict. WorkforceName is automatically set to default when a workforce is created and cannot be modified. + workforce_name: The name of the private workforce whose access you want to restrict. WorkforceName is automatically set to default when a workforce is created and cannot be modified. session: Boto3 session. region: Region name. - + Returns: The Workforce resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31361,38 +31031,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "WorkforceName": workforce_name, + 'WorkforceName': workforce_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_workforce(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeWorkforceResponse") + transformed_response = transform(response, 'DescribeWorkforceResponse') workforce = cls(**transformed_response) return workforce - + @Base.add_validate_call def refresh( self, - ) -> Optional["Workforce"]: + + ) -> Optional["Workforce"]: """ Refresh a Workforce resource - + Returns: The Workforce resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31402,21 +31071,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "WorkforceName": self.workforce_name, + 'WorkforceName': self.workforce_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_workforce(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeWorkforceResponse", self) + transform(response, 'DescribeWorkforceResponse', self) return self - + @populate_inputs_decorator @Base.add_validate_call def update( @@ -31427,17 +31096,17 @@ def update( ) -> Optional["Workforce"]: """ Update a Workforce resource - + Parameters: source_ip_config: A list of one to ten worker IP address ranges (CIDRs) that can be used to access tasks assigned to this workforce. Maximum: Ten CIDR values oidc_config: Use this parameter to update your OIDC Identity Provider (IdP) configuration for a workforce made using your own IdP. workforce_vpc_config: Use this parameter to update your VPC configuration for a workforce. - + Returns: The Workforce resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31448,37 +31117,38 @@ def update( ``` ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - + logger.info("Updating workforce resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "WorkforceName": self.workforce_name, - "SourceIpConfig": source_ip_config, - "OidcConfig": oidc_config, - "WorkforceVpcConfig": workforce_vpc_config, + 'WorkforceName': self.workforce_name, + 'SourceIpConfig': source_ip_config, + 'OidcConfig': oidc_config, + 'WorkforceVpcConfig': workforce_vpc_config, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_workforce(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Workforce resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31488,76 +31158,74 @@ def delete( error_code = e.response['Error']['Code'] ``` """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "WorkforceName": self.workforce_name, + 'WorkforceName': self.workforce_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_workforce(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @Base.add_validate_call def wait_for_status( self, - target_status: Literal["Initializing", "Updating", "Deleting", "Failed", "Active"], + target_status: Literal['Initializing', 'Updating', 'Deleting', 'Failed', 'Active'], poll: int = 5, - timeout: Optional[int] = None, + timeout: Optional[int] = None ) -> None: """ Wait for a Workforce resource to reach certain status. - + Parameters: target_status: The status to wait for. poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: TimeoutExceededError: If the resource does not reach a terminal state before the timeout. FailedStatusError: If the resource reaches a failed state. WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task(f"Waiting for Workforce to reach [bold]{target_status} status...") status = Status("Current status:") - + with Live( Panel( Group(progress, status), title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), + border_style=Style(color=Color.BLUE.value + ) ), - transient=True, + transient=True ): while True: self.refresh() current_status = self.workforce.status status.update(f"Current status: [bold]{current_status}") - + if target_status == current_status: logger.info(f"Final Resource Status: [bold]{current_status}") return - + if "failed" in current_status.lower(): - raise FailedStatusError( - resource_type="Workforce", status=current_status, reason="(Unknown)" - ) - + raise FailedStatusError(resource_type="Workforce", status=current_status, reason='(Unknown)') + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Workforce", status=current_status) time.sleep(poll) - + @Base.add_validate_call def wait_for_delete( self, @@ -31566,13 +31234,13 @@ def wait_for_delete( ) -> None: """ Wait for a Workforce resource to be deleted. - + Parameters: poll: The number of seconds to wait between each poll. timeout: The maximum number of seconds to wait before timing out. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31586,39 +31254,34 @@ def wait_for_delete( WaiterError: Raised when an error occurs while waiting. """ start_time = time.time() - - progress = Progress( - SpinnerColumn("bouncingBar"), + + progress = Progress(SpinnerColumn("bouncingBar"), TextColumn("{task.description}"), TimeElapsedColumn(), ) progress.add_task("Waiting for Workforce to be deleted...") status = Status("Current status:") - - with Live( - Panel( - Group(progress, status), - title="Wait Log Panel", - border_style=Style(color=Color.BLUE.value), - ) - ): + + with Live(Panel(Group(progress, status), title="Wait Log Panel", border_style=Style(color=Color.BLUE.value))): while True: try: self.refresh() current_status = self.workforce.status status.update(f"Current status: [bold]{current_status}") - + + + if timeout is not None and time.time() - start_time >= timeout: raise TimeoutExceededError(resouce_type="Workforce", status=current_status) except botocore.exceptions.ClientError as e: error_code = e.response["Error"]["Code"] - + if "ResourceNotFound" in error_code or "ValidationException" in error_code: logger.info("Resource was not found. It may have been deleted.") return raise e time.sleep(poll) - + @classmethod @Base.add_validate_call def get_all( @@ -31631,7 +31294,7 @@ def get_all( ) -> ResourceIterator["Workforce"]: """ Get all Workforce resources - + Parameters: sort_by: Sort workforces using the workforce name or creation date. sort_order: Sort workforces in ascending or descending order. @@ -31640,12 +31303,12 @@ def get_all( max_results: The maximum number of workforces returned in the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Workforce resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31655,59 +31318,57 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_workforces", - summaries_key="Workforces", - summary_name="Workforce", + list_method='list_workforces', + summaries_key='Workforces', + summary_name='Workforce', resource_cls=Workforce, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) class Workteam(Base): """ Class representing resource Workteam - + Attributes: - workteam: A Workteam instance that contains information about the work team. - + workteam: A Workteam instance that contains information about the work team. + """ - workteam_name: str workteam: Optional[shapes.Workteam] = Unassigned() - + def get_name(self) -> str: attributes = vars(self) - resource_name = "workteam_name" - resource_name_split = resource_name.split("_") + resource_name = 'workteam_name' + resource_name_split = resource_name.split('_') attribute_name_candidates = [] - + l = len(resource_name_split) for i in range(0, l): attribute_name_candidates.append("_".join(resource_name_split[i:l])) - + for attribute, value in attributes.items(): - if attribute == "name" or attribute in attribute_name_candidates: + if attribute == 'name' or attribute in attribute_name_candidates: return value logger.error("Name attribute not found for object workteam") return None - + @classmethod @Base.add_validate_call def create( @@ -31724,7 +31385,7 @@ def create( ) -> Optional["Workteam"]: """ Create a Workteam resource - + Parameters: workteam_name: The name of the work team. Use this name to identify the work team. member_definitions: A list of MemberDefinition objects that contains objects that identify the workers that make up the work team. Workforces can be created using Amazon Cognito or your own OIDC Identity Provider (IdP). For private workforces created using Amazon Cognito use CognitoMemberDefinition. For workforces created using your own OIDC identity provider (IdP) use OidcMemberDefinition. Do not provide input for both of these parameters in a single request. For workforces created using Amazon Cognito, private work teams correspond to Amazon Cognito user groups within the user pool used to create a workforce. All of the CognitoMemberDefinition objects that make up the member definition must have the same ClientId and UserPool values. To add a Amazon Cognito user group to an existing worker pool, see Adding groups to a User Pool. For more information about user pools, see Amazon Cognito User Pools. For workforces created using your own OIDC IdP, specify the user groups that you want to include in your private work team in OidcMemberDefinition by listing those groups in Groups. @@ -31735,12 +31396,12 @@ def create( tags: An array of key-value pairs. For more information, see Resource Tag and Using Cost Allocation Tags in the Amazon Web Services Billing and Cost Management User Guide. session: Boto3 session. region: Region name. - + Returns: The Workteam resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31755,37 +31416,33 @@ def create( LocalConfigNotFoundError: Raised when a configuration file is not found in local file system S3ConfigNotFoundError: Raised when a configuration file is not found in S3 """ - + logger.info("Creating workteam resource.") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - - operation_input_args = { - "WorkteamName": workteam_name, - "WorkforceName": workforce_name, - "MemberDefinitions": member_definitions, - "Description": description, - "NotificationConfiguration": notification_configuration, - "WorkerAccessConfiguration": worker_access_configuration, - "Tags": tags, - } - - operation_input_args = Base.populate_chained_attributes( - resource_name="Workteam", operation_input_args=operation_input_args - ) - + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + operation_input_args = { + 'WorkteamName': workteam_name, + 'WorkforceName': workforce_name, + 'MemberDefinitions': member_definitions, + 'Description': description, + 'NotificationConfiguration': notification_configuration, + 'WorkerAccessConfiguration': worker_access_configuration, + 'Tags': tags, + } + + operation_input_args = Base.populate_chained_attributes(resource_name='Workteam', operation_input_args=operation_input_args) + logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.create_workteam(**operation_input_args) logger.debug(f"Response: {response}") - + return cls.get(workteam_name=workteam_name, session=session, region=region) - + @classmethod @Base.add_validate_call def get( @@ -31796,17 +31453,17 @@ def get( ) -> Optional["Workteam"]: """ Get a Workteam resource - + Parameters: workteam_name: The name of the work team to return a description of. session: Boto3 session. region: Region name. - + Returns: The Workteam resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31816,38 +31473,37 @@ def get( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "WorkteamName": workteam_name, + 'WorkteamName': workteam_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') response = client.describe_workteam(**operation_input_args) - + logger.debug(response) - + # deserialize the response - transformed_response = transform(response, "DescribeWorkteamResponse") + transformed_response = transform(response, 'DescribeWorkteamResponse') workteam = cls(**transformed_response) return workteam - + @Base.add_validate_call def refresh( self, - ) -> Optional["Workteam"]: + + ) -> Optional["Workteam"]: """ Refresh a Workteam resource - + Returns: The Workteam resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31857,21 +31513,21 @@ def refresh( error_code = e.response['Error']['Code'] ``` """ - + operation_input_args = { - "WorkteamName": self.workteam_name, + 'WorkteamName': self.workteam_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client = Base.get_sagemaker_client() response = client.describe_workteam(**operation_input_args) - + # deserialize response and update self - transform(response, "DescribeWorkteamResponse", self) + transform(response, 'DescribeWorkteamResponse', self) return self - + @Base.add_validate_call def update( self, @@ -31882,18 +31538,18 @@ def update( ) -> Optional["Workteam"]: """ Update a Workteam resource - + Parameters: - member_definitions: A list of MemberDefinition objects that contains objects that identify the workers that make up the work team. Workforces can be created using Amazon Cognito or your own OIDC Identity Provider (IdP). For private workforces created using Amazon Cognito use CognitoMemberDefinition. For workforces created using your own OIDC identity provider (IdP) use OidcMemberDefinition. You should not provide input for both of these parameters in a single request. For workforces created using Amazon Cognito, private work teams correspond to Amazon Cognito user groups within the user pool used to create a workforce. All of the CognitoMemberDefinition objects that make up the member definition must have the same ClientId and UserPool values. To add a Amazon Cognito user group to an existing worker pool, see Adding groups to a User Pool. For more information about user pools, see Amazon Cognito User Pools. For workforces created using your own OIDC IdP, specify the user groups that you want to include in your private work team in OidcMemberDefinition by listing those groups in Groups. Be aware that user groups that are already in the work team must also be listed in Groups when you make this request to remain on the work team. If you do not include these user groups, they will no longer be associated with the work team you update. + member_definitions: A list of MemberDefinition objects that contains objects that identify the workers that make up the work team. Workforces can be created using Amazon Cognito or your own OIDC Identity Provider (IdP). For private workforces created using Amazon Cognito use CognitoMemberDefinition. For workforces created using your own OIDC identity provider (IdP) use OidcMemberDefinition. You should not provide input for both of these parameters in a single request. For workforces created using Amazon Cognito, private work teams correspond to Amazon Cognito user groups within the user pool used to create a workforce. All of the CognitoMemberDefinition objects that make up the member definition must have the same ClientId and UserPool values. To add a Amazon Cognito user group to an existing worker pool, see Adding groups to a User Pool. For more information about user pools, see Amazon Cognito User Pools. For workforces created using your own OIDC IdP, specify the user groups that you want to include in your private work team in OidcMemberDefinition by listing those groups in Groups. Be aware that user groups that are already in the work team must also be listed in Groups when you make this request to remain on the work team. If you do not include these user groups, they will no longer be associated with the work team you update. description: An updated description for the work team. notification_configuration: Configures SNS topic notifications for available or expiring work items worker_access_configuration: Use this optional parameter to constrain access to an Amazon S3 resource based on the IP address using supported IAM global condition keys. The Amazon S3 resource is accessed in the worker portal using a Amazon S3 presigned URL. - + Returns: The Workteam resource. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31904,38 +31560,39 @@ def update( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + logger.info("Updating workteam resource.") client = Base.get_sagemaker_client() - + operation_input_args = { - "WorkteamName": self.workteam_name, - "MemberDefinitions": member_definitions, - "Description": description, - "NotificationConfiguration": notification_configuration, - "WorkerAccessConfiguration": worker_access_configuration, + 'WorkteamName': self.workteam_name, + 'MemberDefinitions': member_definitions, + 'Description': description, + 'NotificationConfiguration': notification_configuration, + 'WorkerAccessConfiguration': worker_access_configuration, } logger.debug(f"Input request: {operation_input_args}") # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + # create the resource response = client.update_workteam(**operation_input_args) logger.debug(f"Response: {response}") self.refresh() - + return self - + @Base.add_validate_call def delete( self, - ) -> None: + + ) -> None: """ Delete a Workteam resource - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31946,20 +31603,20 @@ def delete( ``` ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - + client = Base.get_sagemaker_client() - + operation_input_args = { - "WorkteamName": self.workteam_name, + 'WorkteamName': self.workteam_name, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + client.delete_workteam(**operation_input_args) - + logger.info(f"Deleting {self.__class__.__name__} - {self.get_name()}") - + @classmethod @Base.add_validate_call def get_all( @@ -31972,7 +31629,7 @@ def get_all( ) -> ResourceIterator["Workteam"]: """ Get all Workteam resources - + Parameters: sort_by: The field to sort results by. The default is CreationTime. sort_order: The sort order for results. The default is Ascending. @@ -31981,12 +31638,12 @@ def get_all( max_results: The maximum number of work teams to return in each page of the response. session: Boto3 session. region: Region name. - + Returns: Iterator for listed Workteam resources. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -31996,30 +31653,30 @@ def get_all( error_code = e.response['Error']['Code'] ``` """ - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name="sagemaker") + operation_input_args = { - "SortBy": sort_by, - "SortOrder": sort_order, - "NameContains": name_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, + 'NameContains': name_contains, } - + + # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - + return ResourceIterator( client=client, - list_method="list_workteams", - summaries_key="Workteams", - summary_name="Workteam", + list_method='list_workteams', + summaries_key='Workteams', + summary_name='Workteam', resource_cls=Workteam, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) - + + @Base.add_validate_call def get_all_labeling_jobs( self, @@ -32028,13 +31685,12 @@ def get_all_labeling_jobs( creation_time_before: Optional[datetime.datetime] = Unassigned(), job_reference_code_contains: Optional[str] = Unassigned(), sort_by: Optional[str] = Unassigned(), - sort_order: Optional[str] = Unassigned(), - session: Optional[Session] = None, + sort_order: Optional[str] = Unassigned(), session: Optional[Session] = None, region: Optional[str] = None, ) -> ResourceIterator[LabelingJob]: """ Gets a list of labeling jobs assigned to a specified work team. - + Parameters: workteam_arn: The Amazon Resource Name (ARN) of the work team for which you want to see labeling jobs for. max_results: The maximum number of labeling jobs to return in each page of the response. @@ -32046,12 +31702,12 @@ def get_all_labeling_jobs( sort_order: The sort order for results. The default is Ascending. session: Boto3 session. region: Region name. - + Returns: Iterator for listed LabelingJob. - + Raises: - botocore.exceptions.ClientError: This exception is raised for AWS service related errors. + botocore.exceptions.ClientError: This exception is raised for AWS service related errors. The error message and error code can be parsed from the exception as follows: ``` try: @@ -32062,28 +31718,30 @@ def get_all_labeling_jobs( ``` ResourceNotFound: Resource being access is not found. """ - + + operation_input_args = { - "WorkteamArn": workteam_arn, - "CreationTimeAfter": creation_time_after, - "CreationTimeBefore": creation_time_before, - "JobReferenceCodeContains": job_reference_code_contains, - "SortBy": sort_by, - "SortOrder": sort_order, + 'WorkteamArn': workteam_arn, + 'CreationTimeAfter': creation_time_after, + 'CreationTimeBefore': creation_time_before, + 'JobReferenceCodeContains': job_reference_code_contains, + 'SortBy': sort_by, + 'SortOrder': sort_order, } # serialize the input request operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) - + + client = Base.get_sagemaker_client(session=session, region_name=region, service_name='sagemaker') + + return ResourceIterator( client=client, - list_method="list_labeling_jobs_for_workteam", - summaries_key="LabelingJobSummaryList", - summary_name="LabelingJobForWorkteamSummary", + list_method='list_labeling_jobs_for_workteam', + summaries_key='LabelingJobSummaryList', + summary_name='LabelingJobForWorkteamSummary', resource_cls=LabelingJob, - list_method_kwargs=operation_input_args, + list_method_kwargs=operation_input_args ) + + diff --git a/tst/tools/test_resources_codegen.py b/tst/tools/test_resources_codegen.py index 916d04c4..725c16ab 100644 --- a/tst/tools/test_resources_codegen.py +++ b/tst/tools/test_resources_codegen.py @@ -1946,3 +1946,30 @@ def put_record( self.resource_generator.generate_method(method, ["feature_group_name"]) == expected_output ) + + def test_empty_resource_no_methods_or_attributes(self): + """Test that resource with no methods or attributes returns empty string.i.e., resource class not generated""" + result = self.resource_generator.generate_resource_class( + resource_name="EmptyResource", + class_methods=[], + object_methods=[], + additional_methods=[], + raw_actions=[], + resource_status_chain=[], + resource_states=[], + ) + assert result == "" + + def test_resource_with_random_class_method_no_attributes(self): + """Test that resource with random method but no other attributes returns empty string.i.e., resource class not generated""" + """current supported methods are create, get, refresh, update, delete, stop, wait, wait_for_status, wait_for_delete, get_all """ + result = self.resource_generator.generate_resource_class( + resource_name="EmptyResource", + class_methods=["random"], + object_methods=[], + additional_methods=[], + raw_actions=[], + resource_status_chain=[], + resource_states=[], + ) + assert result == ""