Skip to main content
Enterprise only
This tutorial downloads a small UTF-8 text object from a private S3 bucket into a LanceDB column. You create a Secret, register a Python Function that reads it, then refresh the column and read the downloaded text. The AWS credentials authorize the Function’s requests to your source bucket. LanceDB manages access to the table’s own storage separately. Registering this Secret does not configure table storage or a storage integration.

Prepare the deployment and source object

You need:
  • A LanceDB Enterprise deployment with Functions and Secrets enabled, including KMS configuration for Secrets.
  • The Python SDK version supported by your deployment, with pyarrow installed in your local Python environment.
  • An existing database and root namespace (public). Use new object names for this tutorial; creating an existing Secret or table fails.
  • A small UTF-8 text object in S3. The AWS identity needs s3:GetObject on that object. For an object encrypted with SSE-KMS, it also needs kms:Decrypt and permission through the key policy. Workers need network access to S3.
Set these variables in the process running the Python examples, loading credentials from your credential manager rather than placing values in source: Run the Python blocks in order in the same script or session. The worker installs Boto3 from the Function’s dependency declaration below; your local process does not need Boto3.

Grant access

An administrator grants the tutorial principal access to the existing database and namespace, and permission to create its objects. For an existing role named s3_ingest, run this SQL in the tutorial database, replacing the database and role names as needed:
Use a LanceDB credential acting under that role for the Python steps. The creator owns the new Secret, Function, and table. When different principals own or use these objects, the required privileges are: All operations also require USAGE on the containing database and namespaces. For example, after creating the objects, grant another existing role permission to use the Secret with:
A role reading a populated column does not run the Function or need its Secret. See privileges for the remaining grant syntax.

Connect and create the Secret

The Secret contains one JSON string so the key pair and session token can be altered together. Its value must fit your deployment’s Secret size limit. The Function definition below contains only the environment variable name; it does not capture this local dictionary or its values.

Define and register the Function

A class Function creates one S3 client per worker instance and reuses it for that instance’s rows. It reads credentials through its declared Secret binding.
Registration builds the remote environment and returns an immutable Function version after the build succeeds. Imports and credential reads happen inside the worker, after Secret delivery. The explicit Boto3 session uses the bound credentials for source downloads. It does not rely on a worker role, a local AWS profile, or table storage credentials.

Add, refresh, and read the column

The Function’s str parameters require non-nullable string input columns. Its region initialization parameter is a fixed value for this column binding.
If the source object contains Hello from S3!, the row’s content contains that text. add_columns declares an empty output column; automatic refresh is disabled here so the explicit refresh performs the download. Subsequent reads return the stored text without contacting S3. Updating the source object does not automatically update an already populated column. This example reads each complete object into worker memory and decodes UTF-8. Use small text objects for the tutorial. Binary files need a different output schema and decoding logic; large objects need a suitable streaming or blob workflow. AWS request errors and invalid UTF-8 propagate as Function failures.

Alter credentials and handle expiry

After loading a complete replacement credential set into this Python process’s environment, replace the Secret’s JSON value:
Set AWS_SESSION_TOKEN from the same temporary credential set as the new keys. Remove an old session token when switching to long-lived keys. Updating a parent shell’s environment does not update an already running Python process. Alteration keeps the same Secret name, Function version, and column binding. Future jobs capture the replacement value. A running job and its retries keep the credential value captured for that job; alteration does not replace their client credentials or recompute existing output rows. Temporary credentials passed explicitly to Boto3 do not renew automatically. Choose a credential lifetime that covers the complete refresh, including retries. If AWS expires or revokes those credentials, subsequent S3 requests can fail even after the Secret has been altered. Split long backfills into jobs that fit the credential lifetime, renewing credentials between jobs. After replacing an expired credential, submit a new refresh for unfilled rows so it captures the new value. See refresh behavior for recomputation and retry controls. Dropping a Secret prevents future jobs from resolving it, but does not recall credentials already delivered to running work. Revoke the credential in AWS when immediate revocation is required. Never print, return, or log the Secret’s JSON or its fields; redaction does not protect transformed values. See Secret delivery for more detail.