How to use get_stack_policy method in localstack

Best Python code snippet using localstack_python

cloudformation_facts.py

Source:cloudformation_facts.py Github

copy

Full Screen

...187 func = partial(self.client.describe_stack_events, StackName=stack_name)188 return self.paginated_response(func, 'StackEvents')189 except Exception as e:190 self.module.fail_json(msg="Error describing stack events - " + str(e), exception=traceback.format_exc())191 def get_stack_policy(self, stack_name):192 try:193 response = self.client.get_stack_policy(StackName=stack_name)194 stack_policy = response.get('StackPolicyBody')195 if stack_policy:196 return json.loads(stack_policy)197 return dict()198 except Exception as e:199 self.module.fail_json(msg="Error getting stack policy - " + str(e), exception=traceback.format_exc())200 def get_template(self, stack_name):201 try:202 response = self.client.get_template(StackName=stack_name)203 return response.get('TemplateBody')204 except Exception as e:205 self.module.fail_json(msg="Error getting stack template - " + str(e), exception=traceback.format_exc())206 def paginated_response(self, func, result_key, next_token=None):207 '''208 Returns expanded response for paginated operations.209 The 'result_key' is used to define the concatenated results that are combined from each paginated response.210 '''211 args = dict()212 if next_token:213 args['NextToken'] = next_token214 response = func(**args)215 result = response.get(result_key)216 next_token = response.get('NextToken')217 if not next_token:218 return result219 return result + self.paginated_response(func, result_key, next_token)220def to_dict(items, key, value):221 ''' Transforms a list of items to a Key/Value dictionary '''222 if items:223 return dict(zip([i[key] for i in items], [i[value] for i in items]))224 else:225 return dict()226def main():227 argument_spec = ec2_argument_spec()228 argument_spec.update(dict(229 stack_name=dict(),230 all_facts=dict(required=False, default=False, type='bool'),231 stack_policy=dict(required=False, default=False, type='bool'),232 stack_events=dict(required=False, default=False, type='bool'),233 stack_resources=dict(required=False, default=False, type='bool'),234 stack_template=dict(required=False, default=False, type='bool'),235 ))236 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=False)237 if not HAS_BOTO3:238 module.fail_json(msg='boto3 is required.')239 service_mgr = CloudFormationServiceManager(module)240 result = {'ansible_facts': {'cloudformation': {}}}241 for stack_description in service_mgr.describe_stacks(module.params.get('stack_name')):242 facts = {'stack_description': stack_description}243 stack_name = stack_description.get('StackName')244 # Create stack output and stack parameter dictionaries245 if facts['stack_description']:246 facts['stack_outputs'] = to_dict(facts['stack_description'].get('Outputs'), 'OutputKey', 'OutputValue')247 facts['stack_parameters'] = to_dict(facts['stack_description'].get('Parameters'), 'ParameterKey', 'ParameterValue')248 facts['stack_tags'] = boto3_tag_list_to_ansible_dict(facts['stack_description'].get('Tags'))249 # normalize stack description API output250 facts['stack_description'] = camel_dict_to_snake_dict(facts['stack_description'])251 # Create optional stack outputs252 all_facts = module.params.get('all_facts')253 if all_facts or module.params.get('stack_resources'):254 facts['stack_resource_list'] = service_mgr.list_stack_resources(stack_name)255 facts['stack_resources'] = to_dict(facts.get('stack_resource_list'), 'LogicalResourceId', 'PhysicalResourceId')256 if all_facts or module.params.get('stack_template'):257 facts['stack_template'] = service_mgr.get_template(stack_name)258 if all_facts or module.params.get('stack_policy'):259 facts['stack_policy'] = service_mgr.get_stack_policy(stack_name)260 if all_facts or module.params.get('stack_events'):261 facts['stack_events'] = service_mgr.describe_stack_events(stack_name)262 result['ansible_facts']['cloudformation'][stack_name] = facts263 result['changed'] = False264 module.exit_json(**result)265if __name__ == '__main__':...

Full Screen

Full Screen

stack_policies.py

Source:stack_policies.py Github

copy

Full Screen

...36 context.error = e37@then('the policy for stack "{stack_name}" is {state}')38def step_impl(context, stack_name, state):39 full_name = get_cloudformation_stack_name(context, stack_name)40 policy = get_stack_policy(context, full_name)41 if state == 'not set':42 assert (policy is None)43def get_stack_policy(context, stack_name):44 try:45 response = retry_boto_call(46 context.client.get_stack_policy,47 StackName=stack_name48 )49 except ClientError as e:50 if e.response['Error']['Code'] == 'ValidationError' \51 and e.response['Error']['Message'].endswith("does not exist"):52 return None53 else:54 raise e55 return response.get("StackPolicyBody")56def generate_stack_policy(policy_type):57 data = ''...

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