Server-less Python Web Services for AWS Lambda and API Gateway
Complete command-line interface operations for Zappa deployment lifecycle management. The ZappaCLI class provides user-friendly commands for initializing, deploying, monitoring, and managing serverless applications.
Initialize new Zappa projects with configuration templates and setup.
def init(self):
"""
Initialize a new Zappa project by creating settings template.
Creates zappa_settings.json configuration file with default settings
for development and production environments.
Returns:
bool: True if initialization successful
"""Deploy new applications and update existing deployments.
def deploy(self):
"""
Deploy Zappa application to AWS Lambda and API Gateway.
Creates Lambda function, API Gateway, and all necessary AWS resources.
Uses settings from zappa_settings.json configuration file.
Returns:
bool: True if deployment successful
"""def update(self):
"""
Update existing Zappa deployment with new code and configuration.
Updates Lambda function code and configuration while preserving
existing API Gateway and other resources.
Returns:
bool: True if update successful
"""Monitor, rollback, and clean up deployments.
def status(self):
"""
Show current deployment status and information.
Displays Lambda function status, API Gateway endpoints,
recent deployments, and resource utilization.
Returns:
dict: Status information and metadata
"""def undeploy(self):
"""
Remove Zappa deployment and clean up AWS resources.
Deletes Lambda function, API Gateway, IAM roles, and other
associated AWS resources.
Returns:
bool: True if removal successful
"""def rollback(self):
"""
Roll back deployment to previous version.
Reverts Lambda function to previous version and updates
API Gateway to point to rolled-back function.
Returns:
bool: True if rollback successful
"""Monitor application logs and access remote execution environment.
def tail(self):
"""
Stream Lambda function logs in real-time.
Displays CloudWatch logs for the deployed function with
real-time updates and filtering options.
Returns:
None: Runs continuously until interrupted
"""def shell(self):
"""
Open remote Python shell session on Lambda.
Provides interactive Python REPL running in the Lambda
environment with access to deployed application context.
Returns:
None: Interactive session until exit
"""Create deployment packages and templates without deploying.
def package(self):
"""
Create deployment package without deploying to AWS.
Generates Lambda deployment ZIP package with all
dependencies and code for manual deployment or inspection.
Returns:
str: Path to created package file
"""def template(self):
"""
Generate CloudFormation or SAM template for deployment.
Creates Infrastructure as Code template that can be
deployed using CloudFormation or SAM CLI.
Returns:
str: Path to generated template file
"""Manage scheduled events and invocations.
def schedule(self):
"""
Schedule events for deployed Lambda function.
Creates CloudWatch Events rules to trigger Lambda
function on specified schedules (cron or rate expressions).
Returns:
bool: True if scheduling successful
"""def unschedule(self):
"""
Remove scheduled events for Lambda function.
Deletes CloudWatch Events rules and stops
scheduled execution of Lambda function.
Returns:
bool: True if unscheduling successful
"""def invoke(self):
"""
Invoke deployed Lambda function with test data.
Executes Lambda function with specified payload
for testing and debugging purposes.
Returns:
dict: Function response and execution details
"""Manage SSL certificates for custom domains.
def certify(self):
"""
Generate and configure SSL certificates for custom domains.
Uses Let's Encrypt to obtain SSL certificates and
configures them with API Gateway custom domains.
Returns:
dict: Certificate information and domain configuration
"""Save and manage deployment configuration settings.
def save_python_settings_file(self):
"""
Save current Python settings to configuration file.
Exports runtime configuration including Python version,
dependencies, and environment settings to file.
Returns:
bool: True if save successful
"""Advanced deployment and management operations.
def check_environment(self):
"""
Validate deployment environment and dependencies.
Checks Python version, AWS credentials, dependencies,
and configuration for deployment compatibility.
Returns:
dict: Environment validation results
"""def check_stage_name(self, stage_name):
"""
Validate stage name format and availability.
Checks if stage name follows AWS naming conventions
and doesn't conflict with existing deployments.
Parameters:
- stage_name: str, deployment stage name to validate
Returns:
bool: True if stage name is valid
"""def print_logs(self):
"""
Display formatted Lambda function logs.
Retrieves and displays CloudWatch logs with
filtering, coloring, and formatting options.
Returns:
None: Outputs logs to console
"""def handle():
"""
Main CLI entry point for command processing.
Parses command-line arguments and routes to appropriate
ZappaCLI methods. Used by 'zappa' and 'z' console commands.
Returns:
None: Exits with status code
"""# Custom Zappa-specific settings
CUSTOM_SETTINGS = [
'apigateway_policy',
'assume_policy',
'attach_policy',
'aws_region',
'delete_local_zip',
'delete_s3_zip',
'exclude',
'exclude_glob',
'extra_permissions',
'include',
'role_name',
'touch'
]
# Documentation reference
BOTO3_CONFIG_DOCS_URL = "https://boto3.readthedocs.io/en/latest/guide/quickstart.html#configuration"from zappa.cli import ZappaCLI
# Create CLI instance
cli = ZappaCLI()
# Initialize new project (creates zappa_settings.json)
cli.init()
# Deploy to AWS (creates all resources)
cli.deploy()
# Update deployment with changes
cli.update()
# Check deployment status
cli.status()
# Stream logs for monitoring
cli.tail()
# Clean up when done
cli.undeploy()The init() command creates a zappa_settings.json file with the following structure:
{
"dev": {
"app_function": "app.app",
"aws_region": "us-east-1",
"profile_name": "default",
"project_name": "my-project",
"runtime": "python3.9",
"s3_bucket": "my-deployments-bucket"
},
"production": {
"app_function": "app.app",
"aws_region": "us-east-1",
"profile_name": "default",
"project_name": "my-project-prod",
"runtime": "python3.9",
"s3_bucket": "my-deployments-bucket"
}
}# Initialize new project
zappa init
# Deploy to dev environment
zappa deploy dev
# Update dev deployment
zappa update dev
# Check status
zappa status dev
# Stream logs
zappa tail dev
# Deploy to production
zappa deploy production
# Roll back production
zappa rollback production
# Remove deployment
zappa undeploy devInstall with Tessl CLI
npx tessl i tessl/pypi-zappa