AWS Lambda Functions u0026 Handlers Fundamentals Quiz Quiz

Challenge your understanding of AWS Lambda basics with questions on functions and handlers, exploring key concepts like triggers, event objects, return types, and runtime settings. Sharpen your foundational knowledge of serverless compute, error handling, and best practices commonly used in cloud-based application development.

  1. Purpose of Lambda Handler

    In a Lambda function, what is the primary role of the handler?

    1. It triggers other cloud functions automatically.
    2. It processes incoming events and returns a response.
    3. It allocates memory resources to the function.
    4. It encrypts data before execution.

    Explanation: The handler is the entry point for the Lambda function and is responsible for processing incoming events and producing a response. Allocating memory resources is managed through configuration, not the handler itself. Triggering other cloud functions is not the handler's main purpose, though a handler can choose to invoke other services. Encrypting data is not handled automatically by the handler.

  2. File Naming Convention

    Which file would typically contain the handler code for a Lambda function named 'processData' using Python?

    1. lambda-handler.txt
    2. lambda_function.py
    3. main.js
    4. processData.handler

    Explanation: In Python-based Lambda functions, 'lambda_function.py' is the default file that contains the handler code. 'processData.handler' is not a valid Python file format. 'main.js' would be relevant for JavaScript, not Python. 'lambda-handler.txt' is not a recognized file type for code.

  3. Event Object Contents

    What commonly describes the 'event' object received by a Lambda handler?

    1. It is an encrypted string unrelated to context.
    2. It stores the function's environment variables.
    3. It is always an empty object regardless of trigger.
    4. It contains the details of the trigger or request.

    Explanation: The 'event' object carries information about the invocation trigger such as request data or resource information. It is rarely empty as it usually reflects some data from the event source. Environment variables are accessed separately, not through the event object. The event object is not simply an encrypted unrelated value.

  4. Valid Lambda Handler Syntax

    Which of the following represents a valid handler signature in Python?

    1. def handler(event, context):
    2. function handle(event):
    3. lambda_handler(event)
    4. public void handler(event, context);

    Explanation: The standard handler signature in Python includes two arguments: 'event' and 'context'. 'function handle(event):' resembles JavaScript and is missing the context parameter. 'public void handler(event, context);' uses syntax from Java or C#, not Python. 'lambda_handler(event)' is missing the context parameter and has an incorrect syntax for Python.

  5. Return Value in HTTP Trigger

    When a Lambda function handles an HTTP request, what is it typically expected to return?

    1. A numeric value indicating execution time
    2. A bare string representing the body only
    3. A dictionary with statusCode and body keys
    4. A list of environment variables

    Explanation: A typical return value for HTTP-triggered Lambda invokes is a dictionary containing at least 'statusCode' and 'body'. Returning only a string is not sufficient, as status information is required. Numeric values like execution time are for logging, not response. A list of environment variables is unrelated to the HTTP response.

  6. Function Timeout

    If a Lambda function is set with a timeout of 5 seconds and runs for 7 seconds, what is the result?

    1. The function restarts automatically.
    2. The function is paused and resumes when possible.
    3. The function is stopped after 5 seconds and marked as a timeout.
    4. The function waits until it finishes no matter how long it takes.

    Explanation: If the function runs longer than its configured timeout, it is terminated and the invocation is marked as timed out. Lambda does not allow indefinite execution. Automatic restarts or pause-resume behavior are not standard features for timeouts.

  7. Environment Variable Reading

    How can a Lambda function in Python typically access an environment variable named 'BUCKET_NAME'?

    1. By reading from the event object directly
    2. By passing it as a command-line argument
    3. By using os.environ['BUCKET_NAME']
    4. By importing 'bucket_name' as a module

    Explanation: Environment variables in Python are accessed via the os.environ dictionary. The event object does not generally contain environment variables unless explicitly included. Lambda functions do not use command-line arguments. Importing variables as modules is not a recognized practice for environment variables.

  8. Triggering Lambda Functions

    What is a common way to trigger a Lambda function automatically?

    1. Waiting for its memory usage to exceed a threshold
    2. Manually modifying code while it is running
    3. Configuring a resource such as an object store to invoke it on events
    4. Typing its name into the console prompt

    Explanation: Lambda functions are often triggered by setting up resources to invoke them upon certain events, like file uploads. Typing names into a console and modifying code do not trigger functions. Memory thresholds are not trigger mechanisms.

  9. Code Package Size Limit

    What is the approximate maximum uncompressed deployment package size for a Lambda function?

    1. 2 MB
    2. 5 MB
    3. 10 GB
    4. 250 MB

    Explanation: The uncompressed deployment package size limit for Lambda is around 250 MB. Five megabytes and two megabytes are too small for typical deployment packages. Ten gigabytes exceeds the platform's allowance by a large margin.

  10. Error Handling in Lambda

    If a Lambda handler raises an exception and it is not caught, what happens during function execution?

    1. The error is silently ignored with no log entry.
    2. The function automatically retries until it succeeds.
    3. The handler converts the exception to a successful response.
    4. The exception causes the invocation to fail and logs the error.

    Explanation: Uncaught exceptions in handlers result in a failure of the invocation, and the error is logged for review. Lambda does not automatically retry indefinitely or convert errors to success responses. Errors are not ignored; visibility is essential for debugging.