in aws/solutions/StackSetsResource/FunctionCode/lambda_function.py [0:0]
def update_stacks(set_region, set_name, accts, regions, param_overrides, ops_prefs):
# Wrapper for update_stack_instances
sleep_time = 15
retries = 60
this_try = 0
logger.info("Updating stack instances with op prefs {}".format(ops_prefs))
# UpdateStackInstance only allows stackSetName, not stackSetId,
# so we need to truncate.
(set_name, uid) = set_name.split(':')
logger.debug("StackSetName: {}, Accounts: {}, Regions: {}, ParameterOverrides: {}".format(
set_name, accts, regions, param_overrides))
while True:
try:
client = boto3.client('cloudformation', region_name=set_region)
response = client.update_stack_instances(
StackSetName=set_name,
Accounts=accts,
Regions=regions,
ParameterOverrides=param_overrides,
OperationPreferences=ops_prefs,
# OperationId='string'
)
return response
except ClientError as e:
if e.response['Error']['Code'] == 'OperationInProgressException':
this_try += 1
if this_try == retries:
logger.warning("Failed to update stack instances after {} tries".format(this_try))
raise Exception("Error updating stack instances: {}".format(e))
else:
logger.warning(
"Update stack instances operation in progress for {} in {}. Sleeping for {} seconds.".format(
set_name, set_region, sleep_time))
sleep(sleep_time)
continue
elif e.response['Error']['Code'] == 'Throttling':
this_try += 1
if this_try == retries:
logger.warning("Failed to update stack instances after {} tries".format(this_try))
raise Exception("Error updating stack instances: {}".format(e))
else:
logger.warning(
"Throttling exception encountered while updating stack instances. Backing off and retyring. "
"Sleeping for {} seconds.".format(sleep_time))
sleep(sleep_time)
continue
elif e.response['Error']['Code'] == 'StackSetNotFoundException':
raise Exception(
"No StackSet matching {} found in {}. You must create before updating stack instances.".format(
set_name, set_region))
else:
raise Exception("Unexpected error: {}".format(e))