ferruzzi commented on code in PR #38693:
URL: https://github.com/apache/airflow/pull/38693#discussion_r1550181713
##########
airflow/providers/amazon/aws/hooks/bedrock.py:
##########
@@ -16,9 +16,54 @@
# under the License.
from __future__ import annotations
+from botocore.exceptions import ClientError
+
from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
+class BedrockHook(AwsBaseHook):
+ """
+ Interact with Amazon Bedrock.
+
+ Provide thin wrapper around
:external+boto3:py:class:`boto3.client("bedrock") <Bedrock.Client>`.
+
+ Additional arguments (such as ``aws_conn_id``) may be specified and
+ are passed down to the underlying AwsBaseHook.
+
+ .. seealso::
+ - :class:`airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
+ """
+
+ client_type = "bedrock"
+
+ def __init__(self, *args, **kwargs) -> None:
+ kwargs["client_type"] = self.client_type
+ super().__init__(*args, **kwargs)
+
+ def _get_job_by_name(self, job_name: str):
+ return self.conn.get_model_customization_job(jobIdentifier=job_name)
+
+ def get_customize_model_job_state(self, job_name) -> str:
+ state = self._get_job_by_name(job_name)["status"]
+ self.log.info("Job '%s' state: %s", job_name, state)
+ return state
+
+ def job_name_exists(self, job_name: str) -> bool:
+ try:
+ self._get_job_by_name(job_name)
+ self.log.info("Verified that job name '%s' does exist.", job_name)
+ return True
+ except ClientError as e:
+ if e.response["Error"]["Code"] == "ValidationException":
+ self.log.info("Job name '%s' does not exist.", job_name)
+ return False
+ else:
+ raise e
Review Comment:
fair.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]