[アップデート] CloudShell 環境に DynamoDB Local がプリインストールされて利用可能になりました
こんにちは!クラウド事業本部コンサルティング部のたかくに(@takakuni_)です。
CloudShell で DynamoDB Local がプリインストールされ利用可能になりました。
DynamoDB Local
DynamoDB Local はローカル上で、 DynamoDB をエミュレートするツールです。
このツールを利用することで、AWS 上でリソースを作らず or 既存のリソースへ影響を与えず、DynamoDB の操作をテストできます。
アップデート内容
今回、 CloudShell の環境に DynamoDB Local がプリインストールされたというものです。
また、dynamodb-local
がエイリアスで紐づけられており、非常に簡単に起動できるようになりました。
DynamoDB local works with your existing DynamoDB API calls without impacting your production environment. You can now start DynamoDB local just by using dynamodb-local alias in CloudShell to develop and test your DynamoDB tables anywhere in the console without downloading or installing the AWS CLI nor DynamoDB local. To interact with DynamoDB local running in CloudShell with CLI commands, use the --endpoint-url parameter and point it to localhost:8000.
ちなみに、alias で紐づけられていたのは、 Java から起動するタイプのコマンドでした。
~ $ alias | grep dynamodb-local
alias dynamodb-local='java -jar /opt/dynamodb-local/DynamoDBLocal.jar'
やってみる
それでは CloudShell から DynamoDB ローカルを起動してみましょう。リージョンは東京リージョンを利用します。
既存の環境がある場合は、環境を削除して再作成を行います。
環境が立ち上がると、dynamodb-local
コマンドを実行します。
~ $ dynamodb-local
Initializing DynamoDB Local with the following configuration:
Port: 8000
InMemory: false
Version: 2.6.1
DbPath: null
SharedDb: false
shouldDelayTransientStatuses: false
CorsParams: null
フォアグランドで立ち上がっぱなしだったため、別タブで、もう1つの環境を立ち上げます。
--endpoint-url
に http://localhost:8000
を指定して、AWS CLI を実行したところ、うまく動いてそうでした。
テービル一覧表示
~ $ aws dynamodb list-tables --endpoint-url http://localhost:8000
{
"TableNames": []
}
テーブルの作成
~ $ aws dynamodb create-table --table-name Persons \
> --attribute-definitions AttributeName=Id,AttributeType=N \
> --key-schema AttributeName=Id,KeyType=HASH \
> --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 \
> --endpoint-url http://localhost:8000
{
"TableDescription": {
"AttributeDefinitions": [
{
"AttributeName": "Id",
"AttributeType": "N"
}
],
"TableName": "Persons",
"KeySchema": [
{
"AttributeName": "Id",
"KeyType": "HASH"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2025-05-19T22:53:06.691000+00:00",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T00:00:00+00:00",
"LastDecreaseDateTime": "1970-01-01T00:00:00+00:00",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 1,
"WriteCapacityUnits": 1
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Persons",
"DeletionProtectionEnabled": false
}
}
再度、テーブルの一覧表示
~ $ aws dynamodb list-tables --endpoint-url http://localhost:8000
{
"TableNames": [
"Persons"
]
}
一連のテーブル操作
~ $ aws dynamodb put-item --table-name Persons \
> --item '{"Id":{"N":"1"},"Name":{"S":"Jack"}}' \
> --endpoint-url http://localhost:8000
~ $ aws dynamodb get-item --table-name Persons \
> --key '{"Id":{"N":"1"}}' \
> --endpoint-url http://localhost:8000
{
"Item": {
"Id": {
"N": "1"
},
"Name": {
"S": "Jack"
}
}
}
~ $ aws dynamodb delete-item --table-name Persons \
> --key '{"Id":{"N":"1"}}' \
> --endpoint-url http://localhost:8000
~ $ aws dynamodb get-item --table-name Persons \
> --key '{"Id":{"N":"1"}}' \
> --endpoint-url http://localhost:8000
~ $
注意点
CloudShell の仕様上、数分アイドル状態が続いた場合、セッションが切れてしまう(データが消えてしまう)可能性があります。そのため、必要に応じて -sharedDb
オプションで、データ永続化してあげるのがオススメです。
~ $ dynamodb-local -sharedDb
Initializing DynamoDB Local with the following configuration:
Port: 8000
InMemory: false
Version: 2.6.1
DbPath: null
SharedDb: true
shouldDelayTransientStatuses: false
CorsParams: null
まとめ
以上、「CloudShell 環境に DynamoDB Local がプリインストールされて利用可能になりました」でした。
ササっと使いたいケースで役に立ちそうです。クラウド事業本部コンサルティング部のたかくに(@takakuni_)でした!