Posts

Showing posts with the label typescript

A Comprehensive Guide to the NestJS Request-Response Lifecycle

Image
Introduction The Request-Response Lifecycle in NestJS is a clearly defined sequence of steps that a request must pass through before a response is sent back to the client. Simply put, it is like a production line: each department has its own task to check, transform, or process the data. Key Components The typical execution order is as follows: Incoming Request: The request sent from the client. Middleware: Performs tasks such as logging, basic authentication, or modifying the request object. Guards: Responsible for security, deciding whether this request is allowed to proceed (Authentication/Authorization). Interceptors (Pre-controller): Allows you to intervene in the logic before it reaches the Controller. Pipes: Used for data transformation (Transformation) and validating the input data (Validation). Controller: Where the main business logic resides and processes the request. Interceptors (Post-controller): Processes the data after the Controller returns it (e.g., changing the JSON ...

Introduction to AWS Lightsail and Advantages of Simplified Cloud Platforms

Image
Introduction Amazon Lightsail is a Cloud Platform (PaaS/IaaS) service designed to simplify the deployment of web applications and virtual servers for users. It is an ideal solution for developers, small businesses, or those new to AWS who do not want to deal with the complexity of EC2. Advantages Simple to use: Provides pre-configured blueprints for popular platforms such as WordPress, Node.js, or LAMP stack with just a few clicks. Predictable costs: Lightsail uses a flat-rate monthly pricing model, including storage (SSD), bandwidth, and RAM, helping you easily manage your budget. Intuitive interface: The Console is streamlined, focusing on core features like Instance, Database, and Networking management. Easy to scale: When the application outgrows Lightsail's scale, you can easily export a snapshot to Amazon EC2 to take full advantage of the AWS ecosystem. Built-in services: Comes with essential features like DNS management, Static IP, basic Firewall, and Load Balancer. Prerequi...

Using AWS ECS Fargate Horizontal Auto Scaling

Image
Introduction In previous articles, I have provided instructions on using AWS ECS Fargate to deploy a NestJS Docker image utilizing S3 Service; you can review them to understand the basic concepts before proceeding. In this article, I will guide you through configuring auto scaling to automatically increase or decrease the number of instances based on demand. Prerequisites In the NestJS project, to easily test the auto-scaling feature, it is necessary to create an API with a relatively long processing time to drive CPU usage up during execution. I will create a simple API as follows for testing; you can add it to your project or replace it with any equivalent API of your choice. Afterward, build the Docker image and push it to AWS ECR. import {   Controller ,   Get ,   ParseIntPipe ,   Query , } from '@nestjs/common' @ Controller ( 'test' ) export class TestController {   @ Get ( 'sum' )   async sum (@ Query ( 'value' , ParseIntPipe ) value : number...