kakakakakku blog

Weekly Tech Blog: Keep Learning!

lstk コマンドで LocalStack を操作しよう

LocalStack の CLI ツールとして新しく「lstk(lstk コマンド)」がリリースされた🎉 Go で再実装されて,今後は LocalStack for AWS 以外に LocalStack for Snowflake なども起動できるようになる予定とのこと.2026年3月23日から LocalStack は Hobby プランだとしても認証が必要になっていて,lstk にはブラウザ経由で自動的に認証をして認証トークンを保存する仕組みも含まれている👌

github.com

今までは「LocalStack CLI(localstack コマンド)」を使っていたけど,今後は lstk を使う流れになりそう.しかし現状ではまだ安定版をリリースしてなく破壊的変更が入る可能性もある.

docs.localstack.cloud

インストール

今回は Homebrew でインストールする.

$ brew install localstack/tap/lstk

$ lstk --version
lstk 0.5.4

lstk login コマンド

まずは lstk login コマンドで認証をする.コマンドを実行するとブラウザが自動的に起動して,LocalStack アカウントで認証できるようになっている.簡単❗️

$ lstk login

   ▟████▖   lstk (0.5.4)
  ▟██▙█▙█▟
    ▀▛▀▛▀

> Welcome to lstk, a command-line interface for LocalStack

Opening browser to login...
Browser didn't open? Visit https://app.localstack.cloud/auth/request/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx?code=xxxx

One-time code: xxxx

Waiting for authorization... (Press any key when complete)
Checking if auth request is confirmed...
Auth request confirmed, exchanging for token...
Fetching license token...
✔︎ Login successful.

lstk start コマンド

次に lstk start コマンド(もしくはサブコマンドなしの lstk コマンド)で LocalStack を起動する.2026年3月23日から LocalStack のイメージは1つに統合されたため localstack/localstack-pro:latest が使われていることも確認できる.

$ lstk start

   ▟████▖   lstk (0.5.4)
  ▟██▙█▙█▟  LocalStack AWS Emulator
    ▀▛▀▛▀   localhost.localstack.cloud:4566

✔︎ Pulled localstack/localstack-pro:latest
LocalStack: validating license (2026.3.1.dev35)
Starting LocalStack...
Waiting for LocalStack to be ready...
✔︎ LocalStack ready (containerId: 5e8ba8e0598c)
• Endpoint: localhost.localstack.cloud:4566
• Web app: https://app.localstack.cloud
> Tip: View deployed resources: lstk status

awslocal コマンド

動作確認のために LocalStack AWS CLI(awslocal コマンド)を使う.

github.com

lstk で起動した LocalStack 上に Amazon SQS キューと Amazon S3 バケットをデプロイできた👌

$ awslocal sqs create-queue --queue-name sandbox
{
    "QueueUrl": "http://sqs.ap-northeast-1.localhost.localstack.cloud:4566/000000000000/sandbox"
}

$ awslocal s3api create-bucket --bucket sandbox --create-bucket-configuration LocationConstraint=ap-northeast-1
{
    "Location": "http://sandbox.s3.localhost.localstack.cloud:4566/",
    "BucketArn": "arn:aws:s3:::sandbox"
}

lstk status コマンド

lstk status コマンドは LocalStack のステータスだけではなく,デプロイされた AWS リソースの一覧も確認できる.デプロイ状況がわからなくなることはあるからこれは便利だと思う.

$ lstk lstk status
✔︎ LocalStack AWS Emulator is running (localhost.localstack.cloud:4566)
  UPTIME: 2m 16s · CONTAINER: localstack-aws · VERSION: 2026.3.1.dev35

~ 2 resources · 2 services

  SERVICE  RESOURCE                                                                        REGION          ACCOUNT
  S3       sandbox                                                                         global          000000000000
  SQS      http://sqs.ap-northeast-1.localhost.localstack.cloud:4566/000000000000/sandbox  ap-northeast-1  000000000000

lstk config path コマンド

lstk で LocalStack を起動すると自動的に ${HOME}/.config/lstk/config.toml に lstk の設定ファイルが作られる.そして lstk config path コマンドを実行すると読み込まれる設定ファイルのパスを取得できる.

$ lstk config path
/Users/kakakakakku/.config/lstk/config.toml

ちなみに lstk の README に書いてある通り,優先順位的にはプロジェクト直下の ./.lstk/config.toml を参照して,なかったら ${HOME}/.config/lstk/config.toml を参照するような仕組みになっている.実際にプロジェクト直下に設定ファイルを置くと lstk config path コマンドの出力結果も変わる👌

$ lstk config path
/Users/kakakakakku/lstk-sandbox/.lstk/config.toml

lstk completion コマンド

lstk completion コマンドでコマンド補完のためのスクリプトが出力される👌今回は .zshrc に含めることにした.

source <(lstk completion zsh)

すると lstk <TAB> でサブコマンドが補完されるようになって便利❗️

$ lstk <TAB>
completion  -- Generate the autocompletion script for the specified shell
config      -- Manage configuration
help        -- Help about any command
login       -- Manage login
logout      -- Remove stored authentication credentials
logs        -- Show emulator logs
start       -- Start emulator
status      -- Show emulator status and deployed resources
stop        -- Stop emulator
update      -- Update lstk to the latest version

その他

他にもログを確認する lstk logs コマンドや lstk 自体をアップデートする lstk update コマンドなどもある👌

関連記事

blog.localstack.cloud

YouTube

タイミング良く lstk コマンドを紹介するウェビナーが開催されていて YouTube に動画が公開されていた❗️lstk の解説と lstk コマンドのライブデモなど.lstk は エルエスティーケー って呼べば良いっていう発見があった💡

www.youtube.com