Skip to content

s3 ​

Read and write text or binary objects in Amazon S3, create buckets, and generate presigned download links. No AWS SDK installation is needed.

Credentials come from the standard AWS environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and optionally AWS_SESSION_TOKEN). The region defaults to AWS_REGION, then us-east-1, and can be overridden per call.

ts
import { s3Put, s3Get } from "std::aws/s3"

node main() {
  s3Put("my-bucket", "notes.txt", "hello") with approve
  const text = s3Get("my-bucket", "notes.txt") with approve
  print(text)
}

Bind bucket with .partial(bucket: "my-bucket") before handing a function to an agent to keep that tool within one bucket.

Binary uploads and downloads use base64 strings.

Types ​

S3PutResult ​

The result of a successful s3Put / s3PutBinary.

ts
/** The result of a successful `s3Put` / `s3PutBinary`. */
export type S3PutResult = {
  bucket: string;
  key: string;
  url: string;
  etag: string
}

(source)

S3CreateBucketResult ​

The result of a successful createBucket.

ts
/** The result of a successful `createBucket`. */
export type S3CreateBucketResult = {
  bucket: string;
  region: string;
  location: string
}

(source)

Effects ​

std::aws::s3::get ​

ts
effect std::aws::s3::get {
  bucket: string;
  key: string;
  region: string
}

(source)

std::aws::s3::getBinary ​

ts
effect std::aws::s3::getBinary {
  bucket: string;
  key: string;
  region: string
}

(source)

std::aws::s3::put ​

ts
effect std::aws::s3::put {
  bucket: string;
  key: string;
  region: string
}

(source)

std::aws::s3::putBinary ​

ts
effect std::aws::s3::putBinary {
  bucket: string;
  key: string;
  region: string
}

(source)

std::aws::s3::createBucket ​

ts
effect std::aws::s3::createBucket {
  bucket: string;
  region: string
}

(source)

std::aws::s3::presignGet ​

ts
effect std::aws::s3::presignGet {
  bucket: string;
  key: string;
  expiresIn: number;
  region: string
}

(source)

Functions ​

s3Get ​

ts
s3Get(
  bucket: string,
  key: string,
  region: string = "",
): Result<string> raises <std::aws::s3::get>

Download an S3 object as UTF-8 text.

Parameters:

NameTypeDefaultDescription
bucketstring
keystringA non-empty object key with no complete "." or ".." path segments.
regionstring""Leave empty to use AWS_REGION, then us-east-1.

Returns: Result<string>

Throws: std::aws::s3::get

Needs: network

(source)

s3GetBinary ​

ts
s3GetBinary(
  bucket: string,
  key: string,
  region: string = "",
): Result<string> raises <std::aws::s3::getBinary>

Download an S3 object as a base64 string.

Parameters:

NameTypeDefaultDescription
bucketstring
keystringA non-empty object key with no complete "." or ".." path segments.
regionstring""Leave empty to use AWS_REGION, then us-east-1.

Returns: Result<string>

Throws: std::aws::s3::getBinary

Needs: network

(source)

s3Put ​

ts
s3Put(
  bucket: string,
  key: string,
  content: string,
  region: string = "",
  contentType: string = "text/plain",
): Result<S3PutResult> raises <std::aws::s3::put>

Upload UTF-8 text to an S3 object.

Parameters:

NameTypeDefaultDescription
bucketstring
keystringA non-empty object key with no complete "." or ".." path segments.
contentstring
regionstring""Leave empty to use AWS_REGION, then us-east-1.
contentTypestring"text/plain"The MIME type readers should use for the object.

Returns: Result<S3PutResult>

Throws: std::aws::s3::put

Needs: network

(source)

s3PutBinary ​

ts
s3PutBinary(
  bucket: string,
  key: string,
  base64: string,
  region: string = "",
  contentType: string = "application/octet-stream",
): Result<S3PutResult> raises <std::aws::s3::putBinary>

Upload base64-encoded binary to an S3 object.

Parameters:

NameTypeDefaultDescription
bucketstring
keystringA non-empty object key with no complete "." or ".." path segments.
base64stringValid base64 encoding of the bytes to upload.
regionstring""Leave empty to use AWS_REGION, then us-east-1.
contentTypestring"application/octet-stream"The MIME type readers should use for the object.

Returns: Result<S3PutResult>

Throws: std::aws::s3::putBinary

Needs: network

(source)

s3PresignGet ​

ts
s3PresignGet(
  bucket: string,
  key: string,
  expiresIn: number = 1h,
  region: string = "",
): Result<string> raises <std::aws::s3::presignGet>

Create a shareable download URL for a private S3 object.

The URL is computed locally without downloading the object. Treat it as a credential: anyone holding it can download the object. With temporary AWS credentials, it stops working when the session expires even if the requested expiry is later.

Parameters:

NameTypeDefaultDescription
bucketstring
keystringA non-empty object key with no complete "." or ".." path segments.
expiresInnumber1hA whole number of milliseconds from 1 through 604800000, at most seven days.
regionstring""Leave empty to use AWS_REGION, then us-east-1.

Returns: Result<string>

Throws: std::aws::s3::presignGet

(source)

createBucket ​

ts
createBucket(
  bucket: string,
  region: string = "",
): Result<S3CreateBucketResult> raises <std::aws::s3::createBucket>

Create an S3 bucket.

Parameters:

NameTypeDefaultDescription
bucketstringA globally unique S3 bucket name.
regionstring""Leave empty to use AWS_REGION, then us-east-1.

Returns: Result<S3CreateBucketResult>

Throws: std::aws::s3::createBucket

Needs: network

(source)