55from moto .backup .models import BackupBackend , backup_backends
66from moto .core .base_backend import BackendDict , BaseBackend
77from moto .core .exceptions import RESTError
8+ from moto .dynamodb .models import DynamoDBBackend , dynamodb_backends
89from moto .ec2 import ec2_backends
910from moto .ecs .models import EC2ContainerServiceBackend , ecs_backends
1011from moto .elb .models import ELBBackend , elb_backends
@@ -110,6 +111,10 @@ def sqs_backend(self) -> SQSBackend:
110111 def backup_backend (self ) -> BackupBackend :
111112 return backup_backends [self .account_id ][self .region_name ]
112113
114+ @property
115+ def dynamodb_backend (self ) -> DynamoDBBackend :
116+ return dynamodb_backends [self .account_id ][self .region_name ]
117+
113118 def _get_resources_generator (
114119 self ,
115120 tag_filters : Optional [List [Dict [str , Any ]]] = None ,
@@ -198,7 +203,6 @@ def format_tag_keys(
198203
199204 # CloudFormation
200205 if not resource_type_filters or "cloudformation:stack" in resource_type_filters :
201-
202206 try :
203207 from moto .cloudformation import cloudformation_backends
204208
@@ -500,7 +504,6 @@ def format_tag_keys(
500504
501505 # SNS
502506 if not resource_type_filters or "sns" in resource_type_filters :
503-
504507 for topic in self .sns_backend .topics .values ():
505508 tags = format_tags (topic ._tags )
506509 if not tags or not tag_filter (
@@ -545,6 +548,21 @@ def format_tag_keys(
545548 "Tags" : tags ,
546549 }
547550
551+ if (
552+ not resource_type_filters
553+ or "dynamodb" in resource_type_filters
554+ or "dynamodb:table" in resource_type_filters
555+ ):
556+ for table in self .dynamodb_backend .tables .values ():
557+ tags = table .tags
558+
559+ if not tags or not tag_filter (tags ):
560+ continue
561+ yield {
562+ "ResourceARN" : table .table_arn ,
563+ "Tags" : tags ,
564+ }
565+
548566 def _get_tag_keys_generator (self ) -> Iterator [str ]:
549567 # Look at
550568 # https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
@@ -738,7 +756,6 @@ def get_resources(
738756 def get_tag_keys (
739757 self , pagination_token : Optional [str ] = None
740758 ) -> Tuple [Optional [str ], List [str ]]:
741-
742759 if pagination_token :
743760 if pagination_token not in self ._pages :
744761 raise RESTError (
@@ -786,7 +803,6 @@ def get_tag_keys(
786803 def get_tag_values (
787804 self , pagination_token : Optional [str ], key : str
788805 ) -> Tuple [Optional [str ], List [str ]]:
789-
790806 if pagination_token :
791807 if pagination_token not in self ._pages :
792808 raise RESTError (
@@ -835,7 +851,7 @@ def tag_resources(
835851 self , resource_arns : List [str ], tags : Dict [str , str ]
836852 ) -> Dict [str , Dict [str , Any ]]:
837853 """
838- Only Logs and RDS resources are currently supported
854+ Only DynamoDB, Logs and RDS resources are currently supported
839855 """
840856 missing_resources = []
841857 missing_error : Dict [str , Any ] = {
@@ -850,6 +866,10 @@ def tag_resources(
850866 )
851867 if arn .startswith ("arn:aws:logs:" ):
852868 self .logs_backend .tag_resource (arn , tags )
869+ if arn .startswith ("arn:aws:dynamodb" ):
870+ self .dynamodb_backend .tag_resource (
871+ arn , TaggingService .convert_dict_to_tags_input (tags )
872+ )
853873 else :
854874 missing_resources .append (arn )
855875 return {arn : missing_error for arn in missing_resources }
0 commit comments