7
7
8
8
import localstack .services .cloudformation .provider_utils as util
9
9
from localstack import config
10
+ from localstack .aws .connect import ServiceLevelClientFactory
10
11
from localstack .services .cloudformation .resource_provider import (
11
12
ConvertingInternalClientFactory ,
12
13
OperationStatus ,
@@ -64,18 +65,7 @@ def create(
64
65
65
66
"""
66
67
model = request .desired_state
67
- if subscription_region := model .get ("Region" ):
68
- # FIXME: this is hacky, maybe we should have access to the original parameters for the `aws_client_factory`
69
- # as we now need to manually use them
70
- # Not all internal CloudFormation requests will be directed to the same region and account
71
- # maybe we could need to expose a proper client factory where we can override some parameters like the
72
- # Region
73
- factory = ConvertingInternalClientFactory (use_ssl = config .DISTRIBUTED_MODE )
74
- client_params = dict (request .aws_client_factory ._client_creation_params )
75
- client_params ["region_name" ] = subscription_region
76
- sns = factory (** client_params ).sns
77
- else :
78
- sns = request .aws_client_factory .sns
68
+ sns = self ._get_client (request ).sns
79
69
80
70
params = util .select_attributes (model = model , params = ["TopicArn" , "Protocol" , "Endpoint" ])
81
71
@@ -141,7 +131,7 @@ def update(
141
131
"""
142
132
model = request .desired_state
143
133
model ["Id" ] = request .previous_state ["Id" ]
144
- sns = request . aws_client_factory .sns
134
+ sns = self . _get_client ( request ) .sns
145
135
146
136
attrs = [
147
137
"DeliveryPolicy" ,
@@ -166,3 +156,23 @@ def update(
166
156
@staticmethod
167
157
def attr_val (val ):
168
158
return json .dumps (val ) if isinstance (val , dict ) else str (val )
159
+
160
+ @staticmethod
161
+ def _get_client (
162
+ request : ResourceRequest [SNSSubscriptionProperties ],
163
+ ) -> ServiceLevelClientFactory :
164
+ model = request .desired_state
165
+ if subscription_region := model .get ("Region" ):
166
+ # FIXME: this is hacky, maybe we should have access to the original parameters for the `aws_client_factory`
167
+ # as we now need to manually use them
168
+ # Not all internal CloudFormation requests will be directed to the same region and account
169
+ # maybe we could need to expose a proper client factory where we can override some parameters like the
170
+ # Region
171
+ factory = ConvertingInternalClientFactory (use_ssl = config .DISTRIBUTED_MODE )
172
+ client_params = dict (request .aws_client_factory ._client_creation_params )
173
+ client_params ["region_name" ] = subscription_region
174
+ service_factory = factory (** client_params )
175
+ else :
176
+ service_factory = request .aws_client_factory
177
+
178
+ return service_factory
0 commit comments