O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building Serverless Microservices in Python

Book Description

A practical guide for developing end-to-end serverless microservices in Python for developers, DevOps, and architects.

Key Features

  • Create a secure, cost-effective, and scalable serverless data API
  • Use identity management and authentication for a user-specific and secure web application
  • Go beyond traditional web hosting to explore the full range of cloud hosting options

Book Description

Over the last few years, there has been a massive shift from monolithic architecture to microservices, thanks to their small and independent deployments that allow increased flexibility and agile delivery. Traditionally, virtual machines and containers were the principal mediums for deploying microservices, but they involved a lot of operational effort, configuration, and maintenance. More recently, serverless computing has gained popularity due to its built-in autoscaling abilities, reduced operational costs, and increased productivity.

Building Serverless Microservices in Python begins by introducing you to serverless microservice structures. You will then learn how to create your first serverless data API and test your microservice. Moving on, you'll delve into data management and work with serverless patterns. Finally, the book introduces you to the importance of securing microservices.

By the end of the book, you will have gained the skills you need to combine microservices with serverless computing, making their deployment much easier thanks to the cloud provider managing the servers and capacity planning.

What you will learn

  • Discover what microservices offer above and beyond other architectures
  • Create a serverless application with AWS
  • Gain secure access to data and resources
  • Run tests on your configuration and code
  • Create a highly available serverless microservice data API
  • Build, deploy, and run your serverless configuration and code

Who this book is for

If you are a developer with basic knowledge of Python and want to learn how to build, test, deploy, and secure microservices, then this book is for you. No prior knowledge of building microservices is required.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Building Serverless Microservices in Python
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Serverless Microservices Architectures and Patterns
    1. Understanding different architecture types and patterns
      1. The monolithic multi-tier architecture and the monolithic service-oriented architecture
      2. Benefits of monolithic architectures
      3. Drawbacks of the monolithic architectures
      4. Overview of microservices
      5. Benefits and drawbacks of microservice architectures
      6. SOA versus microservices
    2. Virtual machines, containers, and serverless computing
      1. Virtual machines
      2. Containers
      3. Serverless computing
      4. Comparing virtual machines, containers, and serverless
    3. Overview of microservice integration patterns
      1. Design patterns
        1. Why are patterns useful?
      2. Software design patterns and principles
      3. Serverless microservices pattern categories
    4. Communication styles and decomposition microservice patterns
      1. Communication styles
        1. One-to-one communication microservice patterns
        2. Many-to-many communication microservice patterns
      2. Decomposition pattern by business capability
      3. Decomposition pattern by bounded context
    5. Serverless computing in AWS
      1. Overview of some of the key serverless services in AWS
      2. AWS Lambda
      3. Serverless computing to implement microservice patterns
      4. Example use case – serverless file transformer
    6. Setting up your serverless environment
      1. Setting up your AWS account
        1. Setting up MFA
        2. Setting up a new user with keys
        3. Managing your infrastructure with code
      2. Installing bash on Windows 10
      3. Updating Ubuntu, installing Git and Python 3
      4. Installing and setting up the AWS CLI
    7. Summary
  7. Creating Your First Serverless Data API
    1. Overview of security in AWS
      1. Why is security important?
      2. Security by design principles
      3. AWS Identity and Access Management
        1. JavaScript object notation
        2. IAM policies
        3. IAM users
        4. IAM groups
        5. IAM roles
    2. Securing your serverless microservices
      1. Lambda security
      2. API Gateway security
      3. DynamoDB security
      4. Monitoring and alerting
      5. Find out more
    3. Building a serverless microservice data API
      1. Serverless microservice data API requirements
        1. Query string
        2. Data API architecture
    4. Setting up Lambda security in the AWS Management Console
      1. Creating an IAM policy
        1. DynamoDB IAM policy
        2. Lambda IAM policy
      2. Creating the Lambda IAM role
    5. Creating and writing to a NoSQL database called DynamoDB using AWS
      1. Creating a DynamoDB in AWS
      2. Writing data to DynamoDB using AWS
      3. Querying DynamoDB using AWS
        1. DynamoDB Scan in AWS Management Console
        2. DynamoDB Query in AWS Management Console
      4. Deleting DynamoDB using AWS
    6. Creating and writing to a NoSQL database called DynamoDB using Python
      1. Creating a DynamoDB table using Python
      2. Writing to DynamoDB using Python
      3. Querying DynamoDB using Python
    7. Creating a Lambda to query DynamoDB
      1. Creating the Lambda function
      2. Testing the Lambda function
    8. Setting up the API Gateway and integrating it with a Lambda proxy
    9. Connecting API Gateway, Lambda, and DynamoDB
    10. Cleaning-up
    11. Summary
  8. Deploying Your Serverless Stack
    1. An overview of serverless stack build and deploy options
      1. Manually provisioning infrastructure
      2. Infrastructure as code
      3. Building and deploying using the Serverless Application Model (SAM)
      4. Building and deploying using alternate options
    2. Creating a profile, an S3 bucket, IAM policies, and IAM roles resources
      1. Creating an AWS credentials profile
      2. Creating an S3 bucket
      3. Setting up the configuration files for your AWS account
      4. Updating the polices and assuming roles files
      5. Creating the IAM roles and policies
      6. Checking the IAM roles and policies
    3. Building and deploying with API Gateway, Lambda, and DynamoDB
      1. Building the Lambda as a ZIP package
      2. SAM YAML template
      3. Packaging and deploying your serverless stack
      4. Putting it all together
      5. Manually testing the serverless microservice
      6. Making code and configuration changes
      7. Deleting the serverless stack
    4. Summary
  9. Testing Your Serverless Microservice
    1. Unit testing your Python Lambda code
      1. Why is testing important?
      2. Types of testing
      3. Unit testing Lambda Python code
        1. The sample test data
        2. The unit test
      4. Mocking
      5. Running the unit test
      6. Code coverage
    2. Running and debugging your AWS Lambda code locally
      1. Batch-loading data into DynamoDB
      2. Running the Lambda locally
    3. Integration testing using real test data
      1. Testing that a Lambda has been deployed correctly
      2. Testing that API Gateway has been deployed correctly
    4. The AWS Serverless Application Model CLI
    5. Loading and end-to-end testing at scale
      1. Load testing your serverless microservice
    6. Strategies to reduce the API's latency
    7. Cleaning up
    8. Summary
  10. Securing Your Microservice
    1. Overview of the security in AWS
      1. Why is security important?
      2. Types of security terms in AWS
    2. Overview of AWS Identity and Access Management (IAM)
      1. IAM users
      2. IAM groups
      3. IAM roles
    3. Securing your serverless microservice
      1. Lambda security
      2. DynamoDB security
      3. Monitoring and alerting
    4. Summary
  11. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think