import tiledb
import os
# You should set the appropriate environment variables with your keys.
# Get the keys from the environment variables.
= os.environ["AWS_ACCESS_KEY_ID"]
aws_access_key_id = os.environ["AWS_SECRET_ACCESS_KEY"]
aws_secret_access_key
# Get the bucket and region from environment variables
= os.environ["S3_BUCKET"]
s3_bucket = os.environ["S3_REGION"]
s3_region
# Set the AWS keys and region to the config of the default context
# This context initialization can be performed only once.
= tiledb.Config(
cfg
{"vfs.s3.aws_access_key_id": aws_access_key_id,
"vfs.s3.aws_secret_access_key": aws_secret_access_key,
"vfs.s3.region": s3_region,
}
) tiledb.default_ctx(cfg)
Basic S3 Example
You can run this tutorial in two ways:
- Locally on your machine.
- On TileDB Cloud.
However, since TileDB Cloud has a free tier, we strongly recommend that you sign up and run everything there, as that requires no installations or deployment.
This tutorial shows the basic usage of TileDB on Amazon S3. It assumes you have already created an account, a bucket, and the credentials required to access the bucket. For more details on the TileDB S3 usage, as well as information about how to use TileDB with other object stores, visit the Advanced Backends section.
In order for TileDB to be able to access S3 buckets, it needs to know the S3 region and your secret keys. You need to pass this information into the configuration of a TileDB context object. It’s good practice not to share private information in notebooks. One way to do this more securely is to set your keys into environment variables and then have your code read those variables, which is what this tutorial does in the following code snippet.
The rest of the tutorial is almost the same as the Tutorials: Basic Dense section, whereas you can create, write, and read any array in the same manner after setting up your AWS keys as shown earlier.
First, import the necessary libraries, set the array URI (that is, its path, which in this tutorial will be on local storage), and delete any previously created arrays with the same name.
Next, create the array by specifying its schema.
Populate the array with a 2D NumPy array.
The array is now a prefix in the path specified in array_uri
, which is similar to a subfolder on your local storage.
Read the data by using the slicing methods supported in TileDB.
Clean up in the end by deleting the array.