At the time you create a Lambda function, you specify a handler , which is a function in your code, that AWS Lambda can invoke when the service executes your code. Use the following general syntax structure when creating a handler function in Python.
http://docs.aws.amazon.com/lambda/latest/dg/python-programming-model-handler-types.html
* Sign In to the Console * What Is AWS Lambda? * Getting Started * Set Up an AWS Account * Set Up the AWS CLI * Install SAM Local * Create a Simple Lambda Function and Explore the Console * Create a Simple Lambda Function * Lambda Functions * Building Lambda Functions * Programming Model * Programming Model (Node.js) * Handler (Node.js) * The Context Object (Node.js) * Logging (Node.js) * Function Errors (Node.js) * Using Earlier Node.js Runtime (v0.10.42) * Programming Model (Java) * Handler (Java) * Handler Input/Output Types (Java) * Example: Using POJOs for Handler Input/Output (Java) * Example: Using Stream for Handler Input/Output (Java) * Leveraging Predefined Interfaces for Creating Handler (Java) * The Context Object (Java) * Logging (Java) * Function Errors (Java) * Using Earlier Custom Appender for Log4j™ 1.2 (Not Recommended) * Step 2.3: (Optional) Create a Lambda Function Authored in Java * Programming Model (Python) * Handler (Python) * The Context Object (Python) * Logging (Python) * Function Errors (Python) * Programming Model (C#) * Handler (C#) * The Context Object (C#) * Logging (C#) * Function Errors (C#) * Step 2.4: (Optional) Create a Lambda Function Authored in C# * Creating a Deployment Package * Creating a Deployment Package (Node.js) * Creating a Deployment Package (C#) * .NET Core CLI * AWS Toolkit for Visual Studio * Creating a Deployment Package (Java) * Creating a .jar Deployment Package Using Maven without any IDE (Java) * Creating a .jar Deployment Package Using Maven and Eclipse IDE (Java) * Creating a .zip Deployment Package (Java) * Authoring Lambda Functions Using Eclipse IDE and AWS SDK Plugin (Java) * Creating a Deployment Package (Python) * Test Your Serverless Applications Locally Using SAM Local (Public Beta) * Creating Functions Using the AWS Lambda Console Editor * Configuring Lambda Functions * Accessing Resources from a Lambda Function * VPC Support * Tutorials: Accessing Resources in an Amazon VPC * Tutorial: Accessing Amazon ElastiCache in an Amazon VPC * Step 1: Create an ElastiCache Cluster * Step 2: Create a Lambda Function * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function (Upload the Deployment Package) * Step 3: Test the Lambda Function (Invoke Manually) * Tutorial: Accessing Amazon RDS in an Amazon VPC * Step 1: Create an Amazon RDS Instance * Step 2: Create a Lambda Function * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function * Step 3: Test the Lambda Function (Invoke Manually) * AWS Lambda Execution Model * Invoking Lambda Functions * Invocation Types * Understanding Retry Behavior * Understanding Scaling Behavior * Supported Event Sources * Sample Event Data * Use Cases * Amazon S3 * Tutorial * Step 1: Prepare * Step 2: Create a Lambda Function and Invoke It Manually * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function and Test It Manually * Step 3: Add an Event Source * Step 4: Deploy With AWS SAM and AWS CloudFormation * Kinesis * Tutorial * Step 1: Prepare * Step 2: Create a Lambda Function and Invoke It Manually * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function and Test It Manually * Step 3: Add an Event Source * Step 4: Deploy With AWS SAM and AWS CloudFormation * Amazon DynamoDB * Tutorial * Step 1: Prepare * Step 2: Create a Lambda Function and Invoke It Manually * Step 2.1: Create a Lambda Function Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function and Test It Manually * Step 3: Add an Event Source * Step 4: Deploy With AWS SAM and AWS CloudFormation * AWS CloudTrail * Tutorial * Step 1: Prepare * Step 2: Create a Lambda Function and Invoke It Manually * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function and Test It Manually * Step 3: Add Event Source * Step 4: Deploy With AWS SAM and AWS CloudFormation * Amazon SNS * Tutorial * Step 1: Prepare * Step 2: Create a Lambda Function * Step 2.1: Create a Lambda Function Deployment Package * Step 2.2: Create the Execution Role * Step 3: Set Up Cross-Account Permissions * Amazon API Gateway * Using AWS Lambda with Amazon API Gateway (On-Demand Over HTTPS) * Step 1: Prepare * Step 2: Create a Lambda Function and Test It Manually * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function and Test It Manually * Step 3: Create an API Using Amazon API Gateway and Test It * Step 4: Deploy With AWS SAM and AWS CloudFormation * Step 3: Create a Simple Microservice using Lambda and API Gateway * Step 3.1: Create an API Using Amazon API Gateway * Step 3.2: Test Sending an HTTPS Request * Step 3.3: (Optional) Try Other Blueprints * What's Next? * Mobile Backend (Android) * Tutorial * Step 1: Prepare * Step 2: Create the Lambda Function and Invoke It Manually * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create the Lambda Function and Invoke It Manually * Step 3: Create an Amazon Cognito Identity Pool * Step 4: Create a Mobile Application for Android * Scheduled Events * Tutorial * Step 1: Create a Lambda Function * Step 2: Test the Lambda Function (Using a Sample Test Event) * Step 3: Create an Amazon SNS Topic and Subscribe to It * Step 4: Configure a CloudWatch Alarm * Step 5: Test the Lambda Function Again * Step 6: Deploy With AWS SAM and AWS CloudFormation * Schedule Expressions Using Rate or Cron * Custom User Applications * Tutorial * Step 1: Prepare * Step 2: Create a Lambda Function and Invoke It Manually * Step 2.1: Create a Deployment Package * Step 2.2: Create the Execution Role * Step 2.3: Create a Lambda Function * Step 3: Invoke the Lambda Function (AWS CLI) * Step 4: Try More CLI Commands (AWS CLI) * Step 5: Delete the Lambda Function and IAM Role (AWS CLI) * Deploying Lambda-based Applications * Versioning and Aliases * Versioning * Aliases * Tutorial: Using AWS Lambda Aliases * Versioning, Aliases, and Resource Policies * Managing Versioning * Traffic Shifting Using Aliases * Using the AWS Serverless Application Model (AWS SAM) * Create Your Own Serverless Application * Automating Deployment of Lambda-based Applications * Building a Pipeline for Your Serverless Application * Gradual Code Deployment * Monitoring and Troubleshooting Lambda-based Applications * Amazon CloudWatch * Accessing CloudWatch Metrics * Accessing CloudWatch Logs * Metrics * Lambda X-Ray * Administering Lambda-based Applications * Tagging Lambda Functions * API Logging with AWS CloudTrail * Authentication and Access Control * Overview of Managing Access * Using Identity-Based Policies (IAM Policies) * Console Permissions * Using Resource-Based Policies (Lambda Function Policies) * Permissions Model * Lambda API Permissions Reference * Policy Templates * Managing Concurrency * Advanced Topics * Environment Variables * Create a Lambda Function Using Environment Variables * Create a Lambda Function Using Environment Variables To Store Sensitive Information * Dead Letter Queues * Best Practices * Runtime Support Policy * Execution Environment * Limits * AWS Lambda@Edge * API Reference * Actions * AddPermission * CreateAlias * CreateEventSourceMapping * CreateFunction * DeleteAlias * DeleteEventSourceMapping * DeleteFunction * DeleteFunctionConcurrency * GetAccountSettings * GetAlias * GetEventSourceMapping * GetFunction * GetFunctionConfiguration * GetPolicy * Invoke * InvokeAsync * ListAliases * ListEventSourceMappings * ListFunctions * ListTags * ListVersionsByFunction * PublishVersion * PutFunctionConcurrency * RemovePermission * TagResource * UntagResource * UpdateAlias * UpdateEventSourceMapping * UpdateFunctionCode * UpdateFunctionConfiguration * Data Types * AccountLimit * AccountUsage * AliasConfiguration * AliasRoutingConfiguration * Concurrency * DeadLetterConfig * Environment * EnvironmentError * EnvironmentResponse * EventSourceMappingConfiguration * FunctionCode * FunctionCodeLocation * FunctionConfiguration * TracingConfig * TracingConfigResponse * VpcConfig * VpcConfigResponse * Document History * AWS Glossary * AWS Documentation * AWS Lambda * Developer Guide * Lambda Functions * Building Lambda Functions * Programming Model * Programming Model for Authoring Lambda Functions in Python * Creating a Deployment Package (Python) * Create a Simple Lambda Function * Getting Started