Serverless Stack Update: Using AWS CDK
Many of our readers have said defining resources in yaml is both cumbersome and error prone. We’ve now updated Serverless Stack to use AWS CDK 7 instead of CloudFormation YAML. This is a big change! And it makes configuring your Serverless infrastructure a lot easier.
So defining a DynamoDB table 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, + });
Better together: AWS SAM and AWS CDK
AWS Serverless Application Model CLI (AWS SAM CLI) support for local development and testing of AWS Cloud Development Kit (AWS CDK) projects.
Before today, you could use the AWS SAM CLI to build locally, test, and package serverless applications defined using AWS CloudFormation or AWS SAM templates. With this preview release, you can use AWS SAM CLI to build, test, and in the future, package applications defined using the AWS CDK.
AWS CDK vs Serverless Framework
Using AWS CDK with Serverless Framework
No comments:
Post a Comment