AWS Lambda

Understanding Lambda

Functions

AWS Lambda Function Handler Overview

Once a source event triggers an AWS Lambda function, Lambda invokes the function handler, which serves as the entry point for your code. You can author this handler in any natively supported language, so existing code requires minimal modification. The only requirement is a handler function that accepts two parameters:

ParameterDescription
eventCarries data from the event source (e.g., S3 bucket details, API Gateway payload)
contextProvides runtime metadata (e.g., function name, memory limits, request identifiers)

The image illustrates the flow of data in an AWS Lambda function, showing a source triggering the function handler, which processes event and context objects to execute the Lambda function.

Note

Use the event object to tailor your logic at runtime—extract bucket names for S3 triggers or HTTP headers for API Gateway—and leverage the context object to retrieve execution metadata like remaining run time.

Handler Parameters in Detail

Event Object

The event parameter contains details from the triggering source. For example:

  • S3 events: event['Records'][0]['s3']['bucket']['name']
  • API Gateway: JSON payload with HTTP method, headers, and body

Context Object

The context parameter gives access to runtime information and Lambda environment methods, such as:

  • context.function_name
  • context.get_remaining_time_in_millis()

Python Handler Example

Below is a simple Python function that reads a user's first and last name from the incoming event and returns a personalized greeting:

def lambda_handler(event, context):
    first_name = event.get('first_name', 'Guest')
    last_name = event.get('last_name', '')
    # Construct and trim the greeting message
    message = f"Hello {first_name} {last_name}!".strip()
    return {
        "message": message
    }

Learn More

The image is a slide titled "Functions" with a link to AWS Lambda best practices and a list of topics including writing functions, testing, performance, and more.

Next Up: Lambda Pricing Model

In the next section, we'll explore AWS Lambda's pricing structure, cost optimization strategies, and tips for estimating your monthly bill.

Watch Video

Watch video content

Previous
Access Permissions