Best Python code snippet using localstack_python
ec2_starter.py
Source:ec2_starter.py
...3from moto.ec2.responses.reserved_instances import ReservedInstances4from localstack import config5from localstack.services.infra import start_moto_server6def patch_ec2():7 def patch_revoke_security_group_egress(backend):8 revoke_security_group_egress_orig = backend.revoke_security_group_egress9 def revoke_security_group_egress(*args, **kwargs):10 try:11 return revoke_security_group_egress_orig(*args, **kwargs)12 except InvalidPermissionNotFoundError:13 # this can happen, as CidrIpv6 is not yet supported by moto14 if args[4] == []:15 return '_ignore_'16 return revoke_security_group_egress17 def patch_delete_nat_gateway(backend):18 def delete_nat_gateway(nat_gateway_id):19 gateway = backend.nat_gateways.get(nat_gateway_id)20 if gateway:21 gateway.state = 'deleted'22 return delete_nat_gateway23 for region, backend in ec2_models.ec2_backends.items():24 backend.revoke_security_group_egress = patch_revoke_security_group_egress(backend)25 backend.delete_nat_gateway = patch_delete_nat_gateway(backend)26 # TODO Implement Reserved Instance backend27 # https://github.com/localstack/localstack/issues/243528 def describe_reserved_instances_offerings(self):29 template = self.response_template(DESCRIBE_RESERVED_INSTANCES_OFFERINGS_RESPONSE)30 return template.render({})31 def purchase_reserved_instances_offering(self):32 template = self.response_template(PURCHASE_RESERVED_INSTANCES_OFFERINGS_RESPONSE)33 return template.render({})34 def describe_reserved_instances(self):35 template = self.response_template(DESCRIBE_RESERVED_INSTANCES_RESPONSE)36 return template.render({})37 ReservedInstances.describe_reserved_instances_offerings = describe_reserved_instances_offerings38 ReservedInstances.purchase_reserved_instances_offering = purchase_reserved_instances_offering...
main.py
Source:main.py
...51 else:52 ingress_rules.append(rule_id)53 if len(egress_rules) > 0:54 logger.debug(json.dumps(egress_rules, indent=2))55 response = ec2_client.revoke_security_group_egress(56 GroupId=group,57 SecurityGroupRuleIds=egress_rules,58 DryRun=False59 )60 logger.info('revoke_security_group_egress() returned %s', json.dumps(response, indent=2))61 else:62 logger.info('%s had no egress rules', group)63 if len(ingress_rules) > 0:64 logger.debug(json.dumps(ingress_rules, indent=2))65 response = ec2_client.revoke_security_group_ingress(66 GroupId=group,67 SecurityGroupRuleIds=ingress_rules,68 DryRun=False69 )70 logger.info('revoke_security_group_ingress() returned %s', json.dumps(response, indent=2))71 else:72 logger.info('%s had no ingress rules', group)73 except Exception as wtf:74 logger.error(wtf, exc_info=True)...
bot.py
Source:bot.py
...29 if(len(ip_permissions)==0):30 log.warning("[{}] No outbound port/protocol to remove from security group".format(security_group_id))31 else:32 log.info("[{}] Removing all outbound port/protocol from security group".format(security_group_id))33 client.revoke_security_group_egress(GroupId=security_group_id, IpPermissions=ip_permissions)...
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!!