Open template.yaml file in fcj-book-shop folder
Add the following script at the end of the file to create a simple table in DynamoDB:
SimpleTable:
Type: AWS:Serverless::SimpleTable
Properties:
TableName: SimpleTable
PrimaryKey:
Name: id
Type: String
Run the following command to deploy SAM
sam build
sam deploy
Open DynamoDB console
Select Tables on the left menu. You can see SimpleTable table created
But our table needs more config. So delete the above script and replace it with the following:
BooksTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: Books
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: rv_id
AttributeType: N
- AttributeName: name
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: rv_id
KeyType: RANGE
LocalSecondaryIndexes:
- IndexName: name-index
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: name
KeyType: RANGE
Projection:
ProjectionType: ALL
Run the following command to deploy SAM
sam build
sam deploy
Back to DynamoDB console. The Books table have been created and SimpleTable table deleted
Select Books table. Check informations of this table
To add data to the table, you can download the below file. Then, open file and replace all AWS-REGION with the region that create S3 bucket - book-image-resize-shop, such as: us-east-1