0

Create Bucket

by
Published Jul 17, 2024

Creates a bucket on Google Cloud Storage [See the docs](https://googleapis.dev/nodejs/storage/latest/Bucket.html#create)

Script gcloud Verified

The script

Submitted by hugo697 Bun
Verified 692 days ago
1
import { Storage } from "@google-cloud/storage";
2

3
type Gcloud = {
4
  type: string;
5
  project_id: string;
6
  private_key_id: string;
7
  private_key: string;
8
  client_email: string;
9
  client_id: string;
10
  auth_uri: string;
11
  token_uri: string;
12
  auth_provider_x509_cert_url: string;
13
  client_x509_cert_url: string;
14
  universe_domain: string;
15
};
16

17
export async function main(
18
  resource: Gcloud,
19
  bucketName: string,
20
  metadata?: {
21
    location?: string;
22
    storageClass?: "STANDARD" | "NEARLINE" | "COLDLINE" | "ARCHIVE";
23
  }
24
) {
25
  const storageClient = new Storage({
26
    credentials: resource,
27
    projectId: resource.project_id,
28
  });
29

30
  const [bucket] = await storageClient.createBucket(bucketName, metadata);
31

32
  return bucket.metadata;
33
}
34