■VMを建てます(今回はubuntuでテスト)
[Git Bash]
$ mkdir /c/local/vagrants/localstackvm
$ cd /c/local/vagrants/localstackvm/
$ vagrant init bento/ubuntu-22.04
$ vim Vagrantfile
----
-#config.vm.network "private_network", ip: "192.168.33.10"
+config.vm.network "private_network", ip: "192.168.56.40" # 空いているIP
----
$ vagrant up
$ vagrant ssh
■LocalStackをdockerを使って建てます。
[VM]
docker 20.10 系をインストールします。
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt update
$ sudo apt info docker-ce
$ sudo apt install docker-ce docker-ce-cli docker-compose containerd.io docker-compose-plugin
$ sudo docker version
⇒ Version: 20.10.22
$ docker version
⇒permission denied
$ sudo usermod -aG docker vagrant
$ exit
[Git Bash]
$ vagrant ssh
[VM]
$ docker version
⇒OK
$ docker version
⇒ Version: 20.10.22
$ mkdir docker-localstack
$ cd docker-localstack/
設定を編集
$ vim docker-compose.yml
----
version: "3.8"
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME-localstack_main}"
image: localstack/localstack:latest
ports:
- "4566:4566" # LocalStack Gateway
environment:
- SERVICES=dynamodb
- PERSISTENCE=1
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
----
docker起動
$ docker-compose up -d
■awsコマンドのインストール
$ sudo apt install zip
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
$ aws --version
$ aws configure
AWS Access Key ID [None]: fake
AWS Secret Access Key [None]: fake
Default region name [None]: ap-northeast-1
Default output format [None]: json
■アクセス確認
$ aws --endpoint-url=http://localhost:4566 dynamodb list-tables
{
"TableNames": []
}
192.168.56.10など他のVMからアクセスしたい場合はIPアドレスを指定する必要がある
$ aws --endpoint-url=http://192.168.56.40:4566 dynamodb list-tables
{
"TableNames": []
}