Best Python code snippet using localstack_python
move_stack_instances.py
Source:move_stack_instances.py  
...466	Do we need to do this?467	"""468def populate_new_stack_with_existing_stack_instances(faws_acct, fStack_instance_info, fNew_stack_name):469	"""470	response = client.import_stacks_to_stack_set(471	    StackSetName='string',472	    StackIds=[473	        'string',474	    ],475	    OperationPreferences={476	        'RegionConcurrencyType': 'SEQUENTIAL'|'PARALLEL',477	        'RegionOrder': [478	            'string',479	        ],480	        'FailureToleranceCount': 123,481	        'FailureTolerancePercentage': 123,482	        'MaxConcurrentCount': 123,483	        'MaxConcurrentPercentage': 123484	    },485	    OperationId='string',486	    CallAs='SELF'|'DELEGATED_ADMIN'487	)488	The Operation Id as the response is really important, because that's how we determine whether teh operation is done (or a success),489	so that we can add 10 more stacks... This can take a long time for a lot of instances...490	"""491	import logging492	stack_instance_ids = [stack_instance['StackId'] for stack_instance in fStack_instance_info493	                      if stack_instance['Status'] in ['CURRENT', 'OUTDATED', 'CREATE_COMPLETE', 'UPDATE_COMPLETE']]494	logging.info(f"Populating new stackset {fNew_stack_name} in account {faws_acct.acct_number} with stack_ids: {stack_instance_ids}")495	client_cfn = faws_acct.session.client('cloudformation')496	return_response = dict()497	try:498		response = client_cfn.import_stacks_to_stack_set(StackSetName=fNew_stack_name,499		                                                 StackIds=stack_instance_ids,500		                                                 OperationPreferences={501			                                                 'RegionConcurrencyType'     : 'PARALLEL',502			                                                 'FailureTolerancePercentage': 0,503			                                                 'MaxConcurrentPercentage'   : 100},504		                                                 CallAs='SELF')505		return_response['OperationId'] = response['OperationId']506		return_response['Success'] = True507	except client_cfn.exceptions.LimitExceededException as myError:508		logging.error(f"Limit Exceeded: {myError}")509		return_response['Success'] = False510		return_response['ErrorMessage'] = myError511	except client_cfn.exceptions.StackSetNotFoundException as myError:512		logging.error(f"Stack Set Not Found: {myError}")...retry.py
Source:retry.py  
...40    logger.info(f"Starting to migrate {len(instances)} instances into {stackset_name}")41    client = boto3.client("cloudformation")42    for i in range(0, len(instances), 10):43        logger.info(f"Import stack instances from {i} to {i+10}")44        response = client.import_stacks_to_stack_set(45            StackSetName=stackset_name,46            StackIds=instances[i : i + 10],47            OperationPreferences={48                "RegionConcurrencyType": "PARALLEL",49                "FailureToleranceCount": 10,50            },51        )52        wait_operation_is_complete(stackset_name, response["OperationId"])...import.py
Source:import.py  
...9    for stack_arn, stackset_name in stacks:10        get_stack_arn(account, stack)11        import_stack(stack_arn, stackset_name)12def import_stack(stack_arn, stackset_name):13    response = client.import_stacks_to_stack_set(14        StackSetName=stackset_name,15        StackIds=[ stack_arn,16        ],17        OperationPreferences={18            'RegionConcurrencyType': 'PARALLEL',19            'FailureTolerancePercentage': 10,20            'MaxConcurrentPercentage': 10021        },22        OperationId='ImportStackToStackSet',23        CallAs='SELF'24    )25def get_stack_arn(account_id, stackname):26    assume_role_into_account(account_id)27    response = client.describe_stacks(...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
