Data Source: awsS3Objects
\~> NOTE on maxKeys
: Retrieving very large numbers of keys can adversely affect Terraform's performance.
The objects data source returns keys (i.e., file names) and other metadata about objects in an S3 bucket.
Example Usage
The following example retrieves a list of all object keys in an S3 bucket and creates corresponding Terraform object data sources:
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const dataAwsS3ObjectsMyObjects = new aws.dataAwsS3Objects.DataAwsS3Objects(
this,
"my_objects",
{
bucket: "ourcorp",
}
);
const dataAwsS3ObjectObjectInfo = new aws.dataAwsS3Object.DataAwsS3Object(
this,
"object_info",
{
bucket: dataAwsS3ObjectsMyObjects.id,
key: `\${element(${dataAwsS3ObjectsMyObjects.keys}, count.index)}`,
}
);
/*In most cases loops should be handled in the programming language context and
not inside of the Terraform context. If you are looping over something external, e.g. a variable or a file input
you should consider using a for loop. If you are looping over something only known to Terraform, e.g. a result of a data source
you need to keep this like it is.*/
dataAwsS3ObjectObjectInfo.addOverride(
"count",
`\${length(${dataAwsS3ObjectsMyObjects.keys})}`
);
Argument Reference
The following arguments are supported:
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)encodingType
- (Optional) Encodes keys using this method (Default: none; besides none, only "url" can be used)maxKeys
- (Optional) Maximum object keys to return (Default: 1000)startAfter
- (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)fetchOwner
- (Optional) Boolean specifying whether to populate the owner list (Default: false)
Attributes Reference
In addition to all arguments above, the following attributes are exported:
keys
- List of strings representing object keyscommonPrefixes
- List of any keys betweenprefix
and the next occurrence ofdelimiter
(i.e., similar to subdirectories of theprefix
"directory"); the list is only returned when you specifydelimiter
id
- S3 Bucket.owners
- List of strings representing object owner IDs (seefetchOwner
above)