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.
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.
/** 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.
/** The result of a successful `createBucket`. */
export type S3CreateBucketResult = {
bucket: string;
region: string;
location: string
}(source)
Effects
std::aws::s3::get
effect std::aws::s3::get {
bucket: string;
key: string;
region: string
}(source)
std::aws::s3::getBinary
effect std::aws::s3::getBinary {
bucket: string;
key: string;
region: string
}(source)
std::aws::s3::put
effect std::aws::s3::put {
bucket: string;
key: string;
region: string
}(source)
std::aws::s3::putBinary
effect std::aws::s3::putBinary {
bucket: string;
key: string;
region: string
}(source)
std::aws::s3::createBucket
effect std::aws::s3::createBucket {
bucket: string;
region: string
}(source)
std::aws::s3::presignGet
effect std::aws::s3::presignGet {
bucket: string;
key: string;
expiresIn: number;
region: string
}(source)
Functions
s3Get
s3Get(
bucket: string,
key: string,
region: string = "",
): Result<string> raises <std::aws::s3::get>Download an S3 object as UTF-8 text.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| bucket | string | ||
| key | string | A non-empty object key with no complete "." or ".." path segments. | |
| region | string | "" | Leave empty to use AWS_REGION, then us-east-1. |
Returns: Result<string>
Throws: std::aws::s3::get
Needs: network
(source)
s3GetBinary
s3GetBinary(
bucket: string,
key: string,
region: string = "",
): Result<string> raises <std::aws::s3::getBinary>Download an S3 object as a base64 string.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| bucket | string | ||
| key | string | A non-empty object key with no complete "." or ".." path segments. | |
| region | string | "" | Leave empty to use AWS_REGION, then us-east-1. |
Returns: Result<string>
Throws: std::aws::s3::getBinary
Needs: network
(source)
s3Put
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:
| Name | Type | Default | Description |
|---|---|---|---|
| bucket | string | ||
| key | string | A non-empty object key with no complete "." or ".." path segments. | |
| content | string | ||
| region | string | "" | Leave empty to use AWS_REGION, then us-east-1. |
| contentType | string | "text/plain" | The MIME type readers should use for the object. |
Returns: Result<S3PutResult>
Throws: std::aws::s3::put
Needs: network
(source)
s3PutBinary
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:
| Name | Type | Default | Description |
|---|---|---|---|
| bucket | string | ||
| key | string | A non-empty object key with no complete "." or ".." path segments. | |
| base64 | string | Valid base64 encoding of the bytes to upload. | |
| region | string | "" | Leave empty to use AWS_REGION, then us-east-1. |
| contentType | string | "application/octet-stream" | The MIME type readers should use for the object. |
Returns: Result<S3PutResult>
Throws: std::aws::s3::putBinary
Needs: network
(source)
s3PresignGet
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:
| Name | Type | Default | Description |
|---|---|---|---|
| bucket | string | ||
| key | string | A non-empty object key with no complete "." or ".." path segments. | |
| expiresIn | number | 1h | A whole number of milliseconds from 1 through 604800000, at most seven days. |
| region | string | "" | Leave empty to use AWS_REGION, then us-east-1. |
Returns: Result<string>
Throws: std::aws::s3::presignGet
(source)
createBucket
createBucket(
bucket: string,
region: string = "",
): Result<S3CreateBucketResult> raises <std::aws::s3::createBucket>Create an S3 bucket.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| bucket | string | A globally unique S3 bucket name. | |
| region | string | "" | Leave empty to use AWS_REGION, then us-east-1. |
Returns: Result<S3CreateBucketResult>
Throws: std::aws::s3::createBucket
Needs: network
(source)