1
1
import json
2
2
3
- from localstack .clients import BaseClient
4
3
from localstack .sdk .api .aws_api import AwsApi
4
+ from localstack .sdk .clients import BaseClient
5
5
from localstack .sdk .models import (
6
6
Message ,
7
7
SesSentEmail ,
@@ -36,6 +36,12 @@ def _from_sqs_query_to_json(xml_dict: dict) -> list[Message]:
36
36
37
37
38
38
class 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
+
39
45
def __init__ (self , ** kwargs ) -> None :
40
46
super ().__init__ (** kwargs )
41
47
self ._client = AwsApi (self ._api_client )
@@ -45,12 +51,26 @@ def __init__(self, **kwargs) -> None:
45
51
########
46
52
47
53
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
+ """
48
62
response = self ._client .list_sqs_messages_with_http_info (
49
63
account_id = account_id , region = region , queue_name = queue_name
50
64
)
51
65
return _from_sqs_query_to_json (json .loads (response .raw_data ))
52
66
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
+ """
54
74
response = self ._client .list_all_sqs_messages_with_http_info (queue_url = queue_url )
55
75
return _from_sqs_query_to_json (json .loads (response .raw_data ))
56
76
@@ -61,10 +81,23 @@ def list_sqs_messages_from_queue_url(self, queue_url) -> list[Message]:
61
81
def get_ses_messages (
62
82
self , id_filter : str | None = None , email_filter : str | None = None
63
83
) -> 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
+ """
64
91
response = self ._client .get_ses_messages (id = id_filter , email = email_filter )
65
92
return response .messages
66
93
67
94
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
+ """
68
101
return self ._client .discard_ses_messages (id = id_filter )
69
102
70
103
########
@@ -77,6 +110,15 @@ def get_sns_sms_messages(
77
110
account_id : str = "000000000000" ,
78
111
region : str = "us-east-1" ,
79
112
) -> 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
+ """
80
122
return self ._client .get_sns_sms_messages (
81
123
phone_number = phone_number , account_id = account_id , region = region
82
124
)
@@ -87,6 +129,15 @@ def discard_sns_sms_messages(
87
129
account_id : str = "000000000000" ,
88
130
region : str = "us-east-1" ,
89
131
) -> 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
+ """
90
141
return self ._client .discard_sns_sms_messages (
91
142
phone_number = phone_number , account_id = account_id , region = region
92
143
)
@@ -97,6 +148,15 @@ def get_sns_endpoint_messages(
97
148
account_id : str = "000000000000" ,
98
149
region : str = "us-east-1" ,
99
150
) -> 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
+ """
100
160
return self ._client .get_sns_endpoint_messages (
101
161
endpoint_arn = endpoint_arn , account_id = account_id , region = region
102
162
)
@@ -107,6 +167,15 @@ def discard_sns_endpoint_messages(
107
167
account_id : str = "000000000000" ,
108
168
region : str = "us-east-1" ,
109
169
) -> 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
+ """
110
179
return self ._client .discard_sns_endpoint_messages (
111
180
endpoint_arn = endpoint_arn , account_id = account_id , region = region
112
181
)
0 commit comments