CloudBucketMount allows you to mount cloud storage buckets directly to your Modal containers. Currently supports AWS S3, Google Cloud Storage (GCS), and Cloudflare R2.
S3 buckets are mounted using AWS S3 Mountpoint, which is optimized for reading large files sequentially. It does not support every file operation - consult the AWS S3 Mountpoint documentation for more information.
AWS S3
Basic usage
Public buckets
For publicly accessible buckets, you can omit the secret:Key prefix
Mount only a specific prefix (subdirectory) of the bucket:The
key_prefix must end with a / since it will be prefixed to all object paths.Requester pays
For buckets that use requester pays:Credentials are required when using requester pays.
Cloudflare R2
Cloudflare R2 is S3-compatible, but requires thebucket_endpoint_url parameter.
Google Cloud Storage (GCS)
Google Cloud Storage is S3-compatible. GCS buckets require:- A HMAC key
- Google-specific key names in the secret
- The GCS endpoint URL
OIDC authentication
For AWS, you can use OIDC (OpenID Connect) authentication instead of static credentials:Read-write mounts
By default, mounts are read-only. To enable writes, setread_only=False:
Advanced options
Force path style
Force path-style S3 URLs instead of virtual-hosted-style:https://bucket.s3.region.amazonaws.com/key to https://s3.region.amazonaws.com/bucket/key.
API reference
CloudBucketMount parameters
Name of the cloud storage bucket to mount.
Endpoint URL for the bucket. Required for Cloudflare R2 and Google Cloud Storage.Examples:
- R2:
https://<ACCOUNT_ID>.r2.cloudflarestorage.com - GCS:
https://storage.googleapis.com
Secret containing credentials to access the bucket.
- For AWS S3: Must contain
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. OptionallyAWS_REGION. - For GCS: Must contain
GOOGLE_ACCESS_KEY_IDandGOOGLE_ACCESS_KEY_SECRET. - For R2: Must contain
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY.
Prefix to apply to all object paths. Must end with
/. Useful for mounting a specific “subdirectory” of the bucket.If True, mount the bucket as read-only. Write operations will fail.
Enable requester pays mode for S3 buckets. Requires credentials.
ARN of the IAM role to assume using OIDC authentication. Alternative to static credentials for AWS.
Force path-style S3 URLs instead of virtual-hosted-style URLs.
Limitations
- S3 Mountpoint is optimized for sequential reads of large files
- Not all filesystem operations are supported (see AWS S3 Mountpoint semantics)
- Random access and frequent small reads may have degraded performance
- Write support is limited
Best practices
- Use read-only mounts when possible for better performance and safety
- Specify AWS_REGION in your secret to avoid automatic region detection overhead
- Use key prefixes to limit the scope of mounted data
- Consider Volume for use cases requiring full filesystem semantics