You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/12/01 06:48:04 UTC

[GitHub] [airflow] uranusjr commented on a diff in pull request #28024: Add AWS SageMaker operator to register a model's version

uranusjr commented on code in PR #28024:
URL: https://github.com/apache/airflow/pull/28024#discussion_r1036743714


##########
airflow/providers/amazon/aws/hooks/sagemaker.py:
##########
@@ -1010,3 +1010,35 @@ def delete_model(self, model_name: str):
         except Exception as general_error:
             self.log.error("Failed to delete model, error: %s", general_error)
             raise
+
+    def create_model_package_group(self, package_group_name: str, package_group_desc: str = "") -> bool:
+        """
+        Creates a Model Package Group if it does not already exist
+
+        :param package_group_name: Name of the model package group to create if not already present.
+        :param package_group_desc: Description of the model package group, if it was to be created (optional).
+
+        :return: True if the model package group was created, False if it already existed.
+        """
+        try:
+            res = self.conn.create_model_package_group(
+                ModelPackageGroupName=package_group_name,
+                ModelPackageGroupDescription=package_group_desc,
+            )
+            self.log.info(
+                "Created new Model Package Group with name %s (ARN: %s)",
+                package_group_name,
+                res["ModelPackageGroupArn"],
+            )
+            return True
+        except ClientError as e:
+            # ValidationException can also happen if the package group name contains invalid char,
+            # so we have to look at the error message too
+            if e.response["Error"]["Code"] == "ValidationException" and e.response["Error"][
+                "Message"
+            ].startswith("Model Package Group already exists"):
+                self.log.info(e.response["Error"]["Message"])  # log msg only so it doesn't look like an error

Review Comment:
   ```suggestion
                   self.log.info("%s", e.response["Error"]["Message"])  # log msg only so it doesn't look like an error
   ```
   
   Don’t pass a variable to the logger directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org