|
18 | 18 |
|
19 | 19 | from typing import TYPE_CHECKING, Any, Iterable, Sequence
|
20 | 20 |
|
| 21 | +from botocore.exceptions import ClientError |
| 22 | + |
21 | 23 | from airflow.providers.amazon.aws.hooks.dynamodb import DynamoDBHook
|
22 | 24 | from airflow.providers.amazon.aws.sensors.base_aws import AwsBaseSensor
|
23 | 25 | from airflow.providers.amazon.aws.utils.mixins import aws_template_fields
|
@@ -102,14 +104,26 @@ def poke(self, context: Context) -> bool:
|
102 | 104 | table = self.hook.conn.Table(self.table_name)
|
103 | 105 | self.log.info("Table: %s", table)
|
104 | 106 | self.log.info("Key: %s", key)
|
105 |
| - response = table.get_item(Key=key) |
| 107 | + |
106 | 108 | try:
|
107 |
| - item_attribute_value = response["Item"][self.attribute_name] |
108 |
| - self.log.info("Response: %s", response) |
109 |
| - self.log.info("Want: %s = %s", self.attribute_name, self.attribute_value) |
110 |
| - self.log.info("Got: {response['Item'][self.attribute_name]} = %s", item_attribute_value) |
111 |
| - return item_attribute_value in ( |
112 |
| - [self.attribute_value] if isinstance(self.attribute_value, str) else self.attribute_value |
| 109 | + response = table.get_item(Key=key) |
| 110 | + except ClientError as err: |
| 111 | + self.log.error( |
| 112 | + "Couldn't get %s from table %s.\nError Code: %s\nError Message: %s", |
| 113 | + key, |
| 114 | + self.table_name, |
| 115 | + err.response["Error"]["Code"], |
| 116 | + err.response["Error"]["Message"], |
113 | 117 | )
|
114 |
| - except KeyError: |
115 | 118 | return False
|
| 119 | + else: |
| 120 | + try: |
| 121 | + item_attribute_value = response["Item"][self.attribute_name] |
| 122 | + self.log.info("Response: %s", response) |
| 123 | + self.log.info("Want: %s = %s", self.attribute_name, self.attribute_value) |
| 124 | + self.log.info("Got: {response['Item'][self.attribute_name]} = %s", item_attribute_value) |
| 125 | + return item_attribute_value in ( |
| 126 | + [self.attribute_value] if isinstance(self.attribute_value, str) else self.attribute_value |
| 127 | + ) |
| 128 | + except KeyError: |
| 129 | + return False |
0 commit comments