1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
from typing import Optional
from moto.core.exceptions import ServiceException
class RDSClientError(ServiceException):
pass
class DBInstanceNotFoundError(RDSClientError):
def __init__(self, database_identifier: str):
super().__init__(
"DBInstanceNotFound", f"DBInstance {database_identifier} not found."
)
class DBInstanceAlreadyExists(RDSClientError):
def __init__(self) -> None:
super().__init__("DBInstanceAlreadyExists", "DB instance already exists")
class DBSnapshotNotFoundFault(RDSClientError):
def __init__(self, snapshot_identifier: str):
super().__init__(
"DBSnapshotNotFoundFault", f"DBSnapshot {snapshot_identifier} not found."
)
class DBSecurityGroupNotFoundError(RDSClientError):
def __init__(self, security_group_name: str):
super().__init__(
"DBSecurityGroupNotFound",
f"Security Group {security_group_name} not found.",
)
class DBShardGroupAlreadyExistsError(RDSClientError):
def __init__(self, shard_group_identifier: str):
super().__init__(
"DBShardGroupAlreadyExists",
f"DB Shard Group {shard_group_identifier} already exists.",
)
class DBSubnetGroupNotFoundError(RDSClientError):
def __init__(self, subnet_group_name: str):
super().__init__(
"DBSubnetGroupNotFoundFault", f"Subnet Group {subnet_group_name} not found."
)
class DBParameterGroupNotFoundError(RDSClientError):
def __init__(self, db_parameter_group_name: str):
super().__init__(
"DBParameterGroupNotFound",
f"DB Parameter Group {db_parameter_group_name} not found.",
)
class DBParameterGroupAlreadyExistsError(RDSClientError):
def __init__(self, db_parameter_group_name: str):
super().__init__(
"DBParameterGroupAlreadyExists",
f"DB Parameter Group {db_parameter_group_name} already exists.",
)
class DBClusterParameterGroupNotFoundError(RDSClientError):
def __init__(self, group_name: str):
super().__init__(
"DBParameterGroupNotFound",
f"DBClusterParameterGroup not found: {group_name}",
)
class OptionGroupNotFoundFaultError(RDSClientError):
def __init__(self, option_group_name: str):
super().__init__(
"OptionGroupNotFoundFault",
f"Specified OptionGroupName: {option_group_name} not found.",
)
class InvalidDBClusterStateFaultError(RDSClientError):
def __init__(self, database_identifier: str):
super().__init__(
"InvalidDBClusterStateFault",
f"Invalid DB type, when trying to perform StopDBInstance on {database_identifier}e. See AWS RDS documentation on rds.stop_db_instance",
)
class DBClusterToBeDeletedHasActiveMembers(RDSClientError):
def __init__(self) -> None:
super().__init__(
"InvalidDBClusterStateFault",
"Cluster cannot be deleted, it still contains DB instances in non-deleting state.",
)
class InvalidDBInstanceStateError(RDSClientError):
def __init__(self, database_identifier: str, istate: str):
estate = (
"in available state"
if istate == "stop"
else "stopped, it cannot be started"
)
super().__init__(
"InvalidDBInstanceState", f"Instance {database_identifier} is not {estate}."
)
class InvalidDBInstanceStateFault(RDSClientError):
def __init__(self, message: str):
super().__init__("InvalidDBInstanceStateFault", message)
class SnapshotQuotaExceededFault(RDSClientError):
# This is used for both DBSnapshots and DBClusterSnapshots
def __init__(self) -> None:
super().__init__(
"SnapshotQuotaExceeded",
"The request cannot be processed because it would exceed the maximum number of snapshots.",
)
class SharedSnapshotQuotaExceeded(RDSClientError):
def __init__(self) -> None:
super().__init__(
"SharedSnapshotQuotaExceeded",
"The request cannot be processed because it would exceed the maximum number of snapshots.",
)
class KMSKeyNotAccessibleFault(RDSClientError):
fmt = "Specified KMS key [{key_id}] does not exist, is not enabled or you do not have permissions to access it."
def __init__(self, key_id: str) -> None:
super().__init__(
"KMSKeyNotAccessibleFault",
f"Specified KMS key [{key_id}] does not exist, is not enabled or you do not have permissions to access it.",
)
class InvalidDBClusterSnapshotStateFault(RDSClientError):
def __init__(self, message: str):
super().__init__("InvalidDBClusterSnapshotStateFault", message)
class DBSnapshotAlreadyExistsError(RDSClientError):
def __init__(self, database_snapshot_identifier: str):
super().__init__(
"DBSnapshotAlreadyExists",
f"Cannot create the snapshot because a snapshot with the identifier {database_snapshot_identifier} already exists.",
)
class DBShardGroupNotFoundFault(RDSClientError):
def __init__(self, db_shard_group_identifier: str):
super().__init__(
"DBShardGroupNotFoundFault",
f"DBShardGroup {db_shard_group_identifier} not found.",
)
class InvalidParameterValue(RDSClientError):
def __init__(self, message: str):
super().__init__("InvalidParameterValue", message)
class InvalidParameterCombination(RDSClientError):
def __init__(self, message: str):
super().__init__("InvalidParameterCombination", message)
class InvalidDBClusterStateFault(RDSClientError):
def __init__(self, message: str):
super().__init__("InvalidDBClusterStateFault", message)
class DBClusterNotFoundError(RDSClientError):
def __init__(self, cluster_identifier: str, message: Optional[str] = None):
if message is None:
message = f"DBCluster {cluster_identifier} not found."
super().__init__("DBClusterNotFoundFault", message)
class DBClusterSnapshotNotFoundError(RDSClientError):
def __init__(self, snapshot_identifier: str):
super().__init__(
"DBClusterSnapshotNotFoundFault",
f"DBClusterSnapshot {snapshot_identifier} not found.",
)
class DBClusterSnapshotAlreadyExistsError(RDSClientError):
def __init__(self, database_snapshot_identifier: str):
super().__init__(
"DBClusterSnapshotAlreadyExistsFault",
f"Cannot create the snapshot because a snapshot with the identifier {database_snapshot_identifier} already exists.",
)
class ExportTaskAlreadyExistsError(RDSClientError):
def __init__(self, export_task_identifier: str):
super().__init__(
"ExportTaskAlreadyExists",
f"Cannot start export task because a task with the identifier {export_task_identifier} already exists.",
)
class ExportTaskNotFoundError(RDSClientError):
def __init__(self, export_task_identifier: str):
super().__init__(
"ExportTaskNotFound",
f"Cannot cancel export task because a task with the identifier {export_task_identifier} is not exist.",
)
class InvalidExportSourceStateError(RDSClientError):
def __init__(self, status: str):
super().__init__(
"InvalidExportSourceStateFault",
f"Export source should be 'available' but current status is {status}.",
)
class SubscriptionAlreadyExistError(RDSClientError):
def __init__(self, subscription_name: str):
super().__init__(
"SubscriptionAlreadyExist",
f"Subscription {subscription_name} already exists.",
)
class SubscriptionNotFoundError(RDSClientError):
def __init__(self, subscription_name: str):
super().__init__(
"SubscriptionNotFound", f"Subscription {subscription_name} not found."
)
class InvalidGlobalClusterStateFault(RDSClientError):
def __init__(self, arn: str):
super().__init__(
"InvalidGlobalClusterStateFault", f"Global Cluster {arn} is not empty"
)
class InvalidDBInstanceIdentifier(InvalidParameterValue):
def __init__(self) -> None:
super().__init__(
"The parameter DBInstanceIdentifier is not a valid identifier. "
"Identifiers must begin with a letter; must contain only ASCII letters, digits, and hyphens; "
"and must not end with a hyphen or contain two consecutive hyphens."
)
class InvalidDBSnapshotIdentifier(InvalidParameterValue):
def __init__(self, snapshot_identifier: str, parameter_name: str) -> None:
if snapshot_identifier == "":
exception_text = f"The parameter {parameter_name} must be provided and must not be blank."
elif not snapshot_identifier[0].isalpha():
# On AWS, this error message seems to be triggered when the first character is invalid.
# The two spaces before the snapshot_identifier are what AWS produces!
exception_text = f"Invalid snapshot identifier: {snapshot_identifier}"
else:
exception_text = (
f"The parameter {parameter_name} is not a valid identifier. "
"Identifiers must begin with a letter; must contain only ASCII letters, digits, and hyphens; "
"and must not end with a hyphen or contain two consecutive hyphens."
)
super().__init__(exception_text)
class InvalidDBInstanceEngine(InvalidParameterCombination):
def __init__(self, instance_engine: str, cluster_engine: str) -> None:
super().__init__(
f"The engine name requested for your DB instance ({instance_engine}) doesn't match "
f"the engine name of your DB cluster ({cluster_engine})."
)
class InvalidSubnet(RDSClientError):
def __init__(self, subnet_identifier: str):
super().__init__(
"InvalidSubnet",
f"The requested subnet {subnet_identifier} is invalid, or multiple subnets were requested that are not all in a common VPC.",
)
class DBProxyAlreadyExistsFault(RDSClientError):
def __init__(self, db_proxy_identifier: str):
super().__init__(
"DBProxyAlreadyExistsFault",
f"Cannot create the DBProxy because a DBProxy with the identifier {db_proxy_identifier} already exists.",
)
class DBProxyQuotaExceededFault(RDSClientError):
def __init__(self) -> None:
super().__init__(
"DBProxyQuotaExceeded",
"The request cannot be processed because it would exceed the maximum number of DBProxies.",
)
class DBProxyNotFoundFault(RDSClientError):
def __init__(self, db_proxy_identifier: str):
super().__init__(
"DBProxyNotFoundFault",
f"The specified proxy name {db_proxy_identifier} doesn't correspond to a proxy owned by your Amazon Web Services account in the specified Amazon Web Services Region.",
)
class BlueGreenDeploymentAlreadyExistsFault(RDSClientError):
def __init__(self, bg_name: str):
super().__init__(
"BlueGreenDeploymentAlreadyExistsFault",
f"A blue/green deployment with the specified name {bg_name} already exists.",
)
class BlueGreenDeploymentNotFoundFault(RDSClientError):
def __init__(self, bg_identifier: str):
super().__init__(
"BlueGreenDeploymentNotFoundFault",
f"BlueGreenDeploymentIdentifier {bg_identifier} doesn't refer to an existing blue/green deployment.",
)
class InvalidBlueGreenDeploymentStateFault(RDSClientError):
def __init__(self, bg_identifier: str):
super().__init__(
"InvalidBlueGreenDeploymentStateFault",
f"The blue/green deployment {bg_identifier} can't be switched over or deleted because there is an invalid configuration in the green environment.",
)
class SourceDatabaseNotSupportedFault(RDSClientError):
def __init__(self, source_arn: str):
super().__init__(
"SourceDatabaseNotSupportedFault",
f"The source DB instance {source_arn} isn't supported for a blue/green deployment.",
)
class SourceClusterNotSupportedFault(RDSClientError):
def __init__(self, source_arn: str):
super().__init__(
"SourceClusterNotSupportedFault",
f"The source DB cluster {source_arn} isn't supported for a blue/green deployment.",
)
class DBInstanceRoleAlreadyExists(RDSClientError):
def __init__(self, message: str):
super().__init__("DBInstanceRoleAlreadyExists", message)
class DBClusterRoleAlreadyExists(RDSClientError):
def __init__(self, message: str):
super().__init__("DBClusterRoleAlreadyExists", message)
|