How to use get_stack_parameter method in localstack

Best Python code snippet using localstack_python

cxParamRef.py

Source:cxParamRef.py Github

copy

Full Screen

...29 if len(values) > 3:30 default_value = str(values[3])31 result = None32 try:33 result = ssm.get_stack_parameter(34 stack_resource_name, stack_name, param_name, namespace35 )36 logging.info(f"{param_name} found: {result}")37 except ClientError as err:38 if err.response["Error"]["Code"] == "ParameterNotFound":39 logging.error(40 "Parameter '%s' in namespace '%s' not found"41 % (param_name, namespace)42 )43 else:44 logging.error(45 "Unexpected error occurred looking for Parameter '%s' in namespace '%s': %s"46 % (param_name, namespace, err)47 )48 except Exception as exp:49 logging.error(50 "Unexpected error occurred looking for Parameter '%s' in namespace '%s': %s"51 % (param_name, namespace, exp)52 )53 if not result:54 if default_value:55 logging.info(56 f"Param not found in SSM, using default value: {default_value}"57 )58 result = default_value59 else:60 logging.info("Param not found in SSM. No default value provided.")61 raise Exception(62 f"Param: {param_name} not found in SSM. No default value provided."63 )64 return result65 except BaseException as error:66 logging.error(f'Hook failed for module: {str(context.environment["module_name"])}')67 logging.error(f'{str(context.environment["module_name"])}: {"".join(traceback.TracebackException.from_exception(error).format())}')68 raise error.with_traceback(sys.exc_info()[2])69 @classmethod70 def determine_namespace(cls, context, custom_namespace):71 if custom_namespace in context.environment:72 namespace = str(context.environment.get(custom_namespace))73 logging.info(f"Using custom namespace: {namespace}")74 else:75 namespace = str(context.environment.get("namespace"))76 logging.info(f"Using default namespace: {namespace}")77 return namespace78 @classmethod79 def validate(cls, values):80 """Validates the values"""81 if len(values) < 3:82 raise Exception(83 "Insufficient number of arguments provided. Required: 3+, Supplied: "84 + str(len(values))85 )86 @classmethod87 def deconstruct(cls, value):88 """Deconstruct the value."""89 try:90 stack_name, param_name = value.split("::")91 except ValueError:92 raise ValueError(93 "output handler requires syntax "94 "of <stack>::<param_name>. Got: %s" % value95 )96 return stack_name, param_name97## Remove old lookup98def handle(value, context, provider): # pragma: no cover99 """Cross namespace param lookup"""100 try:101 logging.info(f'Running lookup for module: {str(context.environment["module_name"])}')102 # split passed in values103 values = [x.strip() for x in value.split(" ")]104 default_value = ""105 validate(values)106 stack_resource_name = str(values[0])107 stack_name, param_name = deconstruct(str(values[1]))108 custom_namespace = str(values[2])109 namespace = determine_namespace(context, custom_namespace)110 if len(values) > 3:111 default_value = str(values[3])112 result = None113 try:114 result = ssm.get_stack_parameter(115 stack_resource_name, stack_name, param_name, namespace116 )117 logging.info(f"{param_name} found: {result}")118 except ClientError as err:119 if err.response["Error"]["Code"] == "ParameterNotFound":120 logging.error(121 "Parameter '%s' in namespace '%s' not found" % (param_name, namespace)122 )123 else:124 logging.error(125 "Unexpected error occurred looking for Parameter '%s' in namespace '%s': %s"126 % (param_name, namespace, err)127 )128 except Exception as exp:...

Full Screen

Full Screen

ssm.py

Source:ssm.py Github

copy

Full Screen

...104 raise Exception(f'Parameter \'{parameter}\' is not found in SSM')105 else:106 raise Exception(f'Error occurred while retreiving parameter \'{parameter}\' from SSM: {str(error)}')107 return param_value108def get_stack_parameter(stack_resource_name, stack_name, parameter, namespace):109 ''' Get SSM parameter based on provided stack resource, stack name, param name and namespace'''110 module_name = f"cloud-common-{stack_resource_name}-module"111 path = f"/ccplat/{namespace}/{module_name}/{stack_name}/{parameter}"112 return get_parameter(path)113def get_stack_outputs(stack_resource_name, stack_name, namespace):114 ''' Get SSM parameters based on provided stack resource, stack name and namespace'''115 module_name = f"cloud-common-{stack_resource_name}-module"116 path = f"/ccplat/{namespace}/{module_name}/{stack_name}"117 module_params = get_module_parameters(path)118 stack_outputs = {}119 for param in module_params:120 key = param["Name"].split("/")[-1]121 value = param["Value"]122 stack_outputs[key] = value;...

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