Prerequisite

  • Download and install grpcurl.
  • Your S2 authentication token. Checkout the quickstart for instructions.
export S2_AUTH_TOKEN="your-s2-auth-token"

Basins

Basins serve as globally-unique namespaces for streams.

Create a basin

Create an initial basin to work with. This is where your streams will live.

(grpcurl \
-H "Authorization: Bearer ${S2_AUTH_TOKEN}" \
-d @ aws.s2.dev:443 s2.v1alpha.AccountService/CreateBasin <<EOM
{
  "basin": "my-first-basin"
}
EOM
)

List basins

You might end up using many basins. List all of the basins owned by your account with:

grpcurl \
  -H "Authorization: Bearer ${S2_AUTH_TOKEN}" \
  aws.s2.dev:443 s2.v1alpha.AccountService/ListBasins

Streams

Streams are the fundamental building block of S2. Create an unlimited amount.

Create a stream

Create a new stream, optionally specifying a StreamConfig.

In this case, we’ll use the Standard storage class, and configure the stream to auto-trim data after 24 hours.

(grpcurl \
-H "Authorization: Bearer ${S2_AUTH_TOKEN}" \
-d @ my-first-basin.b.aws.s2.dev:443 s2.v1alpha.BasinService/CreateStream <<EOM
{
  "stream": "my-stream",
  "config": {
    "storage_class": 1,
    "age": 86400
  }
}
EOM
)

Append records

Next, we can try appending a batch of records. S2 provides both streaming and unary RPCs for appending. Here, we’ll just make a unary request.

Each record batch is formulated as an AppendInput. For now, we’ll just stick with a simple batch containing of a single record. The record body will be base64-encoded binary data.

(grpcurl \
-H "Authorization: Bearer ${S2_AUTH_TOKEN}" \
-d @ my-first-basin.b.aws.s2.dev:443 s2.v1alpha.StreamService/Append <<EOM
{
  "input": {
    "stream": "my-stream",
    "records": [
      { "body": "SGVsbG8gd29ybGQhCg==" }
    ]
  }
}
EOM
)

Read records

Let’s read it back! Again, we can open a streaming session, using ReadSessionRequest, or make a single unary read. We’ll do the latter below.

(grpcurl \
-H "Authorization: Bearer ${S2_AUTH_TOKEN}" \
-d @ my-first-basin.b.aws.s2.dev:443 s2.v1alpha.StreamService/Read <<EOM
{
  "stream": "my-stream",
  "start_seq_num": 0
}
EOM
)