☠️
smadi0x86 Playground
  • 💀Welcome to smadi0x86 Playground
    • 🍷Resources
    • 🚬Projects
    • 🎓Certifications
    • 📌Pinned
    • ❓Questions
    • 📞Contact
  • 🏞️Cloud Native
    • Docker
      • Quick Reference
      • Introduction
      • Containers
      • Images
      • Storage & Volumes
      • Security
      • Cheatsheet
    • Git
    • Serverless Framework
    • YAML
  • 🔨Software Engineering
    • System Design
    • Environment Variables
    • JSON Web Tokens
  • 👾Architecture
    • C Language
      • Introduction
      • Calling Conventions
      • GCC Compilation
      • Libraries & Linking
      • I/O
      • Files
      • Pointers
      • Dynamic Memory Allocation
      • Data Types
      • Strings Manipulation
      • Bit Manipulation
      • Pre-processors
      • Macros
      • Type Qualifiers
    • C/C++ Build Systems
      • Fundamentals for Linking
      • Symbolic Linking
      • Cross-Platform Compilation
      • CMake for Building and Linking
      • Shared Libraries
      • Dynamic Linking and Dependency Management
    • Operating Systems
      • OS & Architecture
      • Processes
      • CPU Scheduling
      • Memory Management
  • 🛩️Cyber Warfare
    • Flight Physics
    • Communication
      • PWM & PPM
      • MAVLink
  • 🏴‍☠️Offensive Security
    • Active Directory
      • Introduction
    • Web Attacks
      • Server Side
        • OS Command Injection
        • Information Disclosure
        • Directory Traversal
        • Business Logic
        • Authentication
        • File Upload
        • SSRF
      • Client Side
        • CSRF
        • XSS
    • Recon
      • Active
        • Host discovery
        • Nmap
        • Mass Scan
      • Passive
        • Metadata
      • Web Applications
        • Discovery
        • Subdomains & Directories
        • SSL Certs
        • CMS
        • WAF Detection
      • Firewall Evasion
  • Binary Exploitation
    • Stack Smashing
      • x86
      • x86_64
    • pwntools
      • Processes and Communication
      • Logging and Context
      • Cyclic
      • Packing
      • ELF
      • ROP
  • 😈Advanced Persistent Threat
    • C2
      • Sliver
    • Malware
      • Windows Internals
        • PEB
      • Academy
        • Basics
      • Sektor7
        • Essentials
  • 💌Certifications
    • AWS Certified Cloud Practitioner (CLF-C01)
      • Cloud Foundations
      • Domain 1: Cloud Concepts
      • Domain 2: Security and Compliance
      • Domain 3: Technology
      • Domain 4: Billing and Pricing
    • AWS Certified Solutions Architect - Associate (SAA-C03)
      • Foundation
    • Certified Kubernetes Administrator (CKA)
      • Core Concepts
      • Scheduling
      • Logging & Monitoring
      • Application Lifecycle Management
      • Cluster Maintenance
      • Security
      • Storage
      • Networking
      • Design Kubernetes Cluster
      • Kubernetes The Kubeadm Way
      • Troubleshooting
      • JSONPATH
      • Lightning Lab
      • Mock Exams
      • Killer Shell
    • Certified Kubernetes Security (CKS)
      • Foundation
      • Cluster Setup
      • Cluster Hardening
      • Supply Chain Security
      • Runtime Security
      • System Hardening
      • Killer Shell
    • (KGAC-101) Kong Gateway Foundations
      • Introduction to APIs and API Management
      • Introduction to Kong Gateway
      • Getting Started with Kong Enterprise
      • Getting Started with Kong Konnect
      • Introduction to Kong Plugins
  • 📜Blog Posts
    • Modern Solutions For Preventing Ransomware Attacks
Powered by GitBook
On this page
  • Introduction
  • Setting Up Serverless Framework
  • Deploying FastAPI on AWS Lambda
  • FastAPI Setup
  • Deploying on Azure and Other Platforms
  • Azure
  • Features, Tips, and Tricks
  • Extended Management Commands
  1. Cloud Native

Serverless Framework

Using the Serverless Framework, you can easily deploy applications to various cloud providers, such as AWS and Azure.

Introduction

Serverless Framework allows developers to deploy auto-scaling, pay-per-execution, event-driven functions.

The advantages include:

  • No server management

  • Cost-effectiveness

  • Scalability

  • Developer productivity

FastAPI is a modern web framework for building APIs with Python, known for its fast performance and built-in support for data validation and interactive documentation.

Setting Up Serverless Framework

Installation:

npm install -g serverless

Authentication:

For AWS, set up the AWS CLI and configure your credentials:

aws configure

For Azure, set up the Azure CLI and log in:

az login

Deploying FastAPI on AWS Lambda

Create a New Project:

serverless create --template aws-python3 --path my-fastapi-app
cd my-fastapi-app

FastAPI Setup

Install FastAPI and Uvicorn:

pip install fastapi uvicorn

Your application (app.py):

from fastapi import FastAPI

app = FastAPI()

@app.get("/")

def read_root():
    return {"Hello": "World"}

Serverless Configuration (serverless.yml):

service: my-fastapi-app

provider:
  name: aws
  runtime: python3.8

functions:
  api:
    handler: handler.app
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'

Deploy:

serverless deploy

Deploying on Azure and Other Platforms

While AWS is widely used, Serverless Framework also supports Azure, Google Cloud, and more.

Azure

Update your serverless.yml:

provider:
  name: azure
  location: West US
  runtime: python3.6

functions:
  hello:
    handler: handler.hello
    events:
      - http: true
        x-azure-settings:
          authLevel: anonymous

Features, Tips, and Tricks

  1. Local Development: Use serverless-offline plugin for simulating AWS Lambda & API Gateway locally.

  2. Environment Variables: Manage with the serverless-dotenv-plugin.

  3. Middleware: The serverless-middleware plugin allows you to add middlewares before your lambda function is executed.

  4. Optimizing Dependencies: Use serverless-python-requirements to automatically package only the required dependencies.

  5. Warm-Up: AWS Lambdas can sometimes have cold starts. Use serverless-plugin-warmup to mitigate this.

  6. Fine-tune your IAM roles for your functions in serverless.yml to adhere to the principle of least privilege.

  7. Automate Documentation: FastAPI provides automatic interactive API documentation using Swagger.

Extended Management Commands

Deploy to a Specific Stage:

By default, the deployment goes to the dev stage.

serverless deploy --stage production

Remove a Specific Stage:

serverless remove --stage <stage-name>

Specifying a Region:

serverless deploy --region us-west-1

Function Deployment:

Instead of deploying the entire stack, deploy a single function.

serverless deploy function --function <function-name>

View Function Configuration:

serverless info --function <function-name>

Invoke a Function Remotely:

serverless invoke --function <function-name> --log

Print Out the Serverless Configuration:

This prints out the configuration that will be sent to the provider.

serverless print

Serverless Dashboard:

After setting up an account on Serverless Dashboard, you can monitor, troubleshoot, and test your serverless application.

serverless dashboard

Serverless Plugin Management:

Install and manage plugins directly from the CLI.

serverless plugin install --name <plugin-name>
serverless plugin uninstall --name <plugin-name>

Config Credentials:

Set up the Serverless Framework with your account credentials, useful if you didn’t do it during the setup.

serverless config credentials --provider <provider-name> --key <key> --secret <s
PreviousGitNextYAML

Last updated 1 year ago

🏞️
Page cover image