Best Python code snippet using localstack_python
rm.py
Source:rm.py
...14 for eigw in paginate(clients.ec2.get_paginator('describe_egress_only_internet_gateways')):15 for attachment in eigw["Attachments"]:16 if attachment.get("VpcId") == vpc.id:17 logger.info("Will delete %s", eigw["EgressOnlyInternetGatewayId"])18 clients.ec2.delete_egress_only_internet_gateway(19 EgressOnlyInternetGatewayId=eigw["EgressOnlyInternetGatewayId"],20 DryRun=not args.force21 )22 for igw in vpc.internet_gateways.all():23 logger.info("Will delete %s", igw)24 igw.detach_from_vpc(VpcId=vpc.id, DryRun=not args.force)25 igw.delete(DryRun=not args.force)26 for security_group in vpc.security_groups.all():27 if security_group.group_name != "default":28 logger.info("Will delete %s", security_group)29 security_group.delete(DryRun=not args.force)30 for nacl in vpc.network_acls.all():31 if not nacl.is_default:32 logger.info("Will delete %s", nacl)33 nacl.delete(DryRun=not args.force)34 for route_table in vpc.route_tables.all():35 logger.info("Will delete %s", route_table)36 for route in route_table.routes:37 try:38 route.delete(DryRun=not args.force)39 except ClientError:40 pass41 try:42 route_table.delete(DryRun=not args.force)43 except ClientError:44 pass45 for subnet in vpc.subnets.all():46 logger.info("Will delete %s", subnet)47 subnet.delete(DryRun=not args.force)48 logger.info("Will delete %s", vpc)49 vpc.delete(DryRun=not args.force)50def rm(args):51 for name in args.names:52 try:53 if args.key_pair:54 resources.ec2.KeyPair(name).delete(DryRun=not args.force)55 elif args.elb:56 if args.force:57 clients.elb.delete_load_balancer(LoadBalancerName=name)58 else:59 clients.elb.describe_load_balancer_attributes(LoadBalancerName=name)60 elif getattr(args, "lambda"):61 if args.force:62 getattr(clients, "lambda").delete_function(FunctionName=name)63 else:64 getattr(clients, "lambda").get_function(FunctionName=name)65 elif name.startswith("sg-"):66 resources.ec2.SecurityGroup(name).delete(DryRun=not args.force)67 elif name.startswith("vol-"):68 resources.ec2.Volume(name).delete(DryRun=not args.force)69 elif name.startswith("snap-"):70 resources.ec2.Snapshot(name).delete(DryRun=not args.force)71 elif name.startswith("subnet-"):72 resources.ec2.Subnet(name).delete(DryRun=not args.force)73 elif name.startswith("vpc-"):74 delete_vpc(name, args)75 elif name.startswith("lt-"):76 clients.ec2.delete_launch_template(LaunchTemplateId=name, DryRun=not args.force)77 elif name.startswith("igw-"):78 clients.ec2.delete_internet_gateway(InternetGatewayId=name, DryRun=not args.force)79 elif name.startswith("eigw-"):80 clients.ec2.delete_egress_only_internet_gateway(EgressOnlyInternetGatewayId=name, DryRun=not args.force)81 elif name.startswith("fl-"):82 if args.force:83 clients.ec2.delete_flow_logs(FlowLogIds=[name])84 else:85 res = clients.ec2.describe_flow_logs(Filters=[dict(Name="flow-log-id", Values=[name])])86 assert res["FlowLogs"], "Unknown flow log ID"87 elif name.startswith("ami-"):88 image = resources.ec2.Image(name)89 snapshot_id = image.block_device_mappings[0].get("Ebs", {}).get("SnapshotId")90 image.deregister(DryRun=not args.force)91 if snapshot_id:92 resources.ec2.Snapshot(snapshot_id).delete(DryRun=not args.force)93 elif name.startswith("sir-"):94 clients.ec2.cancel_spot_instance_requests(SpotInstanceRequestIds=[name], DryRun=not args.force)...
egress_only_internet_gateways.py
Source:egress_only_internet_gateways.py
...17 egress_only_igw_ids, filters,18 )19 template = self.response_template(DESCRIBE_EGRESS_ONLY_IGW_RESPONSE)20 return template.render(egress_only_igws=egress_only_igws)21 def delete_egress_only_internet_gateway(self):22 egress_only_igw_id = self._get_param("EgressOnlyInternetGatewayId")23 self.ec2_backend.delete_egress_only_internet_gateway(24 gateway_id=egress_only_igw_id25 )26 template = self.response_template(DELETE_EGRESS_ONLY_IGW_RESPONSE)27 return template.render()28CREATE_EGRESS_ONLY_IGW_RESPONSE = """<CreateEgressOnlyInternetGatewayResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">29 <requestId>c617595f-6c29-4a00-a941-example</requestId>30 <egressOnlyInternetGateway>31 <attachmentSet>32 <item>33 <state>{{ egress_only_igw.state }}</state>34 <vpcId>{{ egress_only_igw.vpc_id }}</vpcId>35 </item>36 </attachmentSet>37 <egressOnlyInternetGatewayId>{{ egress_only_igw.id }}</egressOnlyInternetGatewayId>...
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!!