Book Image

Building Serverless Python Web Services with Zappa

By : Abdulwahid Abdulhaque Barguzar
Book Image

Building Serverless Python Web Services with Zappa

By: Abdulwahid Abdulhaque Barguzar

Overview of this book

Serverless applications are becoming very popular these days, not just because they save developers the trouble of managing the servers, but also because they provide several other benefits such as cutting heavy costs and improving the overall performance of the application. This book will help you build serverless applications in a quick and efficient way. We begin with an introduction to AWS and the API gateway, the environment for serverless development, and Zappa. We then look at building, testing, and deploying apps in AWS with three different frameworks--Flask, Django, and Pyramid. Setting up a custom domain along with SSL certificates and configuring them with Zappa is also covered. A few advanced Zappa settings are also covered along with securing Zappa with AWS VPC. By the end of the book you will have mastered using three frameworks to build robust and cost-efficient serverless apps in Python.
Table of Contents (20 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

AWS Lambda interaction with theAWS CLI 


The AWS CLI is an open source tool developed on top of AWS SDK for Python using the Boto library, which provides commands to interact with AWS services. With the very minimum configuration, you can manage any AWS services from the CLI. It provides direct access to AWS services and you can develop shell scripts to manage your resources.

For example, if you want to upload the file to the S3 bucket, then you can do so by just a single command from the CLI:

$ aws s3 cp index.html s3://bucket-name/

aws s3 cp is a shell-like command that performs the multi-part file upload operation in order to complete the operation.

It also supports customization for some of the AWS services. You can see the list of AWS services supported by aws-cli by using the --help command.

Installing the AWS CLI

awscli is available to as a Python distributor package. You can easily install it with the pip command, as described in the following code:

$ pip install awscli --upgrade 

Here are the prerequisites:

  • Python 2 with version 2.6.5+ or Python 3 with version 3.3+
  • Unix, Linux, macOS, or Windows

Configuring the AWS CLI

awscli directly accesses AWS services but we need to configure and authenticate it in order to access AWS services.

Run the aws configure command to configure the AWS CLI with your Amazon account:

You can get the AWS access key ID and AWS secret access key from the My Security Credentials option, as shown in the following screenshot:

Let's configure the AWS Lambda function using AWS CLI.