The objects data source returns keys (i.e., file names) and other metadata about objects in an S3 bucket.
The following example retrieves a list of all object keys in an S3 bucket and creates corresponding Terraform object data sources:
data "aws_s3_objects" "my_objects" {
bucket = "ourcorp"
}
data "aws_s3_object" "object_info" {
count = length(data.aws_s3_objects.my_objects.keys)
key = element(data.aws_s3_objects.my_objects.keys, count.index)
bucket = data.aws_s3_objects.my_objects.id
}
This data source supports the following arguments:
bucket
- (Required) Lists object keys in this S3 bucket. Alternatively, an S3 access point ARN can be specifiedprefix
- (Optional) Limits results to object keys with this prefix (Default: none)delimiter
- (Optional) Character used to group keys (Default: none)encoding_type
- (Optional) Encodes keys using this method (Default: none; besides none, only "url" can be used)max_keys
- (Optional) Maximum object keys to return (Default: 1000)start_after
- (Optional) Returns key names lexicographically after a specific object key in your bucket (Default: none; S3 lists object keys in UTF-8 character encoding in lexicographical order)fetch_owner
- (Optional) Boolean specifying whether to populate the owner list (Default: false)request_payer
- (Optional) Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests. If included, the only valid value is requester
.This data source exports the following attributes in addition to the arguments above:
keys
- List of strings representing object keyscommon_prefixes
- List of any keys between prefix
and the next occurrence of delimiter
(i.e., similar to subdirectories of the prefix
"directory"); the list is only returned when you specify delimiter
id
- S3 Bucket.owners
- List of strings representing object owner IDs (see fetch_owner
above)request_charged
- If present, indicates that the requester was successfully charged for the request.