Skip to content

Data Source: awsS3Bucket

Provides details about a specific S3 bucket.

This resource may prove useful when setting up a Route53 record, or an origin for a CloudFront Distribution.

Example Usage

Route53 Record

/*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 dataAwsRoute53ZoneTestZone =
  new aws.dataAwsRoute53Zone.DataAwsRoute53Zone(this, "test_zone", {
    name: "test.com.",
  });
const dataAwsS3BucketSelected = new aws.dataAwsS3Bucket.DataAwsS3Bucket(
  this,
  "selected",
  {
    bucket: "bucket.test.com",
  }
);
new aws.route53Record.Route53Record(this, "example", {
  alias: {
    name: dataAwsS3BucketSelected.websiteDomain,
    zoneId: dataAwsS3BucketSelected.hostedZoneId,
  },
  name: "bucket",
  type: "A",
  zoneId: dataAwsRoute53ZoneTestZone.id,
});

CloudFront Origin

/*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 dataAwsS3BucketSelected = new aws.dataAwsS3Bucket.DataAwsS3Bucket(
  this,
  "selected",
  {
    bucket: "a-test-bucket",
  }
);
new aws.cloudfrontDistribution.CloudfrontDistribution(this, "test", {
  origin: [
    {
      domainName: dataAwsS3BucketSelected.bucketDomainName,
      originId: "s3-selected-bucket",
    },
  ],
});

Argument Reference

The following arguments are supported:

  • bucket - (Required) Name of the bucket

Attribute Reference

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

  • id - Name of the bucket.
  • arn - ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
  • bucketDomainName - Bucket domain name. Will be of format bucketnameS3AmazonawsCom.
  • bucketRegionalDomainName - The bucket region-specific domain name. The bucket domain name including the region name, please refer here for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent redirect issues from CloudFront to S3 Origin URL.
  • hostedZoneId - The Route 53 Hosted Zone ID for this bucket's region.
  • region - AWS region this bucket resides in.
  • websiteEndpoint - Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
  • websiteDomain - Domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records.