Dependencies
Bucket
The Bucket dependency allows you to easily get a connection to your remote storage bucket (S3 or GCS) that is configured with a buildflow bucket primitive.
To construct a dependency you can use the buildflow.dependencies.bucket.BucketDependencyBuilder
builder with the following arguments:
Arg | Description |
---|---|
bucket_primitive | The S3Bucket or GCSBucket primitive referencing the bucket that should be connected to. |
gcp_quota_project_id | The GCP project to bill API usage to if you are connecting to a GCS bucket defaults to the project the bucket exists in. |
aws_region | The AWS region to use if you are connecting to a S3 bucket, defaults to the region configured in your environment |
The dependency will provide an object containing a reference to the bucket in the bucket
field.
If you are connecting to a GCS bucket this will be a google cloud storage Bucket object returned by the google client library.
If you are connecting to a S3 bucket this will be a s3 Bucket resource returned by boto3.
GCS Usage
from buildflow.dependencies.bucket import BucketDependencyBuilder
from buildflow.io.gcp import GCSBucket
bucket = GCSBucket(project_id="project", bucket_name="bucket")
BucketDep = BucketDependencyBuilder(bucket)
@app.endpoint("/", method="POST")
def endpoint(bucket_dep: BucketDep):
blobs = bucket_dep.list_blobs()
S3 Usage
from buildflow.dependencies.bucket import BucketDependencyBuilder
from buildflow.io.aws import S3Bucket
bucket = S3Bucket(bucket_name="bucket", aws_region="us-east-1")
BucketDep = BucketDependencyBuilder(bucket)
@app.endpoint("/", method="POST")
def endpoint(bucket_dep: BucketDep):
objects = bucket_dep.bucket.objects.all()