0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CDKでDynamoDBのテーブル定義を実装する

0
Last updated at Posted at 2026-07-15

CDKを使ってDynamoDBのテーブル定義を行いたいと思います。
CDKのセットアップは下記に記載しています。

スタックを作成

プロジェクト直下のlib/backend-stack.tsを下記の内容で作成します。
例として、TODOを保存するテーブルを作成します。

import * as cdk from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';

export class BackendStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const todosTable = new dynamodb.Table(this, 'TodosTable', {
      partitionKey: { name: 'userId', type: dynamodb.AttributeType.STRING },
      sortKey: { name: 'todoId', type: dynamodb.AttributeType.STRING },
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
    });
  }
}

下記コマンドで、CloudFormationのJsonファイルを作成します。

cdk synth

デプロイ

プロジェクト直下で下記コマンドを実行します。

cdk deploy BackendStack

デプロイが完了したら、AWSコンソールでDynamoDBを確認します。
テーブルが存在していたら完了です。

終わり

以上が、CDKでDynamoDBをデプロイする方法でした。
別の記事でLambdaからDynamoDBに書き込む方法を記事にしたいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?