Skip to content

state

Source: src/AWS/StateStore/State.ts

State store backed by an AWS S3 bucket.

Stack state is persisted as JSON objects in an account-regional S3 bucket, laid out exactly like the local state store’s file tree with the bucket (plus optional prefix) taking the place of the .alchemy/state directory:

s3://{bucket}/{prefix}{stack}/{stage}/{fqn}.json
s3://{bucket}/{prefix}{stack}/{stage}/__stack_output__.json

The bucket is created lazily on the first state operation if it does not already exist — nothing touches AWS credentials at layer construction time.

Pass AWS.state() as the state option of a Stack. By default the state is stored in an account-regional bucket named alchemy-state-{accountId}-{region}-an.

Default bucket

import * as Alchemy from "alchemy";
import * as AWS from "alchemy/AWS";
const Stack = Alchemy.Stack(
"my-stack",
{ providers: AWS.providers(), state: AWS.state() },
Effect.gen(function* () {
// ...
}),
);

Custom bucket and key prefix

const Stack = Alchemy.Stack(
"my-stack",
{
providers: AWS.providers(),
state: AWS.state({
bucketName: "my-company-state",
prefix: "alchemy",
}),
},
Effect.gen(function* () {
// ...
}),
);