Mở tệp template.yaml trong thư mục fcj-book-shop.
Sao chép các đoạn mã sau vào tệp đó.
booksTableName:
Type: String
Default: Books
BooksTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref booksTableName
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
Chạy lệnh sau để triển khai SAM.
sam build
sam validate
sam deploy
Quay lại bảng điều khiển DynamoDB. Tại trang Tables.
Để thêm dữ liệu vào bảng, bạn có thể tải xuống tệp dưới đây. Sau đó, mở tệp và thay thế tất cả AWS-REGION bằng vùng mà bạn đã tạo S3 bucket - book-image-resize-shop-by-myself, chẳng hạn như: us-east-1
.