How to use create_stack_set method in localstack

Best Python code snippet using localstack_python

test_cloudformation_stack_crud_boto3.py

Source:test_cloudformation_stack_crud_boto3.py Github

copy

Full Screen

...171dummy_redrive_template_json = json.dumps(dummy_redrive_template)172@mock_cloudformation173def test_boto3_describe_stack_instances():174 cf_conn = boto3.client('cloudformation', region_name='us-east-1')175 cf_conn.create_stack_set(176 StackSetName="test_stack_set",177 TemplateBody=dummy_template_json,178 )179 cf_conn.create_stack_instances(180 StackSetName="test_stack_set",181 Accounts=['123456789012'],182 Regions=['us-east-1', 'us-west-2'],183 )184 usw2_instance = cf_conn.describe_stack_instance(185 StackSetName="test_stack_set",186 StackInstanceAccount='123456789012',187 StackInstanceRegion='us-west-2',188 )189 use1_instance = cf_conn.describe_stack_instance(190 StackSetName="test_stack_set",191 StackInstanceAccount='123456789012',192 StackInstanceRegion='us-east-1',193 )194 usw2_instance['StackInstance'].should.have.key('Region').which.should.equal('us-west-2')195 usw2_instance['StackInstance'].should.have.key('Account').which.should.equal('123456789012')196 use1_instance['StackInstance'].should.have.key('Region').which.should.equal('us-east-1')197 use1_instance['StackInstance'].should.have.key('Account').which.should.equal('123456789012')198@mock_cloudformation199def test_boto3_list_stacksets_length():200 cf_conn = boto3.client('cloudformation', region_name='us-east-1')201 cf_conn.create_stack_set(202 StackSetName="test_stack_set",203 TemplateBody=dummy_template_json,204 )205 cf_conn.create_stack_set(206 StackSetName="test_stack_set2",207 TemplateBody=dummy_template_yaml,208 )209 stacksets = cf_conn.list_stack_sets()210 stacksets.should.have.length_of(2)211@mock_cloudformation212def test_boto3_list_stacksets_contents():213 cf_conn = boto3.client('cloudformation', region_name='us-east-1')214 cf_conn.create_stack_set(215 StackSetName="test_stack_set",216 TemplateBody=dummy_template_json,217 )218 stacksets = cf_conn.list_stack_sets()219 stacksets['Summaries'][0].should.have.key('StackSetName').which.should.equal('test_stack_set')220 stacksets['Summaries'][0].should.have.key('Status').which.should.equal('ACTIVE')221@mock_cloudformation222def test_boto3_stop_stack_set_operation():223 cf_conn = boto3.client('cloudformation', region_name='us-east-1')224 cf_conn.create_stack_set(225 StackSetName="test_stack_set",226 TemplateBody=dummy_template_json,227 )228 cf_conn.create_stack_instances(229 StackSetName="test_stack_set",230 Accounts=['123456789012'],231 Regions=['us-east-1', 'us-west-1', 'us-west-2'],232 )233 operation_id = cf_conn.list_stack_set_operations(234 StackSetName="test_stack_set")['Summaries'][-1]['OperationId']235 cf_conn.stop_stack_set_operation(236 StackSetName="test_stack_set",237 OperationId=operation_id238 )239 list_operation = cf_conn.list_stack_set_operations(240 StackSetName="test_stack_set"241 )242 list_operation['Summaries'][-1]['Status'].should.equal('STOPPED')243@mock_cloudformation244def test_boto3_describe_stack_set_operation():245 cf_conn = boto3.client('cloudformation', region_name='us-east-1')246 cf_conn.create_stack_set(247 StackSetName="test_stack_set",248 TemplateBody=dummy_template_json,249 )250 cf_conn.create_stack_instances(251 StackSetName="test_stack_set",252 Accounts=['123456789012'],253 Regions=['us-east-1', 'us-west-1', 'us-west-2'],254 )255 operation_id = cf_conn.list_stack_set_operations(256 StackSetName="test_stack_set")['Summaries'][-1]['OperationId']257 cf_conn.stop_stack_set_operation(258 StackSetName="test_stack_set",259 OperationId=operation_id260 )261 response = cf_conn.describe_stack_set_operation(262 StackSetName="test_stack_set",263 OperationId=operation_id,264 )265 response['StackSetOperation']['Status'].should.equal('STOPPED')266 response['StackSetOperation']['Action'].should.equal('CREATE')267@mock_cloudformation268def test_boto3_list_stack_set_operation_results():269 cf_conn = boto3.client('cloudformation', region_name='us-east-1')270 cf_conn.create_stack_set(271 StackSetName="test_stack_set",272 TemplateBody=dummy_template_json,273 )274 cf_conn.create_stack_instances(275 StackSetName="test_stack_set",276 Accounts=['123456789012'],277 Regions=['us-east-1', 'us-west-1', 'us-west-2'],278 )279 operation_id = cf_conn.list_stack_set_operations(280 StackSetName="test_stack_set")['Summaries'][-1]['OperationId']281 cf_conn.stop_stack_set_operation(282 StackSetName="test_stack_set",283 OperationId=operation_id284 )285 response = cf_conn.list_stack_set_operation_results(286 StackSetName="test_stack_set",287 OperationId=operation_id,288 )289 response['Summaries'].should.have.length_of(3)290 response['Summaries'][0].should.have.key('Account').which.should.equal('123456789012')291 response['Summaries'][1].should.have.key('Status').which.should.equal('STOPPED')292@mock_cloudformation293def test_boto3_update_stack_instances():294 cf_conn = boto3.client('cloudformation', region_name='us-east-1')295 param = [296 {'ParameterKey': 'SomeParam', 'ParameterValue': 'StackSetValue'},297 {'ParameterKey': 'AnotherParam', 'ParameterValue': 'StackSetValue2'},298 ]299 param_overrides = [300 {'ParameterKey': 'SomeParam', 'ParameterValue': 'OverrideValue'},301 {'ParameterKey': 'AnotherParam', 'ParameterValue': 'OverrideValue2'}302 ]303 cf_conn.create_stack_set(304 StackSetName="test_stack_set",305 TemplateBody=dummy_template_yaml_with_ref,306 Parameters=param,307 )308 cf_conn.create_stack_instances(309 StackSetName="test_stack_set",310 Accounts=['123456789012'],311 Regions=['us-east-1', 'us-west-1', 'us-west-2'],312 )313 cf_conn.update_stack_instances(314 StackSetName="test_stack_set",315 Accounts=['123456789012'],316 Regions=['us-west-1', 'us-west-2'],317 ParameterOverrides=param_overrides,318 )319 usw2_instance = cf_conn.describe_stack_instance(320 StackSetName="test_stack_set",321 StackInstanceAccount='123456789012',322 StackInstanceRegion='us-west-2',323 )324 usw1_instance = cf_conn.describe_stack_instance(325 StackSetName="test_stack_set",326 StackInstanceAccount='123456789012',327 StackInstanceRegion='us-west-1',328 )329 use1_instance = cf_conn.describe_stack_instance(330 StackSetName="test_stack_set",331 StackInstanceAccount='123456789012',332 StackInstanceRegion='us-east-1',333 )334 usw2_instance['StackInstance']['ParameterOverrides'][0]['ParameterKey'].should.equal(param_overrides[0]['ParameterKey'])335 usw2_instance['StackInstance']['ParameterOverrides'][0]['ParameterValue'].should.equal(param_overrides[0]['ParameterValue'])336 usw2_instance['StackInstance']['ParameterOverrides'][1]['ParameterKey'].should.equal(param_overrides[1]['ParameterKey'])337 usw2_instance['StackInstance']['ParameterOverrides'][1]['ParameterValue'].should.equal(param_overrides[1]['ParameterValue'])338 usw1_instance['StackInstance']['ParameterOverrides'][0]['ParameterKey'].should.equal(param_overrides[0]['ParameterKey'])339 usw1_instance['StackInstance']['ParameterOverrides'][0]['ParameterValue'].should.equal(param_overrides[0]['ParameterValue'])340 usw1_instance['StackInstance']['ParameterOverrides'][1]['ParameterKey'].should.equal(param_overrides[1]['ParameterKey'])341 usw1_instance['StackInstance']['ParameterOverrides'][1]['ParameterValue'].should.equal(param_overrides[1]['ParameterValue'])342 use1_instance['StackInstance']['ParameterOverrides'].should.be.empty343@mock_cloudformation344def test_boto3_delete_stack_instances():345 cf_conn = boto3.client('cloudformation', region_name='us-east-1')346 cf_conn.create_stack_set(347 StackSetName="test_stack_set",348 TemplateBody=dummy_template_json,349 )350 cf_conn.create_stack_instances(351 StackSetName="test_stack_set",352 Accounts=['123456789012'],353 Regions=['us-east-1', 'us-west-2'],354 )355 cf_conn.delete_stack_instances(356 StackSetName="test_stack_set",357 Accounts=['123456789012'],358 Regions=['us-east-1'],359 RetainStacks=False,360 )361 cf_conn.list_stack_instances(StackSetName="test_stack_set")['Summaries'].should.have.length_of(1)362 cf_conn.list_stack_instances(StackSetName="test_stack_set")['Summaries'][0]['Region'].should.equal(363 'us-west-2')364@mock_cloudformation365def test_boto3_create_stack_instances():366 cf_conn = boto3.client('cloudformation', region_name='us-east-1')367 cf_conn.create_stack_set(368 StackSetName="test_stack_set",369 TemplateBody=dummy_template_json,370 )371 cf_conn.create_stack_instances(372 StackSetName="test_stack_set",373 Accounts=['123456789012'],374 Regions=['us-east-1', 'us-west-2'],375 )376 cf_conn.list_stack_instances(StackSetName="test_stack_set")['Summaries'].should.have.length_of(2)377 cf_conn.list_stack_instances(StackSetName="test_stack_set")['Summaries'][0]['Account'].should.equal(378 '123456789012')379@mock_cloudformation380def test_boto3_create_stack_instances_with_param_overrides():381 cf_conn = boto3.client('cloudformation', region_name='us-east-1')382 param = [383 {'ParameterKey': 'TagDescription', 'ParameterValue': 'StackSetValue'},384 {'ParameterKey': 'TagName', 'ParameterValue': 'StackSetValue2'},385 ]386 param_overrides = [387 {'ParameterKey': 'TagDescription', 'ParameterValue': 'OverrideValue'},388 {'ParameterKey': 'TagName', 'ParameterValue': 'OverrideValue2'}389 ]390 cf_conn.create_stack_set(391 StackSetName="test_stack_set",392 TemplateBody=dummy_template_yaml_with_ref,393 Parameters=param,394 )395 cf_conn.create_stack_instances(396 StackSetName="test_stack_set",397 Accounts=['123456789012'],398 Regions=['us-east-1', 'us-west-2'],399 ParameterOverrides=param_overrides,400 )401 usw2_instance = cf_conn.describe_stack_instance(402 StackSetName="test_stack_set",403 StackInstanceAccount='123456789012',404 StackInstanceRegion='us-west-2',405 )406 usw2_instance['StackInstance']['ParameterOverrides'][0]['ParameterKey'].should.equal(param_overrides[0]['ParameterKey'])407 usw2_instance['StackInstance']['ParameterOverrides'][1]['ParameterKey'].should.equal(param_overrides[1]['ParameterKey'])408 usw2_instance['StackInstance']['ParameterOverrides'][0]['ParameterValue'].should.equal(param_overrides[0]['ParameterValue'])409 usw2_instance['StackInstance']['ParameterOverrides'][1]['ParameterValue'].should.equal(param_overrides[1]['ParameterValue'])410@mock_cloudformation411def test_update_stack_set():412 cf_conn = boto3.client('cloudformation', region_name='us-east-1')413 param = [414 {'ParameterKey': 'TagDescription', 'ParameterValue': 'StackSetValue'},415 {'ParameterKey': 'TagName', 'ParameterValue': 'StackSetValue2'},416 ]417 param_overrides = [418 {'ParameterKey': 'TagDescription', 'ParameterValue': 'OverrideValue'},419 {'ParameterKey': 'TagName', 'ParameterValue': 'OverrideValue2'}420 ]421 cf_conn.create_stack_set(422 StackSetName="test_stack_set",423 TemplateBody=dummy_template_yaml_with_ref,424 Parameters=param,425 )426 cf_conn.update_stack_set(427 StackSetName='test_stack_set',428 TemplateBody=dummy_template_yaml_with_ref,429 Parameters=param_overrides,430 )431 stackset = cf_conn.describe_stack_set(StackSetName='test_stack_set')432 stackset['StackSet']['Parameters'][0]['ParameterValue'].should.equal(param_overrides[0]['ParameterValue'])433 stackset['StackSet']['Parameters'][1]['ParameterValue'].should.equal(param_overrides[1]['ParameterValue'])434 stackset['StackSet']['Parameters'][0]['ParameterKey'].should.equal(param_overrides[0]['ParameterKey'])435 stackset['StackSet']['Parameters'][1]['ParameterKey'].should.equal(param_overrides[1]['ParameterKey'])436@mock_cloudformation437def test_boto3_list_stack_set_operations():438 cf_conn = boto3.client('cloudformation', region_name='us-east-1')439 cf_conn.create_stack_set(440 StackSetName="test_stack_set",441 TemplateBody=dummy_template_json,442 )443 cf_conn.create_stack_instances(444 StackSetName="test_stack_set",445 Accounts=['123456789012'],446 Regions=['us-east-1', 'us-west-2'],447 )448 cf_conn.update_stack_instances(449 StackSetName="test_stack_set",450 Accounts=['123456789012'],451 Regions=['us-east-1', 'us-west-2'],452 )453 list_operation = cf_conn.list_stack_set_operations(StackSetName="test_stack_set")454 list_operation['Summaries'].should.have.length_of(2)455 list_operation['Summaries'][-1]['Action'].should.equal('UPDATE')456@mock_cloudformation457def test_boto3_delete_stack_set():458 cf_conn = boto3.client('cloudformation', region_name='us-east-1')459 cf_conn.create_stack_set(460 StackSetName="test_stack_set",461 TemplateBody=dummy_template_json,462 )463 cf_conn.delete_stack_set(StackSetName='test_stack_set')464 cf_conn.describe_stack_set(StackSetName="test_stack_set")['StackSet']['Status'].should.equal(465 'DELETED')466@mock_cloudformation467def test_boto3_create_stack_set():468 cf_conn = boto3.client('cloudformation', region_name='us-east-1')469 cf_conn.create_stack_set(470 StackSetName="test_stack_set",471 TemplateBody=dummy_template_json,472 )473 cf_conn.describe_stack_set(StackSetName="test_stack_set")['StackSet']['TemplateBody'].should.equal(474 dummy_template_json)475@mock_cloudformation476def test_boto3_create_stack_set_with_yaml():477 cf_conn = boto3.client('cloudformation', region_name='us-east-1')478 cf_conn.create_stack_set(479 StackSetName="test_stack_set",480 TemplateBody=dummy_template_yaml,481 )482 cf_conn.describe_stack_set(StackSetName="test_stack_set")['StackSet']['TemplateBody'].should.equal(483 dummy_template_yaml)484@mock_cloudformation485@mock_s3486def test_create_stack_set_from_s3_url():487 s3 = boto3.client('s3')488 s3_conn = boto3.resource('s3')489 bucket = s3_conn.create_bucket(Bucket="foobar")490 key = s3_conn.Object(491 'foobar', 'template-key').put(Body=dummy_template_json)492 key_url = s3.generate_presigned_url(493 ClientMethod='get_object',494 Params={495 'Bucket': 'foobar',496 'Key': 'template-key'497 }498 )499 cf_conn = boto3.client('cloudformation', region_name='us-west-1')500 cf_conn.create_stack_set(501 StackSetName='stack_from_url',502 TemplateURL=key_url,503 )504 cf_conn.describe_stack_set(StackSetName="stack_from_url")['StackSet']['TemplateBody'].should.equal(505 dummy_template_json)506@mock_cloudformation507def test_boto3_create_stack_set_with_ref_yaml():508 cf_conn = boto3.client('cloudformation', region_name='us-east-1')509 params = [510 {'ParameterKey': 'TagDescription', 'ParameterValue': 'desc_ref'},511 {'ParameterKey': 'TagName', 'ParameterValue': 'name_ref'},512 ]513 cf_conn.create_stack_set(514 StackSetName="test_stack",515 TemplateBody=dummy_template_yaml_with_ref,516 Parameters=params517 )518 cf_conn.describe_stack_set(StackSetName="test_stack")['StackSet']['TemplateBody'].should.equal(519 dummy_template_yaml_with_ref)520@mock_cloudformation521def test_boto3_describe_stack_set_params():522 cf_conn = boto3.client('cloudformation', region_name='us-east-1')523 params = [524 {'ParameterKey': 'TagDescription', 'ParameterValue': 'desc_ref'},525 {'ParameterKey': 'TagName', 'ParameterValue': 'name_ref'},526 ]527 cf_conn.create_stack_set(528 StackSetName="test_stack",529 TemplateBody=dummy_template_yaml_with_ref,530 Parameters=params531 )532 cf_conn.describe_stack_set(StackSetName="test_stack")['StackSet']['Parameters'].should.equal(533 params)534@mock_cloudformation535def test_boto3_create_stack():536 cf_conn = boto3.client('cloudformation', region_name='us-east-1')537 cf_conn.create_stack(538 StackName="test_stack",539 TemplateBody=dummy_template_json,540 )541 cf_conn.get_template(StackName="test_stack")['TemplateBody'].should.equal(...

Full Screen

Full Screen

cloudformation.py

Source:cloudformation.py Github

copy

Full Screen

...62 )63 def createStackSet(self, cftemplate, stackname, iamcapable=None):64 if iamcapable:65 if cftemplate and not isinstance(cftemplate, dict) and cftemplate.startswith('https://s3'):66 response = self.cfClient.create_stack_set(67 StackSetName=stackname,68 TemplateURL=cftemplate,69 Capabilities=iamcapable70 )71 else:72 response = self.cfClient.create_stack_set(73 StackSetName=stackname,74 TemplateBody=json.dumps(cftemplate),75 Capabilities=iamcapable76 )77 else:78 if cftemplate and not isinstance(cftemplate, dict) and cftemplate.startswith('https://s3'):79 response = self.cfClient.create_stack_set(80 StackSetName=stackname,81 TemplateURL=cftemplate82 )83 else:84 response = self.cfClient.create_stack_set(85 StackSetName=stackname,86 TemplateBody=json.dumps(cftemplate)87 )88 return response89 def updateStackSet(self, cftemplate, stackname, iamcapable=None):90 if iamcapable:91 if cftemplate and not isinstance(cftemplate, dict) and cftemplate.startswith('https://s3'):92 response = self.cfClient.update_stack(93 StackSetName=stackname,94 TemplateURL=cftemplate,95 Capabilities=iamcapable96 )97 else:98 response = self.cfClient.update_stack(...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful