getBucket

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

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var selected = Output.Create(Aws.S3.GetBucket.InvokeAsync(new Aws.S3.GetBucketArgs
        {
            Bucket = "bucket.test.com",
        }));
        var testZone = Output.Create(Aws.Route53.GetZone.InvokeAsync(new Aws.Route53.GetZoneArgs
        {
            Name = "test.com.",
        }));
        var example = new Aws.Route53.Record("example", new Aws.Route53.RecordArgs
        {
            ZoneId = testZone.Apply(testZone => testZone.Id),
            Name = "bucket",
            Type = "A",
            Aliases = 
            {
                new Aws.Route53.Inputs.RecordAliasArgs
                {
                    Name = selected.Apply(selected => selected.WebsiteDomain),
                    ZoneId = selected.Apply(selected => selected.HostedZoneId),
                },
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/route53"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/s3"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		selected, err := s3.LookupBucket(ctx, &s3.LookupBucketArgs{
			Bucket: "bucket.test.com",
		}, nil)
		if err != nil {
			return err
		}
		opt0 := "test.com."
		testZone, err := route53.LookupZone(ctx, &route53.LookupZoneArgs{
			Name: &opt0,
		}, nil)
		if err != nil {
			return err
		}
		_, err = route53.NewRecord(ctx, "example", &route53.RecordArgs{
			ZoneId: pulumi.String(testZone.Id),
			Name:   pulumi.String("bucket"),
			Type:   pulumi.String("A"),
			Aliases: route53.RecordAliasArray{
				&route53.RecordAliasArgs{
					Name:   pulumi.String(selected.WebsiteDomain),
					ZoneId: pulumi.String(selected.HostedZoneId),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

selected = aws.s3.get_bucket(bucket="bucket.test.com")
test_zone = aws.route53.get_zone(name="test.com.")
example = aws.route53.Record("example",
    zone_id=test_zone.id,
    name="bucket",
    type="A",
    aliases=[aws.route53.RecordAliasArgs(
        name=selected.website_domain,
        zone_id=selected.hosted_zone_id,
    )])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const selected = aws.s3.getBucket({
    bucket: "bucket.test.com",
});
const testZone = aws.route53.getZone({
    name: "test.com.",
});
const example = new aws.route53.Record("example", {
    zoneId: testZone.then(testZone => testZone.id),
    name: "bucket",
    type: "A",
    aliases: [{
        name: selected.then(selected => selected.websiteDomain),
        zoneId: selected.then(selected => selected.hostedZoneId),
    }],
});

CloudFront Origin

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var selected = Output.Create(Aws.S3.GetBucket.InvokeAsync(new Aws.S3.GetBucketArgs
        {
            Bucket = "a-test-bucket",
        }));
        var test = new Aws.CloudFront.Distribution("test", new Aws.CloudFront.DistributionArgs
        {
            Origins = 
            {
                new Aws.CloudFront.Inputs.DistributionOriginArgs
                {
                    DomainName = selected.Apply(selected => selected.BucketDomainName),
                    OriginId = "s3-selected-bucket",
                },
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cloudfront"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/s3"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		selected, err := s3.LookupBucket(ctx, &s3.LookupBucketArgs{
			Bucket: "a-test-bucket",
		}, nil)
		if err != nil {
			return err
		}
		_, err = cloudfront.NewDistribution(ctx, "test", &cloudfront.DistributionArgs{
			Origins: cloudfront.DistributionOriginArray{
				&cloudfront.DistributionOriginArgs{
					DomainName: pulumi.String(selected.BucketDomainName),
					OriginId:   pulumi.String("s3-selected-bucket"),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

selected = aws.s3.get_bucket(bucket="a-test-bucket")
test = aws.cloudfront.Distribution("test", origins=[aws.cloudfront.DistributionOriginArgs(
    domain_name=selected.bucket_domain_name,
    origin_id="s3-selected-bucket",
)])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const selected = aws.s3.getBucket({
    bucket: "a-test-bucket",
});
const test = new aws.cloudfront.Distribution("test", {origins: [{
    domainName: selected.then(selected => selected.bucketDomainName),
    originId: "s3-selected-bucket",
}]});

Using getBucket

function getBucket(args: GetBucketArgs, opts?: InvokeOptions): Promise<GetBucketResult>
def get_bucket(bucket: Optional[str] = None,
               opts: Optional[InvokeOptions] = None) -> GetBucketResult
func LookupBucket(ctx *Context, args *LookupBucketArgs, opts ...InvokeOption) (*LookupBucketResult, error)

Note: This function is named LookupBucket in the Go SDK.

public static class GetBucket {
    public static Task<GetBucketResult> InvokeAsync(GetBucketArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

Bucket string
The name of the bucket
Bucket string
The name of the bucket
bucket string
The name of the bucket
bucket str
The name of the bucket

getBucket Result

The following output properties are available:

Arn string
The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
Bucket string
BucketDomainName string
The bucket domain name. Will be of format bucketname.s3.amazonaws.com.
BucketRegionalDomainName string
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 string
The Route 53 Hosted Zone ID for this bucket’s region.
Id string
The provider-assigned unique ID for this managed resource.
Region string
The AWS region this bucket resides in.
WebsiteDomain string
The 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.
WebsiteEndpoint string
The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
Arn string
The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
Bucket string
BucketDomainName string
The bucket domain name. Will be of format bucketname.s3.amazonaws.com.
BucketRegionalDomainName string
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 string
The Route 53 Hosted Zone ID for this bucket’s region.
Id string
The provider-assigned unique ID for this managed resource.
Region string
The AWS region this bucket resides in.
WebsiteDomain string
The 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.
WebsiteEndpoint string
The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
arn string
The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
bucket string
bucketDomainName string
The bucket domain name. Will be of format bucketname.s3.amazonaws.com.
bucketRegionalDomainName string
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 string
The Route 53 Hosted Zone ID for this bucket’s region.
id string
The provider-assigned unique ID for this managed resource.
region string
The AWS region this bucket resides in.
websiteDomain string
The 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.
websiteEndpoint string
The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.
arn str
The ARN of the bucket. Will be of format arn:aws:s3:::bucketname.
bucket str
bucket_domain_name str
The bucket domain name. Will be of format bucketname.s3.amazonaws.com.
bucket_regional_domain_name str
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.
hosted_zone_id str
The Route 53 Hosted Zone ID for this bucket’s region.
id str
The provider-assigned unique ID for this managed resource.
region str
The AWS region this bucket resides in.
website_domain str
The 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.
website_endpoint str
The website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.