1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. storage
  5. getBucketObjectContents
Viewing docs for Google Cloud v9.15.0
published on Thursday, Mar 12, 2026 by Pulumi
gcp logo
Viewing docs for Google Cloud v9.15.0
published on Thursday, Mar 12, 2026 by Pulumi

    Gets existing object contents inside an existing bucket in Google Cloud Storage service (GCS). See the official documentation and API.

    Warning: The object content will be saved in the state, and visible to everyone who has access to the state file.

    Warning: This data source loads all object contents into memory. Limit the results with match_glob or prefix.

    Example Usage

    Extract object base64 contents from objects:

    import * as pulumi from "@pulumi/pulumi";
    import * as gcp from "@pulumi/gcp";
    
    const example = gcp.storage.getBucketObjectContents({
        bucket: "example-bucket",
        matchGlob: "example-{foo,bar}.json",
        prefix: "example",
    });
    export const base64EncodedJsonContents = example.then(example => example.bucketObjects.map(__item => __item.contentBase64));
    
    import pulumi
    import pulumi_gcp as gcp
    
    example = gcp.storage.get_bucket_object_contents(bucket="example-bucket",
        match_glob="example-{foo,bar}.json",
        prefix="example")
    pulumi.export("base64EncodedJsonContents", [__item.content_base64 for __item in example.bucket_objects])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/storage"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
    example, err := storage.GetBucketObjectContents(ctx, &storage.GetBucketObjectContentsArgs{
    Bucket: "example-bucket",
    MatchGlob: pulumi.StringRef("example-{foo,bar}.json"),
    Prefix: pulumi.StringRef("example"),
    }, nil);
    if err != nil {
    return err
    }
    ctx.Export("base64EncodedJsonContents", pulumi.StringArray(%!v(PANIC=Format method: fatal: A failure has occurred: unlowered splat expression @ example.pp:7,11-49)))
    return nil
    })
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Gcp = Pulumi.Gcp;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Gcp.Storage.GetBucketObjectContents.Invoke(new()
        {
            Bucket = "example-bucket",
            MatchGlob = "example-{foo,bar}.json",
            Prefix = "example",
        });
    
        return new Dictionary<string, object?>
        {
            ["base64EncodedJsonContents"] = example.Apply(getBucketObjectContentsResult => getBucketObjectContentsResult.BucketObjects).Select(__item => __item.ContentBase64).ToList(),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.gcp.storage.StorageFunctions;
    import com.pulumi.gcp.storage.inputs.GetBucketObjectContentsArgs;
    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 example = StorageFunctions.getBucketObjectContents(GetBucketObjectContentsArgs.builder()
                .bucket("example-bucket")
                .matchGlob("example-{foo,bar}.json")
                .prefix("example")
                .build());
    
            ctx.export("base64EncodedJsonContents", example.bucketObjects().stream().map(element -> element.contentBase64()).collect(toList()));
        }
    }
    
    Example coming soon!
    

    Using getBucketObjectContents

    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 getBucketObjectContents(args: GetBucketObjectContentsArgs, opts?: InvokeOptions): Promise<GetBucketObjectContentsResult>
    function getBucketObjectContentsOutput(args: GetBucketObjectContentsOutputArgs, opts?: InvokeOptions): Output<GetBucketObjectContentsResult>
    def get_bucket_object_contents(bucket: Optional[str] = None,
                                   match_glob: Optional[str] = None,
                                   prefix: Optional[str] = None,
                                   opts: Optional[InvokeOptions] = None) -> GetBucketObjectContentsResult
    def get_bucket_object_contents_output(bucket: Optional[pulumi.Input[str]] = None,
                                   match_glob: Optional[pulumi.Input[str]] = None,
                                   prefix: Optional[pulumi.Input[str]] = None,
                                   opts: Optional[InvokeOptions] = None) -> Output[GetBucketObjectContentsResult]
    func GetBucketObjectContents(ctx *Context, args *GetBucketObjectContentsArgs, opts ...InvokeOption) (*GetBucketObjectContentsResult, error)
    func GetBucketObjectContentsOutput(ctx *Context, args *GetBucketObjectContentsOutputArgs, opts ...InvokeOption) GetBucketObjectContentsResultOutput

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

    public static class GetBucketObjectContents 
    {
        public static Task<GetBucketObjectContentsResult> InvokeAsync(GetBucketObjectContentsArgs args, InvokeOptions? opts = null)
        public static Output<GetBucketObjectContentsResult> Invoke(GetBucketObjectContentsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetBucketObjectContentsResult> getBucketObjectContents(GetBucketObjectContentsArgs args, InvokeOptions options)
    public static Output<GetBucketObjectContentsResult> getBucketObjectContents(GetBucketObjectContentsArgs args, InvokeOptions options)
    
    fn::invoke:
      function: gcp:storage/getBucketObjectContents:getBucketObjectContents
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Bucket string
    The name of the containing bucket.
    MatchGlob string
    A glob pattern used to filter results (for example, foo*bar).
    Prefix string
    Filter results to include only objects whose names begin with this prefix.
    Bucket string
    The name of the containing bucket.
    MatchGlob string
    A glob pattern used to filter results (for example, foo*bar).
    Prefix string
    Filter results to include only objects whose names begin with this prefix.
    bucket String
    The name of the containing bucket.
    matchGlob String
    A glob pattern used to filter results (for example, foo*bar).
    prefix String
    Filter results to include only objects whose names begin with this prefix.
    bucket string
    The name of the containing bucket.
    matchGlob string
    A glob pattern used to filter results (for example, foo*bar).
    prefix string
    Filter results to include only objects whose names begin with this prefix.
    bucket str
    The name of the containing bucket.
    match_glob str
    A glob pattern used to filter results (for example, foo*bar).
    prefix str
    Filter results to include only objects whose names begin with this prefix.
    bucket String
    The name of the containing bucket.
    matchGlob String
    A glob pattern used to filter results (for example, foo*bar).
    prefix String
    Filter results to include only objects whose names begin with this prefix.

    getBucketObjectContents Result

    The following output properties are available:

    Bucket string
    BucketObjects List<GetBucketObjectContentsBucketObject>
    A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
    Id string
    The provider-assigned unique ID for this managed resource.
    MatchGlob string
    Prefix string
    Bucket string
    BucketObjects []GetBucketObjectContentsBucketObject
    A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
    Id string
    The provider-assigned unique ID for this managed resource.
    MatchGlob string
    Prefix string
    bucket String
    bucketObjects List<GetBucketObjectContentsBucketObject>
    A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
    id String
    The provider-assigned unique ID for this managed resource.
    matchGlob String
    prefix String
    bucket string
    bucketObjects GetBucketObjectContentsBucketObject[]
    A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
    id string
    The provider-assigned unique ID for this managed resource.
    matchGlob string
    prefix string
    bucket str
    bucket_objects Sequence[GetBucketObjectContentsBucketObject]
    A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
    id str
    The provider-assigned unique ID for this managed resource.
    match_glob str
    prefix str
    bucket String
    bucketObjects List<Property Map>
    A list of retrieved object contents contained in the provided GCS bucket. Structure is defined below.
    id String
    The provider-assigned unique ID for this managed resource.
    matchGlob String
    prefix String

    Supporting Types

    GetBucketObjectContentsBucketObject

    Content string
    The content of the object.
    ContentBase64 string
    Base64 encoded version of the object content. Use this when dealing with binary data.
    ContentBase64sha512 string
    Base64 encoded SHA512 checksum of file content.
    ContentHexsha512 string
    Hex encoded SHA512 checksum of file content.
    ContentType string
    Content-Type of the object data.
    MediaLink string
    A url reference to download this object.
    Name string
    The name of the object.
    SelfLink string
    A url reference to this object.
    Content string
    The content of the object.
    ContentBase64 string
    Base64 encoded version of the object content. Use this when dealing with binary data.
    ContentBase64sha512 string
    Base64 encoded SHA512 checksum of file content.
    ContentHexsha512 string
    Hex encoded SHA512 checksum of file content.
    ContentType string
    Content-Type of the object data.
    MediaLink string
    A url reference to download this object.
    Name string
    The name of the object.
    SelfLink string
    A url reference to this object.
    content String
    The content of the object.
    contentBase64 String
    Base64 encoded version of the object content. Use this when dealing with binary data.
    contentBase64sha512 String
    Base64 encoded SHA512 checksum of file content.
    contentHexsha512 String
    Hex encoded SHA512 checksum of file content.
    contentType String
    Content-Type of the object data.
    mediaLink String
    A url reference to download this object.
    name String
    The name of the object.
    selfLink String
    A url reference to this object.
    content string
    The content of the object.
    contentBase64 string
    Base64 encoded version of the object content. Use this when dealing with binary data.
    contentBase64sha512 string
    Base64 encoded SHA512 checksum of file content.
    contentHexsha512 string
    Hex encoded SHA512 checksum of file content.
    contentType string
    Content-Type of the object data.
    mediaLink string
    A url reference to download this object.
    name string
    The name of the object.
    selfLink string
    A url reference to this object.
    content str
    The content of the object.
    content_base64 str
    Base64 encoded version of the object content. Use this when dealing with binary data.
    content_base64sha512 str
    Base64 encoded SHA512 checksum of file content.
    content_hexsha512 str
    Hex encoded SHA512 checksum of file content.
    content_type str
    Content-Type of the object data.
    media_link str
    A url reference to download this object.
    name str
    The name of the object.
    self_link str
    A url reference to this object.
    content String
    The content of the object.
    contentBase64 String
    Base64 encoded version of the object content. Use this when dealing with binary data.
    contentBase64sha512 String
    Base64 encoded SHA512 checksum of file content.
    contentHexsha512 String
    Hex encoded SHA512 checksum of file content.
    contentType String
    Content-Type of the object data.
    mediaLink String
    A url reference to download this object.
    name String
    The name of the object.
    selfLink String
    A url reference to this object.

    Package Details

    Repository
    Google Cloud (GCP) Classic pulumi/pulumi-gcp
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the google-beta Terraform Provider.
    gcp logo
    Viewing docs for Google Cloud v9.15.0
    published on Thursday, Mar 12, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.