11import json
22
3- from localstack .clients import BaseClient
43from localstack .sdk .api .aws_api import AwsApi
4+ from localstack .sdk .clients import BaseClient
55from localstack .sdk .models import (
66 Message ,
77 SesSentEmail ,
@@ -36,6 +36,12 @@ def _from_sqs_query_to_json(xml_dict: dict) -> list[Message]:
3636
3737
3838class AWSClient (BaseClient ):
39+ """
40+ The client to interact with all the LocalStack's AWS endpoints.
41+ These endpoints offer specific features in addition to the ones offered by the AWS services. For instance,
42+ access all the messages withing a SQS without the side effect of deleting them.
43+ """
44+
3945 def __init__ (self , ** kwargs ) -> None :
4046 super ().__init__ (** kwargs )
4147 self ._client = AwsApi (self ._api_client )
@@ -45,12 +51,26 @@ def __init__(self, **kwargs) -> None:
4551 ########
4652
4753 def list_sqs_messages (self , account_id : str , region : str , queue_name : str ) -> list [Message ]:
54+ """
55+ Lists all the SQS messages in a given queue in a specific account id and region, without any side effect.
56+
57+ :param account_id: the account id of the queue
58+ :param region: the region of the queue
59+ :param queue_name: the name of the queue
60+ :return: the list of messages in the queue
61+ """
4862 response = self ._client .list_sqs_messages_with_http_info (
4963 account_id = account_id , region = region , queue_name = queue_name
5064 )
5165 return _from_sqs_query_to_json (json .loads (response .raw_data ))
5266
53- def list_sqs_messages_from_queue_url (self , queue_url ) -> list [Message ]:
67+ def list_sqs_messages_from_queue_url (self , queue_url : str ) -> list [Message ]:
68+ """
69+ Lists all the SQS messages in a given queue, without any side effect.
70+
71+ :param queue_url: the URL of the queue
72+ :return: the list of messages in the queue
73+ """
5474 response = self ._client .list_all_sqs_messages_with_http_info (queue_url = queue_url )
5575 return _from_sqs_query_to_json (json .loads (response .raw_data ))
5676
@@ -61,10 +81,23 @@ def list_sqs_messages_from_queue_url(self, queue_url) -> list[Message]:
6181 def get_ses_messages (
6282 self , id_filter : str | None = None , email_filter : str | None = None
6383 ) -> list [SesSentEmail ]:
84+ """
85+ Returns all the in-memory saved SES messages. They can be filtered by message ID and/or message source.
86+
87+ :param id_filter: the message id used as filter for the SES messages
88+ :param email_filter: the message source filter
89+ :return: a list of email sent with SES
90+ """
6491 response = self ._client .get_ses_messages (id = id_filter , email = email_filter )
6592 return response .messages
6693
6794 def discard_ses_messages (self , id_filter : str | None = None ) -> None :
95+ """
96+ Clears all SES messages. An ID filter can be provided to delete only a specific message.
97+
98+ :param id_filter: the id filter
99+ :return: None
100+ """
68101 return self ._client .discard_ses_messages (id = id_filter )
69102
70103 ########
@@ -77,6 +110,15 @@ def get_sns_sms_messages(
77110 account_id : str = "000000000000" ,
78111 region : str = "us-east-1" ,
79112 ) -> SNSSMSMessagesResponse :
113+ """
114+ Returns all SMS messages published to a phone number.
115+
116+ :param phone_number: the phone number to which the messages have been published. If not specified, all messages
117+ are returned.
118+ :param account_id: the AWS Account ID from which the messages have been published. '000000000000' by default
119+ :param region: the AWS region from which the messages have been published. us-east-1 by default
120+ :return:
121+ """
80122 return self ._client .get_sns_sms_messages (
81123 phone_number = phone_number , account_id = account_id , region = region
82124 )
@@ -87,6 +129,15 @@ def discard_sns_sms_messages(
87129 account_id : str = "000000000000" ,
88130 region : str = "us-east-1" ,
89131 ) -> None :
132+ """
133+ Discards all SMS messages published to a phone number.
134+
135+ :param phone_number: the phone number to which the messages have been published. If not specified, all messages
136+ are deleted.
137+ :param account_id: the AWS Account ID from which the messages have been published. '000000000000' by default
138+ :param region: the AWS region from which the messages have been published. us-east-1 by default
139+ :return: None
140+ """
90141 return self ._client .discard_sns_sms_messages (
91142 phone_number = phone_number , account_id = account_id , region = region
92143 )
@@ -97,6 +148,15 @@ def get_sns_endpoint_messages(
97148 account_id : str = "000000000000" ,
98149 region : str = "us-east-1" ,
99150 ) -> SNSPlatformEndpointResponse :
151+ """
152+ Returns all the messages published to a platform endpoint.
153+
154+ :param endpoint_arn: the ARN to which the messages have been published. If not specified, will return all the
155+ messages.
156+ :param account_id: the AWS Account ID from which the messages have been published. 000000000000 if not specified
157+ :param region: the AWS region from which the messages have been published. us-east-1 by default
158+ :return: a response with the list of messages and the queried region
159+ """
100160 return self ._client .get_sns_endpoint_messages (
101161 endpoint_arn = endpoint_arn , account_id = account_id , region = region
102162 )
@@ -107,6 +167,15 @@ def discard_sns_endpoint_messages(
107167 account_id : str = "000000000000" ,
108168 region : str = "us-east-1" ,
109169 ) -> None :
170+ """
171+ Discards all the messaged published to a platform endpoint.
172+
173+ :param endpoint_arn: the ARN to which the messages have been published. If not specified, will discard all the
174+ messages.
175+ :param account_id: the AWS Account ID from which the messages have been published. 000000000000 if not specified
176+ :param region: the AWS region from which the messages have been published. us-east-1 by default
177+ :return: None
178+ """
110179 return self ._client .discard_sns_endpoint_messages (
111180 endpoint_arn = endpoint_arn , account_id = account_id , region = region
112181 )
0 commit comments