Posts

Showing posts with the label api

Guide to Querying and Pagination with AWS DynamoDB in NestJS

Image
Introduction In my previous article, I provided a basic guide on initializing and using AWS DynamoDB, but in this article, we will delve deeper into QueryCommand. In AWS DynamoDB, the Query method allows you to search for data based on the primary key (Partition Key) and filter conditions (Sort Key). To optimize performance and cost, DynamoDB supports a Pagination mechanism through the ExclusiveStartKey and LastEvaluatedKey parameters. Applying pagination not only reduces the data transfer load but also enables the application to handle large data tables smoothly, ensuring system stability. Detail Use AWS CDK to create the file lib/dynamodb-gsi-stack.ts import * as cdk from "aws-cdk-lib" import * as dynamodb from "aws-cdk-lib/aws-dynamodb" import { Construct } from "constructs" export class DynamoDbGsiStack extends cdk . Stack { constructor ( scope : Construct , id : string , props ?: cdk . StackProps ) { super (scope, id, props) ...

Guide to Initializing and Connecting AWS DynamoDB

Image
Introduction Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability at any scale. Key benefits include: unlimited scalability, extremely low latency in milliseconds, built-in security, and flexible pricing models based on usage (On-demand) to optimize costs. Detail Use AWS CDK to create the lib/dynamodb-stack.ts file import * as cdk from "aws-cdk-lib" import * as dynamodb from "aws-cdk-lib/awsf-dynamodb" import { Construct } from "constructs" export class DynamodbStack extends cdk . Stack { constructor ( scope : Construct , id : string , props ?: cdk . StackProps ) { super (scope, id, props) const productTable = new dynamodb. Table ( this , "ProductTable" , { tableName: "Products" , partitionKey: { name: "id" , type: dynamodb.AttributeType. STRING , }, billingMode: dynamodb.Bi...

Revoking JWT with Redis in NestJS

Image
Introduction In the previous article, I provided instructions on using NestJS with JWT, and you may also realize that if you use JWT, once a token is issued, it cannot be revoked. This means that if you have a token that hasn't expired yet, you can continue to use the service. For small systems that do not prioritize security, this might not be a major issue and can be simply resolved by deleting the token from the frontend when the user logs out. However, if you need to build a system with extremely high security, where the token must be invalidated upon logout so that no one can use it to access the service, this article will guide you through how to achieve that. To do this, we will use Redis (which I have already guided you on in this article) to store tokens that have not expired but are requested to be deleted. The storage duration for these tokens will be exactly the time remaining until they expire. Thus, after applying Redis, the operation of tokens will be as follows: If ...