Serverless Stack Update: Using AWS CDK

We’ve now updated Serverless Stack to use AWS CDK instead of CloudFormation YAML. This is a big change! And it makes configuring your Serverless infrastructure a lot easier.

So defining our Notes table in DynamoDB looks like this:

- Resources:
-   NotesTable:
-     Type: AWS::DynamoDB::Table
-     Properties:
-       TableName: ${self:custom.tableName}
-       AttributeDefinitions:
-         - AttributeName: userId
-           AttributeType: S
-         - AttributeName: noteId
-           AttributeType: S
-       KeySchema:
-         - AttributeName: userId
-           KeyType: HASH
-         - AttributeName: noteId
-           KeyType: RANGE
-       # Set the capacity to auto-scale
-       BillingMode: PAY_PER_REQUEST

+ const table = new dynamodb.Table(this, "notes", {
+   partitionKey: { name: 'userId', type: dynamodb.AttributeType.STRING },
+   sortKey: { name: 'noteId', type: dynamodb.AttributeType.STRING },
+   billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
+ });

All the chapters in the Deploying The Backend to Production section have now been updated.

We also added a chapter to help you get started with AWS CDK. So have a look and let us know what you think!