Returns some or all (up to 1,000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. A 200 OK
response can contain valid or invalid XML. Make sure to design your application to parse the contents of the response and handle it appropriately.
To use this operation, you must have READ access to the bucket.
To use this operation in an AWS Identity and Access Management (IAM) policy, you must have permissions to perform the s3:ListBucket
action. The bucket owner has this permission by default and can grant this permission to others. For more information about permissions, see Permissions Related to Bucket Subresource Operations and Managing Access Permissions to Your Amazon S3 Resources .
Warning
This section describes the latest revision of the API. We recommend that you use this revised API for application development. For backward compatibility, Amazon S3 continues to support the prior version of this API, ListObjects .
To get a list of your buckets, see ListBuckets .
The following operations are related to ListObjectsV2
:
See also: AWS API Documentation
See ‘aws help’ for descriptions of global parameters.
list-objects-v2
is a paginated operation. Multiple API calls may be issued in order to retrieve the entire data set of results. You can disable pagination by providing the --no-paginate
argument.
When using --output text
and the --query
argument on a paginated response, the --query
argument must extract data from the results of the following query expressions: Contents
, CommonPrefixes
list-objects-v2
--bucket <value>
[--delimiter <value>]
[--encoding-type <value>]
[--prefix <value>]
[--fetch-owner | --no-fetch-owner]
[--start-after <value>]
[--request-payer <value>]
[--expected-bucket-owner <value>]
[--cli-input-json | --cli-input-yaml]
[--starting-token <value>]
[--page-size <value>]
[--max-items <value>]
[--generate-cli-skeleton <value>]
--bucket
(string)
Bucket name to list.
When using this API with an access point, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName -AccountId .s3-accesspoint.*Region* .amazonaws.com. When using this operation with an access point through the AWS SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using Access Points in the Amazon Simple Storage Service Developer Guide .
When using this API with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form AccessPointName -AccountId .*outpostID* .s3-outposts.*Region* .amazonaws.com. When using this operation using S3 on Outposts through the AWS SDKs, you provide the Outposts bucket ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see Using S3 on Outposts in the Amazon Simple Storage Service Developer Guide .
--delimiter
(string)
A delimiter is a character you use to group keys.
--encoding-type
(string)
Encoding type used by Amazon S3 to encode object keys in the response.
Possible values:
url
--prefix
(string)
Limits the response to keys that begin with the specified prefix.
--fetch-owner
| --no-fetch-owner
(boolean)
The owner field is not present in listV2 by default, if you want to return owner field with each key in the result then set the fetch owner field to true.
--start-after
(string)
StartAfter is where you want Amazon S3 to start listing from. Amazon S3 starts listing after this specified key. StartAfter can be any key in the bucket.
--request-payer
(string)
Confirms that the requester knows that she or he will be charged for the list objects request in V2 style. Bucket owners need not specify this parameter in their requests.
Possible values:
requester
--expected-bucket-owner
(string)
The account id of the expected bucket owner. If the bucket is owned by a different account, the request will fail with an HTTP
403 (Access Denied)
error.
--cli-input-json
| --cli-input-yaml
(string)
Reads arguments from the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton
. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with --cli-input-yaml
.
--starting-token
(string)
A token to specify where to start paginating. This is the
NextToken
from a previously truncated response.For usage examples, see Pagination in the AWS Command Line Interface User Guide .
--page-size
(integer)
The size of each page to get in the AWS service call. This does not affect the number of items returned in the command’s output. Setting a smaller page size results in more calls to the AWS service, retrieving fewer items in each call. This can help prevent the AWS service calls from timing out.
For usage examples, see Pagination in the AWS Command Line Interface User Guide .
--max-items
(integer)
The total number of items to return in the command’s output. If the total number of items available is more than the value specified, a
NextToken
is provided in the command’s output. To resume pagination, provide theNextToken
value in thestarting-token
argument of a subsequent command. Do not use theNextToken
response element directly outside of the AWS CLI.For usage examples, see Pagination in the AWS Command Line Interface User Guide .
--generate-cli-skeleton
(string)
Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input
, prints a sample input JSON that can be used as an argument for --cli-input-json
. Similarly, if provided yaml-input
it will print a sample input YAML that can be used with --cli-input-yaml
. If provided with the value output
, it validates the command inputs and returns a sample output JSON for that command.
See ‘aws help’ for descriptions of global parameters.
To get a list of objects in a bucket
The following list-objects-v2
example lists the objects in the specified bucket.
aws s3api list-objects-v2 \
--bucket my-bucket
Output:
{
"Contents": [
{
"LastModified": "2019-11-05T23:11:50.000Z",
"ETag": "\"621503c373607d548b37cff8778d992c\"",
"StorageClass": "STANDARD",
"Key": "doc1.rtf",
"Size": 391
},
{
"LastModified": "2019-11-05T23:11:50.000Z",
"ETag": "\"a2cecc36ab7c7fe3a71a273b9d45b1b5\"",
"StorageClass": "STANDARD",
"Key": "doc2.rtf",
"Size": 373
},
{
"LastModified": "2019-11-05T23:11:50.000Z",
"ETag": "\"08210852f65a2e9cb999972539a64d68\"",
"StorageClass": "STANDARD",
"Key": "doc3.rtf",
"Size": 399
},
{
"LastModified": "2019-11-05T23:11:50.000Z",
"ETag": "\"d1852dd683f404306569471af106988e\"",
"StorageClass": "STANDARD",
"Key": "doc4.rtf",
"Size": 6225
}
]
}
IsTruncated -> (boolean)
Set to false if all of the results were returned. Set to true if more keys are available to return. If the number of results exceeds that specified by MaxKeys, all of the results might not be returned.
Contents -> (list)
Metadata about each object returned.
(structure)
An object consists of data and its descriptive metadata.
Key -> (string)
The name that you assign to an object. You use the object key to retrieve the object.
LastModified -> (timestamp)
The date the Object was Last Modified
ETag -> (string)
The entity tag is a hash of the object. The ETag reflects changes only to the contents of an object, not its metadata. The ETag may or may not be an MD5 digest of the object data. Whether or not it is depends on how the object was created and how it is encrypted as described below:
Objects created by the PUT Object, POST Object, or Copy operation, or through the AWS Management Console, and are encrypted by SSE-S3 or plaintext, have ETags that are an MD5 digest of their object data.
Objects created by the PUT Object, POST Object, or Copy operation, or through the AWS Management Console, and are encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest of their object data.
If an object is created by either the Multipart Upload or Part Copy operation, the ETag is not an MD5 digest, regardless of the method of encryption.
Size -> (integer)
Size in bytes of the object
StorageClass -> (string)
The class of storage used to store the object.
Owner -> (structure)
The owner of the object
DisplayName -> (string)
Container for the display name of the owner.
ID -> (string)
Container for the ID of the owner.
Name -> (string)
The bucket name.
When using this API with an access point, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName -AccountId .s3-accesspoint.*Region* .amazonaws.com. When using this operation with an access point through the AWS SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using Access Points in the Amazon Simple Storage Service Developer Guide .
When using this API with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form AccessPointName -AccountId .*outpostID* .s3-outposts.*Region* .amazonaws.com. When using this operation using S3 on Outposts through the AWS SDKs, you provide the Outposts bucket ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see Using S3 on Outposts in the Amazon Simple Storage Service Developer Guide .
Prefix -> (string)
Keys that begin with the indicated prefix.
Delimiter -> (string)
Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the CommonPrefixes collection. These rolled-up keys are not returned elsewhere in the response. Each rolled-up result counts as only one return against the
MaxKeys
value.
MaxKeys -> (integer)
Sets the maximum number of keys returned in the response. By default the API returns up to 1,000 key names. The response might contain fewer keys but will never contain more.
CommonPrefixes -> (list)
All of the keys rolled up into a common prefix count as a single return when calculating the number of returns.
A response can contain
CommonPrefixes
only if you specify a delimiter.
CommonPrefixes
contains all (if there are any) keys betweenPrefix
and the next occurrence of the string specified by a delimiter.
CommonPrefixes
lists keys that act like subdirectories in the directory specified byPrefix
.For example, if the prefix is
notes/
and the delimiter is a slash (/
) as innotes/summer/july
, the common prefix isnotes/summer/
. All of the keys that roll up into a common prefix count as a single return when calculating the number of returns.(structure)
Container for all (if there are any) keys between Prefix and the next occurrence of the string specified by a delimiter. CommonPrefixes lists keys that act like subdirectories in the directory specified by Prefix. For example, if the prefix is notes/ and the delimiter is a slash (/) as in notes/summer/july, the common prefix is notes/summer/.
Prefix -> (string)
Container for the specified common prefix.
EncodingType -> (string)
Encoding type used by Amazon S3 to encode object key names in the XML response.
If you specify the encoding-type request parameter, Amazon S3 includes this element in the response, and returns encoded key name values in the following response elements:
Delimiter, Prefix, Key,
andStartAfter
.
KeyCount -> (integer)
KeyCount is the number of keys returned with this request. KeyCount will always be less than equals to MaxKeys field. Say you ask for 50 keys, your result will include less than equals 50 keys
ContinuationToken -> (string)
If ContinuationToken was sent with the request, it is included in the response.
NextContinuationToken -> (string)
NextContinuationToken
is sent whenisTruncated
is true, which means there are more keys in the bucket that can be listed. The next list requests to Amazon S3 can be continued with thisNextContinuationToken
.NextContinuationToken
is obfuscated and is not a real key
StartAfter -> (string)
If StartAfter was sent with the request, it is included in the response.