diff --git a/awscli/customizations/s3/s3.py b/awscli/customizations/s3/s3.py index 064d2c2e3bcb..4e8e6e02e214 100644 --- a/awscli/customizations/s3/s3.py +++ b/awscli/customizations/s3/s3.py @@ -342,7 +342,10 @@ def _get_endpoint(self, service, parsed_globals): class ListCommand(S3SubCommand): def _do_command(self, parsed_args, parsed_globals): - bucket, key = find_bucket_key(parsed_args.paths[0][5:]) + path = parsed_args.paths[0] + if path.startswith('s3://'): + path = path[5:] + bucket, key = find_bucket_key(path) self.service = self._session.get_service('s3') self.endpoint = self._get_endpoint(self.service, parsed_globals) if not bucket: diff --git a/tests/integration/customizations/s3/test_plugin.py b/tests/integration/customizations/s3/test_plugin.py index e4fe878dc5e3..fb95f0df43cd 100644 --- a/tests/integration/customizations/s3/test_plugin.py +++ b/tests/integration/customizations/s3/test_plugin.py @@ -534,6 +534,15 @@ def test_ls_recursive(self): self.assertIn('8 bar.txt', p.stdout) self.assertIn('8 subdir/foo.txt', p.stdout) + def test_ls_without_prefix(self): + # The ls command does not require an s3:// prefix, + # we're always listing s3 contents. + bucket_name = self.create_bucket() + self.put_object(bucket_name, 'foo.txt', 'contents') + p = aws('s3 ls %s' % bucket_name) + self.assertEqual(p.rc, 0) + self.assertIn('foo.txt', p.stdout) + class TestMbRb(BaseS3CLICommand): """