# Storage (S3-compatible)

Managed S3-compatible object storage.

```hcl
storage "uploads" {}

storage "assets" {}
```

Reference storage attributes in env blocks:

```hcl
service "api" {
  build = build.api
  command = "./api"

  endpoint {
    public = true
  }

  env = {
    S3_ENDPOINT   = storage.uploads.endpoint
    S3_ACCESS_KEY = storage.uploads.access_key
    S3_SECRET_KEY = storage.uploads.secret_key
    S3_BUCKET     = storage.uploads.bucket
  }
}

storage "uploads" {}
```

## Available storage attributes

- `endpoint` - S3-compatible endpoint URL (e.g., `http://127.0.0.1:5000`)
- `access_key` - Access key for authentication
- `secret_key` - Secret key for authentication
- `bucket` - Bucket name

## Example using AWS SDK (JavaScript)

```javascript
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

const s3 = new S3Client({
  endpoint: process.env.S3_ENDPOINT,
  region: "us-east-1", // Required but ignored locally
  credentials: {
    accessKeyId: process.env.S3_ACCESS_KEY,
    secretAccessKey: process.env.S3_SECRET_KEY,
  },
  forcePathStyle: true, // Required for local S3-compatible servers
});

await s3.send(
  new PutObjectCommand({
    Bucket: process.env.S3_BUCKET,
    Key: "myfile.txt",
    Body: "Hello, world!",
  })
);
```
