@@ -180,6 +180,9 @@ def _handle_get_application_request(self, app_id, semver, key, logical_id):
180
180
warning_message = "{}. Unable to verify access to {}/{}." .format (e , app_id , semver )
181
181
LOG .warning (warning_message )
182
182
self ._applications [key ] = {"Unable to verify" }
183
+ except ClientError as e :
184
+ LOG .exception (e )
185
+ raise e
183
186
184
187
def _handle_create_cfn_template_request (self , app_id , semver , key , logical_id ):
185
188
"""
@@ -194,7 +197,12 @@ def _handle_create_cfn_template_request(self, app_id, semver, key, logical_id):
194
197
create_cfn_template = lambda app_id , semver : self ._sar_client .create_cloud_formation_template (
195
198
ApplicationId = self ._sanitize_sar_str_param (app_id ), SemanticVersion = self ._sanitize_sar_str_param (semver )
196
199
)
197
- response = self ._sar_service_call (create_cfn_template , logical_id , app_id , semver )
200
+ try :
201
+ response = self ._sar_service_call (create_cfn_template , logical_id , app_id , semver )
202
+ except ClientError as e :
203
+ LOG .exception (e )
204
+ raise e
205
+
198
206
LOG .info ("Requested to create CFN template {}/{} in serverless application repo." .format (app_id , semver ))
199
207
self ._applications [key ] = response [self .TEMPLATE_URL_KEY ]
200
208
if response ["Status" ] != "ACTIVE" :
@@ -308,6 +316,7 @@ def on_after_transform_template(self, template):
308
316
while (time () - start_time ) < self .TEMPLATE_WAIT_TIMEOUT_SECONDS :
309
317
temp = self ._in_progress_templates
310
318
self ._in_progress_templates = []
319
+ throttled = False
311
320
312
321
# Check each resource to make sure it's active
313
322
LOG .info ("Checking resources in serverless application repo..." )
@@ -318,8 +327,26 @@ def on_after_transform_template(self, template):
318
327
TemplateId = self ._sanitize_sar_str_param (template_id ),
319
328
)
320
329
)
321
- response = self ._sar_service_call (get_cfn_template , application_id , application_id , template_id )
330
+ response = {"Status" : "PREPARING" } # default response if we can't reach SAR
331
+
332
+ try :
333
+ if not throttled :
334
+ response = self ._sar_service_call (
335
+ get_cfn_template , application_id , application_id , template_id
336
+ )
337
+ except ClientError as e :
338
+ error_code = e .response ["Error" ]["Code" ]
339
+ if error_code == "TooManyRequestsException" :
340
+ # We were throttled by SAR, don't hammer SAR with more calls in this for loop
341
+ throttled = True
342
+ LOG .debug ("SAR call timed out for application id {}" .format (application_id ))
343
+ # don't re-raise, fall through to regular processing as if the template wasn't ready yet
344
+ else :
345
+ LOG .exception (e )
346
+ raise e
347
+
322
348
self ._handle_get_cfn_template_response (response , application_id , template_id )
349
+
323
350
LOG .info ("Finished checking resources in serverless application repo." )
324
351
325
352
# Don't sleep if there are no more templates with PREPARING status
@@ -372,9 +399,6 @@ def _sar_service_call(self, service_call_lambda, logical_id, *args):
372
399
error_code = e .response ["Error" ]["Code" ]
373
400
if error_code in ("AccessDeniedException" , "NotFoundException" ):
374
401
raise InvalidResourceException (logical_id , e .response ["Error" ]["Message" ])
375
-
376
- # 'ForbiddenException'- SAR rejects connection
377
- LOG .exception (e )
378
402
raise e
379
403
380
404
def _resource_is_supported (self , resource_type ):
0 commit comments