localstack-state

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

State Management

状态管理

Save, load, and manage LocalStack state for reproducible development environments and state snapshots.
保存、加载并管理LocalStack状态,以实现可复现的开发环境和状态快照。

Capabilities

功能特性

  • Export and import state locally to files
  • Save and load state to/from Cloud Pods (remote storage)
  • Share state across teams via Cloud Pods
  • Enable persistent state across container restarts
  • 本地导出和导入状态到文件
  • 将状态保存到Cloud Pods(远程存储)或从其中加载
  • 通过Cloud Pods在团队间共享状态
  • 实现容器重启后的状态持久化

Local Snapshots (state export/import)

本地快照(状态导出/导入)

Local snapshots allow you to export LocalStack state to files and import them back. This works without requiring a Pro subscription.
本地快照允许您将LocalStack状态导出到文件并重新导入。此功能无需Pro订阅即可使用。

Export State

导出状态

bash
undefined
bash
undefined

Export current state to a local file

将当前状态导出到本地文件

localstack state export my-state.zip
localstack state export my-state.zip

Export to a specific path

导出到指定路径

localstack state export /path/to/backup/state.zip
undefined
localstack state export /path/to/backup/state.zip
undefined

Import State

导入状态

bash
undefined
bash
undefined

Import state from a local file

从本地文件导入状态

localstack state import my-state.zip
localstack state import my-state.zip

Import from a specific path

从指定路径导入状态

localstack state import /path/to/backup/state.zip
undefined
localstack state import /path/to/backup/state.zip
undefined

Use Cases for Local Snapshots

本地快照的使用场景

  • Backup/restore: Save state before destructive operations
  • CI/CD pipelines: Commit state files to version control for reproducible tests
  • Offline workflows: Work with state files without cloud connectivity
  • Quick snapshots: Fast local save/restore during development
  • 备份/恢复:在执行破坏性操作前保存状态
  • CI/CD流水线:将状态文件提交到版本控制,以实现可复现的测试
  • 离线工作流:无需云连接即可使用状态文件
  • 快速快照:开发过程中快速进行本地保存/恢复

Cloud Pods (pod save/load)

Cloud Pods(Pod保存/加载)

Cloud Pods store state in LocalStack's cloud platform, enabling team collaboration and remote state management.
Cloud Pods将状态存储在LocalStack的云平台中,支持团队协作和远程状态管理。

Prerequisites

前提条件

Cloud Pods require a LocalStack Pro subscription and auth token:
bash
export LOCALSTACK_AUTH_TOKEN=<your-token>
使用Cloud Pods需要LocalStack Pro订阅和认证令牌:
bash
export LOCALSTACK_AUTH_TOKEN=<your-token>

Save to Cloud Pod

保存到Cloud Pod

bash
undefined
bash
undefined

Save current state to a Cloud Pod

将当前状态保存到Cloud Pod

localstack pod save my-pod-name
localstack pod save my-pod-name

Save with a message

附带说明信息保存

localstack pod save my-pod-name --message "Initial setup with S3 and DynamoDB"
undefined
localstack pod save my-pod-name --message "Initial setup with S3 and DynamoDB"
undefined

Load from Cloud Pod

从Cloud Pod加载

bash
undefined
bash
undefined

Load state from a Cloud Pod

从Cloud Pod加载状态

localstack pod load my-pod-name
localstack pod load my-pod-name

Load and merge with existing state

加载并与现有状态合并

localstack pod load my-pod-name --merge
undefined
localstack pod load my-pod-name --merge
undefined

List Cloud Pods

列出Cloud Pods

bash
undefined
bash
undefined

List all available Cloud Pods

列出所有可用的Cloud Pods

localstack pod list
undefined
localstack pod list
undefined

Delete Cloud Pods

删除Cloud Pods

bash
undefined
bash
undefined

Delete a Cloud Pod

删除一个Cloud Pod

localstack pod delete my-pod-name
undefined
localstack pod delete my-pod-name
undefined

Inspect Cloud Pods

查看Cloud Pods详情

bash
undefined
bash
undefined

View Cloud Pod details

查看Cloud Pod详情

localstack pod inspect my-pod-name
undefined
localstack pod inspect my-pod-name
undefined

Use Cases for Cloud Pods

Cloud Pods的使用场景

  • Team collaboration: Share consistent development environments across team members
  • Demo environments: Prepare and share demo-ready states
  • Cross-machine development: Access the same state from different machines
  • 团队协作:在团队成员间共享一致的开发环境
  • 演示环境:准备并分享可直接用于演示的状态
  • 跨机器开发:从不同机器访问相同的状态

Local Persistence

本地持久化

For automatic persistence across LocalStack restarts (without explicit export/import):
bash
undefined
若要在LocalStack重启后自动保持状态(无需显式导出/导入):
bash
undefined

Enable local persistence

启用本地持久化

PERSISTENCE=1 localstack start -d
PERSISTENCE=1 localstack start -d

State is saved to .localstack/ directory

状态将保存到.localstack/目录

Survives container restarts

容器重启后仍会保留

undefined
undefined

Comparison

对比

FeatureLocal Snapshots (export/import)Cloud Pods (save/load)
StorageLocal filesLocalStack cloud
Pro requiredNoYes
Team sharingManual file sharingBuilt-in
Version controlCan commit filesCloud-managed
Offline useYesNo
特性本地快照(导出/导入)Cloud Pods(保存/加载)
存储位置本地文件LocalStack云端
是否需要Pro订阅
团队共享手动文件共享内置支持
版本控制可提交文件到版本控制云端管理
离线使用

Best Practices

最佳实践

  • Use
    state export/import
    for local development and CI/CD pipelines
  • Use Cloud Pods for team collaboration and shared environments
  • Use descriptive names that indicate the state contents
  • Enable
    PERSISTENCE=1
    for simple state retention across restarts
  • 使用
    state export/import
    进行本地开发和CI/CD流水线
  • 使用Cloud Pods进行团队协作和共享环境
  • 使用能体现状态内容的描述性名称
  • 启用
    PERSISTENCE=1
    以在重启后简单保留状态