<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad Fuzail</title>
    <description>The latest articles on DEV Community by Mohammad Fuzail (@fuzail96).</description>
    <link>https://dev.to/fuzail96</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1002330%2F8718f7d7-bcec-417c-bdcb-1edd49f4471f.jpg</url>
      <title>DEV Community: Mohammad Fuzail</title>
      <link>https://dev.to/fuzail96</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fuzail96"/>
    <language>en</language>
    <item>
      <title>Modern Cloud Infrastructure as Code with Sceptre: Building and Deploying a Simple Python Web Service</title>
      <dc:creator>Mohammad Fuzail</dc:creator>
      <pubDate>Wed, 16 Jul 2025 09:25:10 +0000</pubDate>
      <link>https://dev.to/epam_india_python/modern-cloud-infrastructure-as-code-with-sceptre-building-and-deploying-a-simple-python-web-service-3601</link>
      <guid>https://dev.to/epam_india_python/modern-cloud-infrastructure-as-code-with-sceptre-building-and-deploying-a-simple-python-web-service-3601</guid>
      <description>&lt;p&gt;As cloud-native architectures become the norm, managing infrastructure as code (IaC) is no longer a luxury, it's a necessity. While tools like the Serverless Framework are popular for abstracting infrastructure, Sceptre stands out for its tight integration with AWS CloudFormation and its flexibility in complex, real-world use cases.&lt;/p&gt;

&lt;p&gt;In this post, we’ll:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Sceptre to provision infrastructure&lt;/li&gt;
&lt;li&gt;Build a simple Python service&lt;/li&gt;
&lt;li&gt;Containerize it with Docker&lt;/li&gt;
&lt;li&gt;Set up Jenkins for CI/CD&lt;/li&gt;
&lt;li&gt;Briefly explore why Sceptre may be preferable to the Serverless Framework&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Sceptre over Serverless Framework?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4g06bx3584wj0fw1xpdv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4g06bx3584wj0fw1xpdv.png" alt="secptre vs serverless comparision" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sceptre is especially suited for teams who:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Need infrastructure flexibility (beyond Lambda/APIs)&lt;/li&gt;
&lt;li&gt;Want full access to AWS resource definitions&lt;/li&gt;
&lt;li&gt;Deploy to multiple environments (dev, test, prod) in a structured way&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Write a Simple Python Script&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s the application logic — a basic Python script to be run in the cloud:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#script.py
import time

