Using the DynamoDB with Serverless Framework

--

Requirement :

Create a table if non existent and enable TTL for a table via Cloud-formation.

Explanation :

Reference [1] will provide insight to install the requirements and build a sample project. Add the following code to the template.yaml file

AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
Parameters:
AppName:
Type: String
Default: ii-app
Stage:
Type: String
Default: dev
Resources:##### DynamoDB specification for Internal integration metadata #####InternalIntegrationMetadata:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: "internal_integration_metadata"
TableClass: STANDARD
BillingMode: PROVISIONED
AttributeDefinitions:
- AttributeName: RequestId
AttributeType: S
- AttributeName: Key
AttributeType: S
- AttributeName: Value
AttributeType: S
- AttributeName: ExpirationDate
AttributeType: N
KeySchema:
- AttributeName: RequestId
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
TimeToLiveSpecification:
AttributeName: ExpirationDate
Enabled: True

References :

  1. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started.html
  2. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-timetolivespecification.html
  3. https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/setup-credentials.html
  4. https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

--

--