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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
|
from collections.abc import Iterable
from typing import Any, Optional, Union
from moto.core.exceptions import RESTError, ServiceException
class EC2Error(ServiceException):
pass
class DryRunClientError(EC2Error):
code = "DryRunOperation"
message = "Request would have succeeded, but DryRun flag is set."
# EC2 has a custom root-tag - <Response> vs <ErrorResponse>
# `terraform destroy` will complain if the roottag is incorrect
# See https://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html#api-error-response
EC2_ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Errors>
<Error>
<Code>{{error_type}}</Code>
<Message>{{message}}</Message>
</Error>
</Errors>
<{{request_id_tag}}>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</{{request_id_tag}}>
</Response>
"""
class EC2ClientError(RESTError):
code = 400
# EC2 uses <RequestID> as tag name in the XML response
request_id_tag_name = "RequestID"
extended_templates = {"custom_response": EC2_ERROR_RESPONSE}
env = RESTError.extended_environment(extended_templates)
def __init__(self, *args: Any, **kwargs: Any):
kwargs.setdefault("template", "custom_response")
super().__init__(*args, **kwargs)
class DefaultVpcAlreadyExists(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"DefaultVpcAlreadyExists",
"A Default VPC already exists for this account in this region.",
)
class DefaultVpcDoesNotExistError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"DefaultVpcDoesNotExist",
"No default VPC exists for this account in this region.",
)
class DefaultSubnetAlreadyExistsInAvailabilityZoneError(EC2ClientError):
def __init__(self, subnet_id: str, availability_zone: str) -> None:
super().__init__(
"DefaultSubnetAlreadyExistsInAvailabilityZone",
f"'{subnet_id}' is already the default subnet in {availability_zone}.",
)
class DependencyViolationError(EC2ClientError):
def __init__(self, message: str):
super().__init__("DependencyViolation", message)
class MissingInputError(EC2ClientError):
def __init__(self, message: str):
super().__init__("MissingInput", message)
class InvalidInputError(EC2ClientError):
def __init__(self, message: str):
super().__init__("InvalidInput", message)
class MissingParameterError(EC2ClientError):
def __init__(self, parameter: str):
super().__init__(
"MissingParameter",
f"The request must contain the parameter {parameter}",
)
class InvalidDHCPOptionsIdError(EC2ClientError):
def __init__(self, dhcp_options_id: str):
super().__init__(
"InvalidDhcpOptionID.NotFound",
f"DhcpOptionID {dhcp_options_id} does not exist.",
)
class InvalidRequest(EC2ClientError):
def __init__(self) -> None:
super().__init__("InvalidRequest", "The request received was invalid")
class InvalidParameterCombination(EC2ClientError):
def __init__(self, msg: str):
super().__init__("InvalidParameterCombination", msg)
class MalformedDHCPOptionsIdError(EC2ClientError):
def __init__(self, dhcp_options_id: Optional[str]):
super().__init__(
"InvalidDhcpOptionsId.Malformed",
f'Invalid id: "{dhcp_options_id}" (expecting "dopt-...")',
)
class InvalidKeyPairNameError(EC2ClientError):
def __init__(self, key: Iterable[str]):
super().__init__(
"InvalidKeyPair.NotFound", f"The keypair '{key}' does not exist."
)
class InvalidKeyPairDuplicateError(EC2ClientError):
def __init__(self, key: str):
super().__init__(
"InvalidKeyPair.Duplicate", f"The keypair '{key}' already exists."
)
class InvalidKeyPairFormatError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidKeyPair.Format", "Key is not in valid OpenSSH public key format"
)
class VPCIdNotSpecifiedError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"VPCIdNotSpecified",
"No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.",
)
class InvalidVPCIdError(EC2ClientError):
def __init__(self, vpc_id: Any):
super().__init__("InvalidVpcID.NotFound", f"VpcID {vpc_id} does not exist.")
class InvalidSubnetIdError(EC2ClientError):
def __init__(self, subnet_id: str):
super().__init__(
"InvalidSubnetID.NotFound", f"The subnet ID '{subnet_id}' does not exist"
)
class InvalidFlowLogIdError(EC2ClientError):
def __init__(self, count: int, flow_log_ids: str):
super().__init__(
"InvalidFlowLogId.NotFound",
f"These flow log ids in the input list are not found: [TotalCount: {count}] {flow_log_ids}",
)
class FlowLogAlreadyExists(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"FlowLogAlreadyExists",
"Error. There is an existing Flow Log with the same configuration and log destination.",
)
class InvalidNetworkAclIdError(EC2ClientError):
def __init__(self, network_acl_id: str):
super().__init__(
"InvalidNetworkAclID.NotFound",
f"The network acl ID '{network_acl_id}' does not exist",
)
class InvalidVpnGatewayIdError(EC2ClientError):
def __init__(self, vpn_gw: str):
super().__init__(
"InvalidVpnGatewayID.NotFound",
f"The virtual private gateway ID '{vpn_gw}' does not exist",
)
class InvalidVpnGatewayAttachmentError(EC2ClientError):
def __init__(self, vpn_gw: str, vpc_id: str):
super().__init__(
"InvalidVpnGatewayAttachment.NotFound",
f"The attachment with vpn gateway ID '{vpn_gw}' and vpc ID '{vpc_id}' does not exist",
)
class InvalidVpnConnectionIdError(EC2ClientError):
def __init__(self, network_acl_id: str):
super().__init__(
"InvalidVpnConnectionID.NotFound",
f"The vpnConnection ID '{network_acl_id}' does not exist",
)
class InvalidCustomerGatewayIdError(EC2ClientError):
def __init__(self, customer_gateway_id: str):
super().__init__(
"InvalidCustomerGatewayID.NotFound",
f"The customerGateway ID '{customer_gateway_id}' does not exist",
)
class InvalidNetworkInterfaceIdError(EC2ClientError):
def __init__(self, eni_id: str):
super().__init__(
"InvalidNetworkInterfaceID.NotFound",
f"The networkInterface ID '{eni_id}' does not exist",
)
class InvalidNetworkAttachmentIdError(EC2ClientError):
def __init__(self, attachment_id: str):
super().__init__(
"InvalidAttachmentID.NotFound",
f"The network interface attachment ID '{attachment_id}' does not exist",
)
class InvalidSecurityGroupDuplicateError(EC2ClientError):
def __init__(self, name: str):
super().__init__(
"InvalidGroup.Duplicate", f"The security group '{name}' already exists"
)
class InvalidSecurityGroupNotFoundError(EC2ClientError):
def __init__(self, name: Any):
super().__init__(
"InvalidGroup.NotFound",
f"The security group '{name}' does not exist",
)
class InvalidSecurityGroupRuleIdNotFoundError(EC2ClientError):
def __init__(self, name: Any):
super().__init__(
"InvalidSecurityGroupRuleId.NotFound",
f"The security group rule ID '{name}' does not exist",
)
class InvalidPermissionNotFoundError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidPermission.NotFound",
"The specified rule does not exist in this security group",
)
class InvalidPermissionDuplicateError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidPermission.Duplicate", "The specified rule already exists"
)
class DuplicateTransitGatewayAttachmentError(EC2ClientError):
def __init__(self, transit_gateway_id: str):
super().__init__(
"DuplicateTransitGatewayAttachment",
f"{transit_gateway_id} has non-deleted Transit Gateway Attachments with same VPC ID.",
)
class InvalidRouteTableIdError(EC2ClientError):
def __init__(self, route_table_id: str):
super().__init__(
"InvalidRouteTableID.NotFound",
f"The routeTable ID '{route_table_id}' does not exist",
)
class InvalidRouteError(EC2ClientError):
def __init__(self, route_table_id: str, cidr: str):
super().__init__(
"InvalidRoute.NotFound",
f"no route with destination-cidr-block {cidr} in route table {route_table_id}",
)
class RouteAlreadyExistsError(EC2ClientError):
def __init__(self, cidr: str):
super().__init__(
"RouteAlreadyExists", f"The route identified by {cidr} already exists"
)
class RouteNotSupportedError(EC2ClientError):
def __init__(self, vpce_id: str):
super().__init__(
"RouteNotSupported",
f"Route table contains unsupported route target: {vpce_id}. "
f"VPC Endpoints of this type cannot be used as route targets.",
)
class InvalidInstanceIdError(EC2ClientError):
def __init__(self, instance_id: Any):
if isinstance(instance_id, str):
instance_id = [instance_id]
if len(instance_id) > 1:
msg = f"The instance IDs '{', '.join(instance_id)}' do not exist"
else:
msg = f"The instance ID '{instance_id[0]}' does not exist"
super().__init__("InvalidInstanceID.NotFound", msg)
class InvalidInstanceTypeError(EC2ClientError):
def __init__(
self, instance_type: Any, error_type: str = "InvalidInstanceType.NotFound"
):
if isinstance(instance_type, str):
msg = f"The instance type '{instance_type}' does not exist"
else:
msg = (
f"The following supplied instance types do not exist: "
f"[{', '.join(instance_type)}]"
)
super().__init__(error_type, msg)
class InvalidAMIIdError(EC2ClientError):
def __init__(self, ami_id: Union[list[str], str]):
super().__init__(
"InvalidAMIID.NotFound",
f"The image id '[{ami_id}]' does not exist",
)
class UnvailableAMIIdError(EC2ClientError):
def __init__(self, ami_id: str):
super().__init__(
"InvalidAMIID.Unavailable",
f"The image id '[{ami_id}]' is no longer available",
)
class InvalidAMIAttributeItemValueError(EC2ClientError):
def __init__(self, attribute: str, value: Union[str, Iterable[str], None]):
super().__init__(
"InvalidAMIAttributeItemValue",
f'Invalid attribute item value "{value}" for {attribute} item type.',
)
class MalformedAMIIdError(EC2ClientError):
def __init__(self, ami_id: list[str]):
super().__init__(
"InvalidAMIID.Malformed", f'Invalid id: "{ami_id}" (expecting "ami-...")'
)
class InvalidSnapshotIdError(EC2ClientError):
def __init__(self) -> None:
# Note: AWS returns empty message for this, as of 2014.08.22.
super().__init__("InvalidSnapshot.NotFound", "")
class InvalidSnapshotInUse(EC2ClientError):
def __init__(self, snapshot_id: str, ami_id: str):
super().__init__(
"InvalidSnapshot.InUse",
f"The snapshot {snapshot_id} is currently in use by {ami_id}",
)
class InvalidVolumeIdError(EC2ClientError):
def __init__(self, volume_id: Any):
super().__init__(
"InvalidVolume.NotFound", f"The volume '{volume_id}' does not exist."
)
class InvalidVolumeAttachmentError(EC2ClientError):
def __init__(self, volume_id: str, instance_id: str):
super().__init__(
"InvalidAttachment.NotFound",
f"Volume {volume_id} can not be detached from {instance_id} because it is not attached",
)
class InvalidVolumeDetachmentError(EC2ClientError):
def __init__(self, volume_id: str, instance_id: str, device: str):
super().__init__(
"InvalidAttachment.NotFound",
f"The volume {volume_id} is not attached to instance {instance_id} as device {device}",
)
class VolumeInUseError(EC2ClientError):
def __init__(self, volume_id: str, instance_id: str):
super().__init__(
"VolumeInUse",
f"Volume {volume_id} is currently attached to {instance_id}",
)
class InvalidAddressError(EC2ClientError):
def __init__(self, ip: Any):
super().__init__("InvalidAddress.NotFound", f"Address '{ip}' not found.")
class InvalidAllocationIdError(EC2ClientError):
def __init__(self, allocation_id: Any):
super().__init__(
"InvalidAllocationID.NotFound",
f"Allocation ID '{allocation_id}' not found.",
)
class InvalidAssociationIdError(EC2ClientError):
def __init__(self, association_id: Any):
super().__init__(
"InvalidAssociationID.NotFound",
f"Association ID '{association_id}' not found.",
)
class InvalidVpcCidrBlockAssociationIdError(EC2ClientError):
def __init__(self, association_id: str):
super().__init__(
"InvalidVpcCidrBlockAssociationIdError.NotFound",
f"The vpc CIDR block association ID '{association_id}' does not exist",
)
class InvalidVPCPeeringConnectionIdError(EC2ClientError):
def __init__(self, vpc_peering_connection_id: str):
super().__init__(
"InvalidVpcPeeringConnectionId.NotFound",
f"VpcPeeringConnectionID {vpc_peering_connection_id} does not exist.",
)
class InvalidVPCPeeringConnectionStateTransitionError(EC2ClientError):
def __init__(self, vpc_peering_connection_id: str):
super().__init__(
"InvalidStateTransition",
f"VpcPeeringConnectionID {vpc_peering_connection_id} is not in the correct state for the request.",
)
class InvalidServiceName(EC2ClientError):
def __init__(self, service_name: str):
super().__init__(
"InvalidServiceName",
f"The Vpc Endpoint Service '{service_name}' does not exist",
)
class InvalidFilter(EC2ClientError):
def __init__(self, filter_name: str, error_type: str = "InvalidFilter"):
super().__init__(error_type, f"The filter '{filter_name}' is invalid")
class InvalidNextToken(EC2ClientError):
def __init__(self, next_token: str):
super().__init__("InvalidNextToken", f"The token '{next_token}' is invalid")
class InvalidDependantParameterError(EC2ClientError):
def __init__(self, dependant_parameter: str, parameter: str, parameter_value: str):
super().__init__(
"InvalidParameter",
f"{dependant_parameter} can't be empty if {parameter} is {parameter_value}.",
)
class InvalidDependantParameterTypeError(EC2ClientError):
def __init__(self, dependant_parameter: str, parameter_value: str, parameter: str):
super().__init__(
"InvalidParameter",
f"{dependant_parameter} type must be {parameter_value} if {parameter} is provided.",
)
class InvalidAggregationIntervalParameterError(EC2ClientError):
def __init__(self, parameter: str):
super().__init__("InvalidParameter", f"Invalid {parameter}")
class InvalidParameterValueError(EC2ClientError):
def __init__(self, parameter_value: str):
super().__init__(
"InvalidParameterValue",
f"Value {parameter_value} is invalid for parameter.",
)
class InvalidParameterValueErrorPeeringAttachment(EC2ClientError):
def __init__(self, operation: str, transit_gateway_attachment_id: str):
super().__init__(
"InvalidParameterValue",
f"Cannot {operation} {transit_gateway_attachment_id} as the source of the peering request.",
)
class InvalidParameterValueErrorTagSpotFleetRequest(EC2ClientError):
def __init__(self, resource_type: str):
super().__init__(
"InvalidParameterValue",
f"The value for `ResourceType` must be `spot-fleet-request`, but got `{resource_type}` instead.",
)
class InvalidParameterValueErrorReplaceRoute(EC2ClientError):
def __init__(self, cidr: str):
super().__init__(
"InvalidParameterValue",
f"There is no route defined for '{cidr}' in the route table. Use CreateRoute instead.",
)
class EmptyTagSpecError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidParameterValue", "Tag specification must have at least one tag"
)
class InvalidParameterValueErrorTagNull(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidParameterValue",
"Tag value cannot be null. Use empty string instead.",
)
class InvalidParameterValueErrorUnknownAttribute(EC2ClientError):
def __init__(self, parameter_value: str):
super().__init__(
"InvalidParameterValue",
f"Value ({parameter_value}) for parameter attribute is invalid. Unknown attribute.",
)
class InvalidGatewayIDError(EC2ClientError):
def __init__(self, gateway_id: str):
super().__init__(
"InvalidGatewayID.NotFound", f"The eigw ID '{gateway_id}' does not exist"
)
class InvalidInternetGatewayIdError(EC2ClientError):
def __init__(self, internet_gateway_id: str):
super().__init__(
"InvalidInternetGatewayID.NotFound",
f"InternetGatewayID {internet_gateway_id} does not exist.",
)
class InvalidGroupIdMalformedError(EC2ClientError):
def __init__(self, group_id: str):
super().__init__(
"InvalidGroupId.Malformed",
f"The security group ID '{group_id}' is malformed",
)
class GatewayNotAttachedError(EC2ClientError):
def __init__(self, internet_gateway_id: str, vpc_id: str):
super().__init__(
"Gateway.NotAttached",
f"InternetGatewayID {internet_gateway_id} is not attached to a VPC {vpc_id}.",
)
class ResourceAlreadyAssociatedError(EC2ClientError):
def __init__(self, resource_id: str):
super().__init__(
"Resource.AlreadyAssociated",
f"Resource {resource_id} is already associated.",
)
class TagLimitExceeded(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"TagLimitExceeded",
"The maximum number of Tags for a resource has been reached.",
)
class InvalidID(EC2ClientError):
def __init__(self, resource_id: str):
super().__init__("InvalidID", f"The ID '{resource_id}' is not valid")
class InvalidCIDRSubnetError(EC2ClientError):
def __init__(self, cidr: Any):
super().__init__(
"InvalidParameterValue", f"invalid CIDR subnet specification: {cidr}"
)
class RulesPerSecurityGroupLimitExceededError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"RulesPerSecurityGroupLimitExceeded",
"The maximum number of rules per security group has been reached.",
)
class MotoNotImplementedError(NotImplementedError):
def __init__(self, blurb: str):
super().__init__(
f"{blurb} has not been implemented in Moto yet."
" Feel free to open an issue at"
" https://github.com/getmoto/moto/issues"
)
class FilterNotImplementedError(MotoNotImplementedError):
def __init__(self, filter_name: str, method_name: Optional[str]):
super().__init__(f"The filter '{filter_name}' for {method_name}")
class CidrLimitExceeded(EC2ClientError):
def __init__(self, vpc_id: str, max_cidr_limit: int):
super().__init__(
"CidrLimitExceeded",
f"This network {vpc_id} has met its maximum number of allowed CIDRs: {max_cidr_limit}",
)
class UnsupportedTenancy(EC2ClientError):
def __init__(self, tenancy: str):
super().__init__(
"UnsupportedTenancy", f"The tenancy value {tenancy} is not supported."
)
class VPCCidrBlockAssociationError(EC2ClientError):
def __init__(self, association_id: str):
super().__init__(
"OperationNotPermitted",
f"The vpc CIDR block with association ID {association_id} may not be disassociated. It is the primary IPv4 CIDR block of the VPC",
)
class OperationNotPermitted(EC2ClientError):
def __init__(self, message: str):
super().__init__("OperationNotPermitted", message)
class LastEniDetachError(OperationNotPermitted):
def __init__(self) -> None:
super().__init__(
"The network interface at device index 0 and networkCard index 0 cannot be detached."
)
class InvalidAvailabilityZoneError(EC2ClientError):
def __init__(
self, availability_zone_value: Optional[str], valid_availability_zones: str
):
super().__init__(
"InvalidParameterValue",
f"Value ({availability_zone_value}) for parameter availabilityZone is invalid. "
f"Subnets can currently only be created in the following availability zones: {valid_availability_zones}.",
)
class AvailabilityZoneNotFromRegionError(EC2ClientError):
def __init__(self, availability_zone_value: str):
super().__init__(
"InvalidParameterValue",
f"Invalid Availability Zone ({availability_zone_value})",
)
class NetworkAclEntryAlreadyExistsError(EC2ClientError):
def __init__(self, rule_number: int):
super().__init__(
"NetworkAclEntryAlreadyExists",
f"The network acl entry identified by {rule_number} already exists.",
)
class InvalidSubnetRangeError(EC2ClientError):
def __init__(self, cidr_block: str):
super().__init__("InvalidSubnet.Range", f"The CIDR '{cidr_block}' is invalid.")
class InvalidCIDRBlockParameterError(EC2ClientError):
def __init__(self, cidr_block: str):
super().__init__(
"InvalidParameterValue",
f"Value ({cidr_block}) for parameter cidrBlock is invalid. This is not a valid CIDR block.",
)
class InvalidDestinationCIDRBlockParameterError(EC2ClientError):
def __init__(self, cidr_block: str):
super().__init__(
"InvalidParameterValue",
f"Value ({cidr_block}) for parameter destinationCidrBlock is invalid. This is not a valid CIDR block.",
)
class InvalidSubnetConflictError(EC2ClientError):
def __init__(self, cidr_block: str):
super().__init__(
"InvalidSubnet.Conflict",
f"The CIDR '{cidr_block}' conflicts with another subnet",
)
class InvalidVPCRangeError(EC2ClientError):
def __init__(self, cidr_block: str):
super().__init__("InvalidVpc.Range", f"The CIDR '{cidr_block}' is invalid.")
# Raised when attempting to accept a VPC peering connection request in own account but in the requester region
class OperationNotPermitted2(EC2ClientError):
def __init__(self, client_region: str, pcx_id: str, acceptor_region: str):
super().__init__(
"OperationNotPermitted",
f"Incorrect region ({client_region}) specified for this request. "
f"VPC peering connection {pcx_id} must be accepted in region {acceptor_region}",
)
# Raised when attempting to reject a VPC peering connection request in own account but in the requester region
class OperationNotPermitted3(EC2ClientError):
def __init__(self, client_region: str, pcx_id: str, acceptor_region: str):
super().__init__(
"OperationNotPermitted",
f"Incorrect region ({client_region}) specified for this request. "
f"VPC peering connection {pcx_id} must be accepted or rejected in region {acceptor_region}",
)
class OperationNotPermitted4(EC2ClientError):
def __init__(self, instance_id: str):
super().__init__(
"OperationNotPermitted",
f"The instance '{instance_id}' may not be terminated. Modify its 'disableApiTermination' instance attribute and try again.",
)
class OperationDisableApiStopNotPermitted(EC2ClientError):
def __init__(self, instance_id: str):
super().__init__(
"OperationNotPermitted",
f"The instance '{instance_id}' may not be terminated. Modify its 'disableApiStop' instance attribute and try again.",
)
# Raised when attempting to accept or reject a VPC peering connection request for a VPC not belonging to self
class OperationNotPermitted5(EC2ClientError):
def __init__(self, account_id: str, pcx_id: str, operation: str):
super().__init__(
"OperationNotPermitted",
f"User ({account_id}) cannot {operation} peering {pcx_id}",
)
class InvalidLaunchTemplateNameAlreadyExistsError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidLaunchTemplateName.AlreadyExistsException",
"Launch template name already in use.",
)
class InvalidLaunchTemplateNameNotFoundError(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidLaunchTemplateName.NotFoundException",
"At least one of the launch templates specified in the request does not exist.",
)
class InvalidLaunchTemplateNameNotFoundWithNameError(EC2ClientError):
def __init__(self, name: str):
super().__init__(
"InvalidLaunchTemplateName.NotFoundException",
f"The specified launch template, with template name {name}, does not exist",
)
class InvalidParameterDependency(EC2ClientError):
def __init__(self, param: str, param_needed: str):
super().__init__(
"InvalidParameterDependency",
f"The parameter [{param}] requires the parameter {param_needed} to be set.",
)
class IncorrectStateIamProfileAssociationError(EC2ClientError):
def __init__(self, instance_id: str):
super().__init__(
"IncorrectState",
f"There is an existing association for instance {instance_id}",
)
class InvalidAssociationIDIamProfileAssociationError(EC2ClientError):
def __init__(self, association_id: str):
super().__init__(
"InvalidAssociationID.NotFound",
f"An invalid association-id of '{association_id}' was given",
)
class InvalidVpcEndPointIdError(EC2ClientError):
def __init__(self, vpc_end_point_id: str):
super().__init__(
"InvalidVpcEndpointId.NotFound",
f"The VpcEndPoint ID '{vpc_end_point_id}' does not exist",
)
class InvalidTaggableResourceType(EC2ClientError):
def __init__(self, resource_type: str):
super().__init__(
"InvalidParameterValue",
f"'{resource_type}' is not a valid taggable resource type for this operation.",
)
class GenericInvalidParameterValueError(EC2ClientError):
def __init__(self, attribute: str, value: str):
super().__init__(
"InvalidParameterValue",
f"invalid value for parameter {attribute}: {value}",
)
class InvalidParameter(EC2ClientError):
def __init__(self, message: str):
super().__init__(
"InvalidParameter",
message,
)
class InvalidParameterValue(EC2ClientError):
def __init__(self, message: str):
super().__init__(
"InvalidParameterValue",
message,
)
class MissingParameter(EC2ClientError):
def __init__(self, message: str):
super().__init__(
"MissingParameter",
message,
)
class InvalidSubnetCidrBlockAssociationID(EC2ClientError):
def __init__(self, association_id: str):
super().__init__(
"InvalidSubnetCidrBlockAssociationID.NotFound",
f"The subnet CIDR block with association ID '{association_id}' does not exist",
)
class InvalidCarrierGatewayID(EC2ClientError):
def __init__(self, carrier_gateway_id: str):
super().__init__(
"InvalidCarrierGatewayID.NotFound",
f"The CarrierGateway ID '{carrier_gateway_id}' does not exist",
)
class InvalidTransitGatewayID(EC2ClientError):
def __init__(self, transit_gateway_id: str, msg: Optional[str] = None):
super().__init__(
"InvalidTransitGatewayID.NotFound",
msg or f"The transitGateway ID '{transit_gateway_id}' does not exist",
)
class NoLoadBalancersProvided(EC2ClientError):
def __init__(self) -> None:
super().__init__(
"InvalidParameter",
"exactly one of network_load_balancer_arn or gateway_load_balancer_arn is a required member",
)
class UnknownVpcEndpointService(EC2ClientError):
def __init__(self, service_id: str):
super().__init__(
"InvalidVpcEndpointServiceId.NotFound",
f"The VpcEndpointService Id '{service_id}' does not exist",
)
class AuthFailureRestricted(RESTError):
"""Replicate real world issue https://github.com/aws/aws-cli/issues/1083"""
code = 401
def __init__(self) -> None:
super().__init__(
"AuthFailure",
"Unauthorized attempt to access restricted resource",
)
class InvalidUserDataError(EC2ClientError):
def __init__(self, message: str):
super().__init__(
"InvalidUserData.Malformed",
message,
)
|