Best Python code snippet using localstack_python
ssm_listener.py
Source:ssm_listener.py
...82 # Get parameter with all its labels (for all the parameters in params_in_path)83 # Labels of the parameters can be obtained by calling get_parameter_history with parameter name84 all_params = []85 for params in params_in_path:86 all_params.extend(ssm_client.get_parameter_history(Name=params["Name"])["Parameters"])87 # Filter the params with matched labels88 filtered_params = list(89 filter(90 lambda param: filter_by_label(param=param, labels=labels_to_filter),91 all_params,92 )93 )94 # Get details of the filtered params to return95 # This step is needed because get_parameter_history doesn't return parameter's ARN96 details_of_filtered_params = list(97 map(98 lambda param: ssm_client.get_parameter(Name=param["Name"])["Parameter"],99 filtered_params,100 )...
ssm.py
Source:ssm.py
1import types2import logging3import time4logger = logging.getLogger(__file__)5put_parameter_and_wait_max_retries = 106def put_parameter_and_wait(self, Name, **kwargs):7 """8 This will call put_parameter and ensure it has been successfully put by checking it9 :param self: ssm client10 :param Name: The fully qualified name of the parameter that you want to add to the system11 :param kwargs: These args are passed through to ssm.put_parameter12 :return: ssm.get_parameter.response13 """14 new_version = self.put_parameter(Name=Name, **kwargs).get('Version')15 count = 016 current_parameter = {17 "Parameter": {18 "Version": -119 }20 }21 while current_parameter.get('Parameter').get('Version') < new_version:22 count += 123 if count > put_parameter_and_wait_max_retries:24 raise Exception(f"Putting and waiting for param {Name} failed")25 time.sleep(1)26 if new_version == 1:27 try:28 current_parameter = self.get_parameter(Name=Name)29 except self.exceptions.ParameterNotFound:30 pass31 else:32 current_parameter = self.get_parameter(Name=Name)33 return current_parameter34def get_parameter_history_single_page(self, **kwargs):35 """36 This will continue to call get_parameter_history_single_page until there are no more pages left to retrieve.37 It will return the aggregated response in the same structure as get_parameter_history_single_page does.38 :param self: ssm client39 :param kwargs: these are passed onto the get_parameter_history_single_page method call40 :return: ssm_client.get_parameter_history_single_page.response41 """42 return slurp(43 'get_parameter_history',44 self.get_parameter_history,45 'Parameters',46 'NextToken', 'NextToken',47 **kwargs48 )49class ParameterVersionNotFoundException(Exception):50 pass51def get_parameter_version(self, Version, **kwargs):52 paginator = self.get_paginator('get_parameter_history')53 iterator = paginator.paginate(54 **kwargs55 )56 for page in iterator:57 for parameter in page.get("Parameters", []):58 if parameter.get("Version") == Version:59 return dict(Parameter=parameter)60 raise ParameterVersionNotFoundException(f"Could not find version: {Version} of {kwargs.get('Name')}")61def make_better(client):62 client.put_parameter_and_wait = types.MethodType(put_parameter_and_wait, client)63 client.get_parameter_history_single_page = types.MethodType(get_parameter_history_single_page, client)64 client.get_parameter_version = types.MethodType(get_parameter_version, client)...
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!!