print("Python task started...")
time.sleep(3)
print("Task completed successfully!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automation tasks&lt;/li&gt;
&lt;li&gt;Data processing&lt;/li&gt;
&lt;li&gt;Scheduled jobs&lt;/li&gt;
&lt;li&gt;Infrastructure hooks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Dockerize It&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To run this in ECS, we need to containerize the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Dockerfile
FROM python:3.10-slim

WORKDIR /app
COPY script.py .

CMD ["python", "script.py"]
Build and test:
docker build -t python-task .
docker run python-task
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Use Sceptre to Deploy to ECS Fargate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sceptre lets us manage AWS infrastructure using CloudFormation templates and environment-specific configurations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Directory Structure&lt;br&gt;
infra/&lt;br&gt;
├── config/&lt;br&gt;
│   └── dev/&lt;br&gt;
│       └── python-task.yaml&lt;br&gt;
└── templates/&lt;br&gt;
    └── ecs-task.yaml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#config/dev/python-task.yaml
template_path: templates/ecs-task.yaml
stack_name: python-task
parameters:
  TaskName: python-script-task
  ContainerImage: &amp;lt;YOUR_ECR_IMAGE_URL&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;templates/ecs-task.yaml (CloudFormation)
Resources:
  TaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      Family: !Ref TaskName
      Cpu: '256'
      Memory: '512'
      RequiresCompatibilities: [FARGATE]
      NetworkMode: awsvpc
      ExecutionRoleArn: arn:aws:iam::&amp;lt;ACCOUNT_ID&amp;gt;:role/ecsTaskExecutionRole
      ContainerDefinitions:
        - Name: python-container
          Image: !Ref ContainerImage
          Essential: true
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-group: /ecs/python-task
              awslogs-region: !Ref AWS::Region
              awslogs-stream-prefix: python-task
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Deploy with Sceptre :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd infra&lt;br&gt;
sceptre launch dev/python-task.yaml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once launched, you can run this task using AWS CLI or trigger it via EventBridge for scheduled executions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Automate Deployment with Jenkins&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's a minimal Jenkinsfile to automate the entire flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
  agent any
  environment {
    ECR_REPO = "&amp;lt;ACCOUNT_ID&amp;gt;.dkr.ecr.&amp;lt;REGION&amp;gt;.amazonaws.com/python-task"
  }
  stages {
    stage('Build') {
      steps {
        sh 'docker build -t python-task .'
      }
    }
    stage('Push to ECR') {
      steps {
        sh '''
          aws ecr get-login-password | docker login --username AWS --password-stdin $ECR_REPO
          docker tag python-task:latest $ECR_REPO:latest
          docker push $ECR_REPO:latest
        '''
      }
    }
    stage('Deploy Infra') {
      steps {
        dir('infra') {
          sh 'sceptre launch dev/python-task.yaml'
        }
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One push to Git, and Jenkins takes care of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building your container&lt;/li&gt;
&lt;li&gt;Publishing it to ECR&lt;/li&gt;
&lt;li&gt;Updating your ECS TaskDefinition via Sceptre&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You now have a repeatable, production-grade deployment pattern for running Python tasks in AWS with full control and no unnecessary abstraction.&lt;br&gt;
Sceptre is not a replacement for Serverless Framework, but an empowering alternative when you want low-level control and native AWS CloudFormation integration. For teams who treat infrastructure as a first-class citizen, Sceptre is a great fit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Useful References&lt;/strong&gt; : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://sceptre.cloudreach.com/" rel="noopener noreferrer"&gt;Sceptre Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/" rel="noopener noreferrer"&gt;Docker Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/userguide/task_definitions.html" rel="noopener noreferrer"&gt;AWS ECS Task Definition Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jenkins.io/doc/book/pipeline/" rel="noopener noreferrer"&gt;Jenkins Pipeline Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cli/latest/reference/ecs/run-task.html" rel="noopener noreferrer"&gt;AWS CLI: Run ECS Task&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: This is a personal blog. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>septre</category>
      <category>infrastructureascode</category>
      <category>python</category>
    </item>
    <item>
      <title>Navigating Concurrency for Large-Scale Systems</title>
      <dc:creator>Mohammad Fuzail</dc:creator>
      <pubDate>Tue, 19 Nov 2024 05:35:57 +0000</pubDate>
      <link>https://dev.to/epam_india_python/navigating-concurrency-for-large-scale-systems-581f</link>
      <guid>https://dev.to/epam_india_python/navigating-concurrency-for-large-scale-systems-581f</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;As a developer, one of the most exciting challenges I face is developing large-scale systems that can handle massive workloads efficiently. In this blog post, I'll share insights on leveraging Python's concurrent programming features to build robust, high-performance systems while optimizing resource usage. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Concurrency Options in Python&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Python offers three main approaches to concurrency: asyncio, multithreading, and multiprocessing. Each has its strengths and use cases, and choosing the right one is crucial for system performance. &lt;/p&gt;

&lt;p&gt;Asyncio: Event-driven, single-threaded concurrency &lt;/p&gt;

&lt;p&gt;Multithreading: Concurrent execution within a single process &lt;/p&gt;

&lt;p&gt;Multiprocessing: Parallel execution across multiple CPU cores &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choosing the Right Concurrency Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The decision between asyncio, multithreading, and multiprocessing depends on the nature of your workload: &lt;/p&gt;

&lt;p&gt;Asyncio: Ideal for I/O-bound tasks with many concurrent operations, such as handling numerous network connections or file operations. &lt;/p&gt;

&lt;p&gt;Multithreading: Suitable for I/O-bound tasks where you need to maintain shared state or work with libraries that aren't asyncio-compatible. &lt;/p&gt;

&lt;p&gt;Multiprocessing: Best for CPU-bound tasks that require true parallelism and can benefit from utilizing multiple cores. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Determining the Optimal Number of Workers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finding the right number of workers (threads or processes) is crucial for maximizing performance without overwhelming system resources. Here are some guidelines: &lt;/p&gt;

&lt;p&gt;For I/O-bound tasks (asyncio or multithreading): &lt;/p&gt;

&lt;p&gt;Start with number of workers equal to 2-4 times the number of CPU cores. &lt;/p&gt;

&lt;p&gt;Gradually increase and monitor performance improvements. &lt;/p&gt;

&lt;p&gt;Stop increasing when you see diminishing returns or increased resource contention. &lt;/p&gt;

&lt;p&gt;For CPU-bound tasks (multiprocessing) &lt;/p&gt;

&lt;p&gt;Begin with a number of workers equal to the number of CPU cores. &lt;/p&gt;

&lt;p&gt;Experiment with slightly higher numbers (e.g., number of cores + 1 or 2) to account for any I/O operations. &lt;/p&gt;

&lt;p&gt;Monitor CPU usage and adjust accordingly. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Practical Example: Log Processing System&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's consider a large-scale log processing system that needs to handle millions of log entries per day. This system will read logs from files, process them, and store the results in a database. &lt;/p&gt;

&lt;p&gt;Here's how we might approach this using Python's concurrency features: &lt;/p&gt;

&lt;p&gt;Log Reading (I/O-bound): Use asyncio for efficient file I/O operations. This allows us to read multiple log files concurrently without blocking. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjuxu44o3fo49v7yhdgns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjuxu44o3fo49v7yhdgns.png" alt="logging code example 1" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Log Processing (CPU-bound): Use multiprocessing to parallelize the actual processing of log entries across multiple CPU cores.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwrve55iccy1vlg4wvi9o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwrve55iccy1vlg4wvi9o.png" alt="logging code example 2" width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Database Storage (I/O-bound): Use multithreading for database operations, as most database libraries are not asyncio-compatible but can benefit from concurrent access. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvp693e5vhwmtwakqok2b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvp693e5vhwmtwakqok2b.png" alt="DB storage example" width="800" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Putting it all together&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This example demonstrates how we can leverage different concurrency models in Python to build a large-scale system that efficiently handles I/O-bound and CPU-bound tasks. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Building large-scale systems with Python requires a deep understanding of its concurrency features and how to apply them effectively. By carefully choosing between asyncio, multithreading, and multiprocessing, and optimizing the number of workers, we can create systems that make the best use of available resources and scale to handle massive workloads. &lt;/p&gt;

&lt;p&gt;Remember, there's no one-size-fits-all solution. Always profile your application, experiment with different approaches, and be prepared to adjust your design based on real-world performance data. Happy scaling! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;This is a personal [blog, post, statement, opinion]. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally. &lt;/p&gt;

</description>
      <category>concurrency</category>
      <category>asyncronousprogramming</category>
      <category>threading</category>
      <category>parallelprogramming</category>
    </item>
    <item>
      <title>Leveraging Serverless To Build Scalable Soluions</title>
      <dc:creator>Mohammad Fuzail</dc:creator>
      <pubDate>Fri, 06 Jan 2023 09:44:52 +0000</pubDate>
      <link>https://dev.to/epam_india_python/leveraging-serverless-to-build-scalable-soluions-2i93</link>
      <guid>https://dev.to/epam_india_python/leveraging-serverless-to-build-scalable-soluions-2i93</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Serverless is a cloud computing application development and execution model that enables developers to build and run application code without provisioning or managing servers or backend infrastructure. &lt;/p&gt;

&lt;p&gt;A serverless provider allows users to write and deploy code without worrying about the underlying infrastructure. A company that gets backend services from a serverless provider is charged based on their computation and do not have to reserve and pay for a fixed amount of bandwidth or number of servers, as the service is auto-scaling. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Despite the name serverless, physical servers are still used but developers do not need to be aware of that.&lt;/p&gt;

&lt;p&gt;So, to leverage serverless computing, we will be exploring and implementing serverless framework in this blog.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is serverless framework?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Serverless framework is an open-source web framework written using Node.js which enables us to build, package and deploy scalable applications without worrying about provisioning and managing infrastructure. It supports different Public Cloud vendors and satisfies the definition of an Infrastructure As A Code.&lt;/p&gt;

&lt;p&gt;It's a CLI that offers structure, automation and best practices out-of-the-box, allowing you to focus on building sophisticated, event-driven, serverless architectures, comprised of &lt;a href="https://www.serverless.com/framework/docs/providers/aws/guide/intro#functions"&gt;Functions&lt;/a&gt; and &lt;a href="https://www.serverless.com/framework/docs/providers/aws/guide/intro#events"&gt;Events&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functions :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The code of a serverless application is deployed and executed in AWS Lambda functions.&lt;br&gt;
Each function is an independent unit of execution and deployment, like a microservice. A function is merely code, deployed in the cloud, that is most often written to perform a single job such as:&lt;/p&gt;

&lt;p&gt;• Saving a user to the database&lt;br&gt;
• Processing a file in a database&lt;br&gt;
• Performing a scheduled task&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Events :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Functions are triggered by events. Events come from other AWS resources, for example:&lt;br&gt;
• An HTTP request on an API Gateway URL (e.g. for a REST API)&lt;br&gt;
• A new file uploaded in an S3 bucket (e.g. for an image upload)&lt;br&gt;
• A CloudWatch schedule (e.g. run every 5 minutes)&lt;br&gt;
• A message in an SNS topic&lt;br&gt;
• A CloudWatch alert&lt;br&gt;
• And more...&lt;/p&gt;

&lt;p&gt;When you configure an event on a Lambda function, Serverless Framework will automatically create the infrastructure needed for that event (e.g. an API Gateway endpoint) and configure your functions to listen to it.&lt;/p&gt;

&lt;p&gt;The entry point of a Serverless Framework application is the &lt;strong&gt;serverless.yml&lt;/strong&gt; file in a source root that describes the serverless application in its own syntax. Just like an AWS SAM template, it allows configuring the whole serverless application. It also has its own blueprints that can be used to bootstrap your own application.&lt;br&gt;
&lt;a href="https://tinyurl.com/384vyzh2"&gt;Check more details here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why serverless framework?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Serverless Framework is different from other application frameworks because:&lt;/p&gt;

&lt;p&gt;• It manages your code as well as your infrastructure&lt;br&gt;
• It supports multiple languages (Node.js, Python, Java, and more)&lt;br&gt;
• It supports different cloud providers which supports function as a service.&lt;/p&gt;

&lt;p&gt;We should focus on developing the business logic and let the infrastructure related stuff abstracted and handled by a managed service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to leverage serverless framework?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s use serverless framework to develop and deploy a simple serverless API using AWS Lambda with Python.&lt;br&gt;
Since serverless framework is a node.js CLI tool, at first we need to install Node.js&lt;br&gt;
Now, just to verify Node.js installation use version check command.&lt;br&gt;
Note: Serverless runs on Node v6 or higher&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jajl8adg4qv7025190e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jajl8adg4qv7025190e.png" alt="Image description" width="800" height="38"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, the next step would be to install serverless framework using following command :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g serverless&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs6pcapouadbeq7vrhqee.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs6pcapouadbeq7vrhqee.png" alt="Image description" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can verify the serverless framework installation by using version check command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;serverless -v&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to have an AWS account and an AWS profile is setup for the same. If not, &lt;a href="https://tinyurl.com/yv2kw6d3"&gt;you can use this guide.&lt;/a&gt; to set it up.&lt;/p&gt;

&lt;p&gt;Basically, you need to create an IAM user and access role to secure the service deployment on AWS. Here is how we can config AWS credentials :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;serverless config credentials --provider aws --key &amp;lt;AccessKey&amp;gt; --secret &amp;lt;secretKey&amp;gt; --profile &amp;lt;profile name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgzsks5anqjem32fllyww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgzsks5anqjem32fllyww.png" alt="Image description" width="800" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s create a python service using the template available in serverless framework. Use following command with service name as “backend” here :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;serverless create --template aws-python --path backend&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8kwc3gkwu5mcyazojiq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8kwc3gkwu5mcyazojiq.png" alt="Image description" width="800" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To see a list of available templates run serverless create --help&lt;br&gt;
Most commonly used templates are:&lt;/p&gt;

&lt;p&gt;• aws-clojurescript-gradle&lt;br&gt;
• aws-clojure-gradle&lt;br&gt;
• aws-nodejs&lt;br&gt;
• aws-nodejs-typescript&lt;br&gt;
• aws-alexa-typescript&lt;br&gt;
• aws-nodejs-ecma-script&lt;br&gt;
• aws-python&lt;br&gt;
• aws-python3&lt;br&gt;
• aws-ruby&lt;br&gt;
• aws-provided&lt;/p&gt;

&lt;p&gt;Note: To check the available templates, &lt;a href="https://tinyurl.com/yhhe895p"&gt;follow this link.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will create two files in backend project directory , one serverless.yml and another one as handler.py, we can see below :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faktp4r7a4hadrmg60upz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faktp4r7a4hadrmg60upz.png" alt="Image description" width="682" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The serverless.yml file includes all the configurations related to cloud resources, language and functions. While handler.py have codes or logic related to lambda function.&lt;/p&gt;

&lt;p&gt;Since we have the boilerplate for both the files created, let’s modify these files to create a simple API which gives us the product of two number.&lt;/p&gt;

&lt;p&gt;We will start with the serverless.yml file :&lt;/p&gt;

&lt;p&gt;• First, define the name of the service you want to create: mybackendservice (This should be a unique service name for a particular serverless account).&lt;br&gt;
• If you want to monitor the serverless project in the serverless dashboard(dashboard.serverless.com), you can mention the app and org.&lt;br&gt;
• Now, we have to mention the configuration of the cloud provider, resources and permissions. In our case, we are using AWS as our cloud service provider.&lt;br&gt;
• At last, we include the lambda function configurations. In our case, we will define a POST API.&lt;/p&gt;

&lt;p&gt;Note :  For more details on provider configurations, &lt;a href="https://tinyurl.com/bp4r4nk2"&gt;please visit here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we can see the configurations added for POST API in serverless.yml file.&lt;/p&gt;

&lt;p&gt;Note: Add app/org name same as in your serverless dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxgyfqhwihny6boswq1q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftxgyfqhwihny6boswq1q.png" alt="Image description" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s add the service logic in handler.py file.&lt;/p&gt;

&lt;p&gt;We need to write a python function which returns product of two numbers in the json response.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhr3grz0yqgibe509jlsw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhr3grz0yqgibe509jlsw.png" alt="Image description" width="800" height="712"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since, we are done with the changes. Let’s deploy our service using below command :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;serverless deploy&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;once we execute this command it will be provisioning all the necessary resources in AWS and deploy our code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2gqrsv6s4dptq2fo8q5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2gqrsv6s4dptq2fo8q5.png" alt="Image description" width="800" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we can see after deployment, we got dashboard link to our app and the endpoint URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Invoking A Lambda Function :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Events are the things that trigger your functions to run.&lt;/p&gt;

&lt;p&gt;If you are using AWS as your provider, all events in the service are anything in AWS that can trigger an AWS Lambda function, like an S3 bucket upload, an SNS topic, and HTTP endpoints created via API Gateway.&lt;/p&gt;

&lt;p&gt;Other way to invoke a lambda function is using CLI:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;serverless invoke [local] --function functionName&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It invokes a deployed function. You can send event data, read logs and display other important information of the function invocation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tinyurl.com/2s3wu8j9"&gt;check this link for more details about invocation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logs :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One way to get the logs of a lambda function invocation is the AWS cloudwatch which we can access for a particular log set through monitoring tab in AWS Console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw41u8r3jy33lyk8d39ba.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw41u8r3jy33lyk8d39ba.png" alt="Image description" width="614" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way is using CLI :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;serverless logs -f hello&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This lets you watch the logs of a specific function. This command returns as many log events as can fit in 1MB (up to 10,000 log events).&lt;/p&gt;

&lt;p&gt;This will fetch the logs from last 10 minutes as startTime was not given.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tinyurl.com/2w3p6rfx"&gt;For more details on logs, check this link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s try out our API service using Postman.&lt;/p&gt;

&lt;p&gt;Here, we are using an HTTP request as an event to invoke serverless lambda function which we have developed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpel6rdplzpeyrte3dyc0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpel6rdplzpeyrte3dyc0.png" alt="Image description" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see here, that the service is working as expected. So, now it’s your turn. Write your own service using serverless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Removing A Serverless App :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The sls remove command will remove the deployed service, defined in your current working directory, from the provider.&lt;/p&gt;

&lt;p&gt;Use this command from your CLI :&lt;/p&gt;

&lt;p&gt;&lt;code&gt;serverless remove --stage dev --region us-east-1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This example will remove the deployed service of your current working directory with the stage “dev” and the region “us-east-1”.&lt;/p&gt;

&lt;p&gt;The alternate way is to delete the CloudFormation Stack corresponding to your service using AWS Console.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was a very basic example, but we can create a full stack and very sophisticated application as well with ease using serverless. So, with serverless we as developer can focus mostly at the logic part without caring about configuring and managing infrastructures. Serverless computing is evolving day by day and it’s adoption is also growing. This basic understanding will help you to develop and deploy your own service using serverless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;• &lt;a href="https://tinyurl.com/4sxwwwfs"&gt;https://tinyurl.com/4sxwwwfs&lt;/a&gt;&lt;br&gt;
• &lt;a href="https://tinyurl.com/mtdruy88"&gt;https://tinyurl.com/mtdruy88&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a personal [blog, post, statement, opinion]. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally.&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>lambda</category>
      <category>python</category>
      <category>api</category>
    </item>
  </channel>
</rss>
