Best Python code snippet using localstack_python
events.py
Source:events.py
...29 local_rules = self._config.get_events().get('rules')30 remote_rules = events_client.get_rules_by_target(arn)31 self._clean(remote_rules, local_rules, arn, func_name, alias_name)32 self._put_rules(remote_rules, local_rules, func_name, alias_name)33 self._put_targets(local_rules, arn)34 def _put_rules(self, remote, local, function, alias):35 lambda_client = self.get_lambda_client()36 events_client = self.get_events_client()37 for l in local:38 l['state'] = self._convert_state(l.get('disabled'))39 r = self._search_rule(remote, l['name'])40 if len(r) == 0:41 self._logger.warn(42 '[EventRule] Create new event rule "{}"'.format(l['name']))43 self._print_diff(44 prefix='[EventRule] {}:'.format(l['name']),45 keys=EVENT_RULE_DIFF_KEYS,46 remote=r, local=l)47 ret = events_client.put_rule(l)48 lambda_client.add_permission(function, alias, l['name'], ret.get('RuleArn'))49 def _convert_state(self, disabled):50 if disabled:51 return 'DISABLED'52 else:53 return 'ENABLED'54 def _search_rule(self, rules, name):55 for r in rules:56 if name in [r.get('Name'), r.get('name')]:57 return r58 return {}59 def _exist_rule(self, rules, name):60 return len(self._search_rule(rules, name)) > 061 def _put_targets(self, local, arn):62 client = self.get_events_client()63 for l in local:64 targets = client.get_targets_by_rule(l['name'])65 for lt in l['targets']:66 if 'input' in lt:67 lt['input'] = json.dumps(lt['input'])68 diff_r = {}69 for rt in targets:70 if rt['Id'] == lt['id']:71 diff_r = rt72 break73 self._logger.warn(74 '[EventRule] {}: Add "{}" to targets'.format(l['name'], lt['id']))75 self._print_diff(...
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!!