1. Packages
  2. AWS Classic
  3. API Docs
  4. s3
  5. getBucket

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.3.0 published on Thursday, Sep 28, 2023 by Pulumi

aws.s3.getBucket

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.3.0 published on Thursday, Sep 28, 2023 by Pulumi

    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 System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.S3.GetBucket.Invoke(new()
        {
            Bucket = "bucket.test.com",
        });
    
        var testZone = Aws.Route53.GetZone.Invoke(new()
        {
            Name = "test.com.",
        });
    
        var example = new Aws.Route53.Record("example", new()
        {
            ZoneId = testZone.Apply(getZoneResult => getZoneResult.Id),
            Name = "bucket",
            Type = "A",
            Aliases = new[]
            {
                new Aws.Route53.Inputs.RecordAliasArgs
                {
                    Name = selected.Apply(getBucketResult => getBucketResult.WebsiteDomain),
                    ZoneId = selected.Apply(getBucketResult => getBucketResult.HostedZoneId),
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/route53"
    	"github.com/pulumi/pulumi-aws/sdk/v6/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
    		}
    		testZone, err := route53.LookupZone(ctx, &route53.LookupZoneArgs{
    			Name: pulumi.StringRef("test.com."),
    		}, 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
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.s3.S3Functions;
    import com.pulumi.aws.s3.inputs.GetBucketArgs;
    import com.pulumi.aws.route53.Route53Functions;
    import com.pulumi.aws.route53.inputs.GetZoneArgs;
    import com.pulumi.aws.route53.Record;
    import com.pulumi.aws.route53.RecordArgs;
    import com.pulumi.aws.route53.inputs.RecordAliasArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var selected = S3Functions.getBucket(GetBucketArgs.builder()
                .bucket("bucket.test.com")
                .build());
    
            final var testZone = Route53Functions.getZone(GetZoneArgs.builder()
                .name("test.com.")
                .build());
    
            var example = new Record("example", RecordArgs.builder()        
                .zoneId(testZone.applyValue(getZoneResult -> getZoneResult.id()))
                .name("bucket")
                .type("A")
                .aliases(RecordAliasArgs.builder()
                    .name(selected.applyValue(getBucketResult -> getBucketResult.websiteDomain()))
                    .zoneId(selected.applyValue(getBucketResult -> getBucketResult.hostedZoneId()))
                    .build())
                .build());
    
        }
    }
    
    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),
        }],
    });
    
    resources:
      example:
        type: aws:route53:Record
        properties:
          zoneId: ${testZone.id}
          name: bucket
          type: A
          aliases:
            - name: ${selected.websiteDomain}
              zoneId: ${selected.hostedZoneId}
    variables:
      selected:
        fn::invoke:
          Function: aws:s3:getBucket
          Arguments:
            bucket: bucket.test.com
      testZone:
        fn::invoke:
          Function: aws:route53:getZone
          Arguments:
            name: test.com.
    

    CloudFront Origin

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.S3.GetBucket.Invoke(new()
        {
            Bucket = "a-test-bucket",
        });
    
        var test = new Aws.CloudFront.Distribution("test", new()
        {
            Origins = new[]
            {
                new Aws.CloudFront.Inputs.DistributionOriginArgs
                {
                    DomainName = selected.Apply(getBucketResult => getBucketResult.BucketDomainName),
                    OriginId = "s3-selected-bucket",
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudfront"
    	"github.com/pulumi/pulumi-aws/sdk/v6/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
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.s3.S3Functions;
    import com.pulumi.aws.s3.inputs.GetBucketArgs;
    import com.pulumi.aws.cloudfront.Distribution;
    import com.pulumi.aws.cloudfront.DistributionArgs;
    import com.pulumi.aws.cloudfront.inputs.DistributionOriginArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var selected = S3Functions.getBucket(GetBucketArgs.builder()
                .bucket("a-test-bucket")
                .build());
    
            var test = new Distribution("test", DistributionArgs.builder()        
                .origins(DistributionOriginArgs.builder()
                    .domainName(selected.applyValue(getBucketResult -> getBucketResult.bucketDomainName()))
                    .originId("s3-selected-bucket")
                    .build())
                .build());
    
        }
    }
    
    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",
    }]});
    
    resources:
      test:
        type: aws:cloudfront:Distribution
        properties:
          origins:
            - domainName: ${selected.bucketDomainName}
              originId: s3-selected-bucket
    variables:
      selected:
        fn::invoke:
          Function: aws:s3:getBucket
          Arguments:
            bucket: a-test-bucket
    

    Using getBucket

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getBucket(args: GetBucketArgs, opts?: InvokeOptions): Promise<GetBucketResult>
    function getBucketOutput(args: GetBucketOutputArgs, opts?: InvokeOptions): Output<GetBucketResult>
    def get_bucket(bucket: Optional[str] = None,
                   opts: Optional[InvokeOptions] = None) -> GetBucketResult
    def get_bucket_output(bucket: Optional[pulumi.Input[str]] = None,
                   opts: Optional[InvokeOptions] = None) -> Output[GetBucketResult]
    func LookupBucket(ctx *Context, args *LookupBucketArgs, opts ...InvokeOption) (*LookupBucketResult, error)
    func LookupBucketOutput(ctx *Context, args *LookupBucketOutputArgs, opts ...InvokeOption) LookupBucketResultOutput

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

    public static class GetBucket 
    {
        public static Task<GetBucketResult> InvokeAsync(GetBucketArgs args, InvokeOptions? opts = null)
        public static Output<GetBucketResult> Invoke(GetBucketInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetBucketResult> getBucket(GetBucketArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:s3/getBucket:getBucket
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Bucket string

    Name of the bucket

    Bucket string

    Name of the bucket

    bucket String

    Name of the bucket

    bucket string

    Name of the bucket

    bucket str

    Name of the bucket

    bucket String

    Name of the bucket

    getBucket Result

    The following output properties are available:

    Arn string

    ARN of the bucket. Will be of format arn:aws:s3:::bucketname.

    Bucket string
    BucketDomainName string

    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 to the S3 endpoints reference for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the Virtual Hosted-Style Requests for Other Regions section in the AWS S3 User Guide.

    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

    AWS region this bucket resides in.

    WebsiteDomain string

    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

    Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

    Arn string

    ARN of the bucket. Will be of format arn:aws:s3:::bucketname.

    Bucket string
    BucketDomainName string

    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 to the S3 endpoints reference for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the Virtual Hosted-Style Requests for Other Regions section in the AWS S3 User Guide.

    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

    AWS region this bucket resides in.

    WebsiteDomain string

    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

    Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

    arn String

    ARN of the bucket. Will be of format arn:aws:s3:::bucketname.

    bucket String
    bucketDomainName String

    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 to the S3 endpoints reference for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the Virtual Hosted-Style Requests for Other Regions section in the AWS S3 User Guide.

    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

    AWS region this bucket resides in.

    websiteDomain String

    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

    Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

    arn string

    ARN of the bucket. Will be of format arn:aws:s3:::bucketname.

    bucket string
    bucketDomainName string

    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 to the S3 endpoints reference for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the Virtual Hosted-Style Requests for Other Regions section in the AWS S3 User Guide.

    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

    AWS region this bucket resides in.

    websiteDomain string

    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

    Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

    arn str

    ARN of the bucket. Will be of format arn:aws:s3:::bucketname.

    bucket str
    bucket_domain_name str

    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 to the S3 endpoints reference for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the Virtual Hosted-Style Requests for Other Regions section in the AWS S3 User Guide.

    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

    AWS region this bucket resides in.

    website_domain str

    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

    Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

    arn String

    ARN of the bucket. Will be of format arn:aws:s3:::bucketname.

    bucket String
    bucketDomainName String

    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 to the S3 endpoints reference for format. Note: AWS CloudFront allows specifying an S3 region-specific endpoint when creating an S3 origin. This will prevent redirect issues from CloudFront to the S3 Origin URL. For more information, see the Virtual Hosted-Style Requests for Other Regions section in the AWS S3 User Guide.

    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

    AWS region this bucket resides in.

    websiteDomain String

    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

    Website endpoint, if the bucket is configured with a website. If not, this will be an empty string.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes

    This Pulumi package is based on the aws Terraform Provider.

    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.3.0 published on Thursday, Sep 28, 2023 by Pulumi