Use AWS CDK to Deploy a DynamoDB Table

InstructorLee Robinson

Share this video with your friends

Send Tweet

We'll create a new CDK Stack, defining a DynamoDB table called "Items" that is configured to pay per request with a partition key of ID.

nicoandresr rodriguez
~ 4 years ago

Here a typo in min 1:45 is dynamo.Table instead of dynamo.table

~ 3 years ago

I keep getting this error when running "cdk deploy"

throw new Error('construct does not have an associated node. All constructs must extend the "Construct" base class');

anyone else having this issue?

~ 3 years ago

I am also having that issue

Lucas Minter
~ 2 years ago

Hey, here is an issue that should hopefully solve your problem. We will look into the validity of the course with the mismatched versions in mind. https://github.com/aws/aws-cdk/issues/20370

James
~ 2 years ago

Yeah this tutorial is broken. I'm unable to do a 'cdk deploy' as well. This tutorial needs to be updated to be compatible with aws-cdk v2.

James
~ 2 years ago

Solution I found was to do the following:

  1. cdk init <app-name> --language typescript This init builds with v2 of the aws-cdk, while the --language javascript in this tutorial defaults to v1.
  2. Modify nextjs-dynamodb-stack.js to be... import { Stack, StackProps } from 'aws-cdk-lib'; import { Construct } from 'constructs';

import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';

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

new dynamodb.Table(this, 'Items', {
  partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
  billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
});

} } 3. cdk bootstrap This is needed if it's your first time to try and do cdk deploy 4. cdk deploy