code: def ec2_fab(service, args):
      
      instance_ids = args.instances
      instances = service.list(elb=args.elb, instance_ids=instance_ids)
      hosts = service.resolve_hosts(instances)
  
      fab.env.hosts = hosts
      fab.env.key_filename = settings.get('SSH', 'KEY_FILE')
      fab.env.user = settings.get('SSH', 'USER', getpass.getuser())
      fab.env.parallel = True
  
      fabfile = find_fabfile(args.file)
      if not fabfile:
          print 'Couldn\'t find any fabfiles!'
          return
  
      fab.env.real_fabile = fabfile
      docstring, callables, default = load_fabfile(fabfile)
      fab_state.commands.update(callables)
  
      commands_to_run = parse_arguments(args.methods)
      for name, args, kwargs, arg_hosts, arg_roles, arg_exclude_hosts in commands_to_run:
          fab.execute(name,
                      hosts=arg_hosts,
                      roles=arg_roles,
                      exclude_hosts=arg_exclude_hosts,
                      *args, **kwargs)
docs: Run Fabric commands against EC2 instances