Skip to content

Data Source: aws_s3_objects#

~> Note on max_keys: Retrieving very large numbers of keys can adversely affect Terraform's performance.

Provides information about keys and metadata of S3 objects.

Example Usage#

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" "example" {
  bucket = "tf-example"
}

data "aws_s3_object" "example" {
  count  = length(data.aws_s3_objects.example.keys)
  key    = element(data.aws_s3_objects.example.keys, count.index)
  bucket = data.aws_s3_objects.example.bucket
}

Argument Reference#

The following arguments are supported:

  • bucket - (Required) Lists object keys in this S3 bucket.
  • delimiter - (Optional) A character used to group keys.
  • encoding_type - (Optional) Encodes keys using this method.
    • Valid values: url
  • fetch_owner - (Optional) Boolean specifying whether to populate the owner list.
    • Default value: false
  • max_keys - (Optional) Maximum object keys to return.
    • Default value: 1000
  • prefix - (Optional) Limits results to object keys with this prefix.
  • start_after - (Optional) Returns key names lexicographically after a specific object key in your bucket. S3 lists object keys in UTF-8 character encoding in lexicographical order.

Attribute Reference#

In addition to all arguments above, the following attributes are exported:

  • common_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.
  • keys - List of strings representing object keys.
  • owners - List of strings representing object owner IDs (see fetch_owner above).