Bird
Raised Fist0
AWScloud~20 mins

Creating a Lambda function in AWS - Practice Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Lambda Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
What happens when a Lambda function is invoked with an event?

Consider an AWS Lambda function configured with a handler that processes incoming events. What is the expected behavior when the function is invoked with a valid event?

AThe Lambda function deletes the event without processing it.
BThe Lambda function stores the event in S3 and does not execute any code.
CThe Lambda function automatically scales to multiple instances without running the handler.
DThe Lambda function executes the handler code with the event data and returns a response or error.
Attempts:
2 left
💡 Hint

Think about what a Lambda function is designed to do when triggered.

❓ Configuration
intermediate
2:00remaining
Which IAM role policy allows a Lambda function to write logs to CloudWatch?

You want your Lambda function to write logs to CloudWatch Logs. Which IAM policy statement should be attached to the Lambda execution role?

A{"Effect": "Deny", "Action": ["logs:CreateLogGroup"], "Resource": "*"}
B{"Effect": "Allow", "Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"], "Resource": "arn:aws:logs:*:*:*"}
C{"Effect": "Allow", "Action": ["ec2:StartInstances"], "Resource": "*"}
D{"Effect": "Allow", "Action": ["s3:PutObject"], "Resource": "arn:aws:s3:::my-bucket/*"}
Attempts:
2 left
💡 Hint

Focus on permissions related to CloudWatch Logs actions.

❓ Architecture
advanced
2:30remaining
How to design a Lambda function for high availability and fault tolerance?

You need to design a Lambda function that remains highly available and fault tolerant in case of failures. Which architecture approach best achieves this?

ADisable CloudWatch Logs to improve performance and reduce failure points.
BDeploy the Lambda function only in one Availability Zone to reduce latency.
CDeploy the Lambda function in multiple AWS Regions and use Route 53 latency-based routing to invoke the nearest function.
DUse a single Lambda function with no retries configured to avoid duplicate processing.
Attempts:
2 left
💡 Hint

Consider geographic redundancy and routing to improve availability.

❓ security
advanced
2:30remaining
What is the best practice to secure environment variables in Lambda functions?

You want to store sensitive data like API keys in Lambda environment variables securely. What is the best practice to protect these secrets?

AEncrypt environment variables using AWS KMS and enable Lambda to decrypt them at runtime.
BStore secrets directly in plain text environment variables without encryption.
CHardcode secrets inside the Lambda function code for faster access.
DSend secrets as part of the event payload when invoking the Lambda function.
Attempts:
2 left
💡 Hint

Think about encryption and secure key management.

✅ Best Practice
expert
3:00remaining
How to optimize cold start performance for a Lambda function written in Java?

Java Lambda functions often have longer cold start times. Which approach best reduces cold start latency?

AUse provisioned concurrency to keep Lambda instances initialized and ready to serve requests.
BIncrease the memory allocation to the minimum value to reduce startup time.
CAvoid using any dependencies and write all code inline in the handler method.
DDisable VPC access to reduce network initialization delays.
Attempts:
2 left
💡 Hint

Consider AWS features that keep functions warm.

Practice

(1/5)
1. What is the main purpose of an AWS Lambda function?
easy
A. To run code without managing servers
B. To store large amounts of data
C. To create virtual machines
D. To manage user permissions

Solution

  1. Step 1: Understand Lambda's role

    AWS Lambda lets you run code without needing to manage servers or infrastructure.
  2. Step 2: Compare options

    The incorrect options describe other AWS services such as user permissions (IAM), data storage (S3), and virtual machines (EC2).
  3. Final Answer:

    To run code without managing servers -> Option A
  4. Quick Check:

    Lambda = serverless code execution [OK]
Hint: Lambda runs code without servers [OK]
Common Mistakes:
  • Confusing Lambda with storage services
  • Thinking Lambda manages servers
  • Mixing Lambda with user management
2. Which of the following is the correct way to specify the handler when creating a Lambda function in AWS?
easy
A. handler.index
B. index.handler
C. lambda.handler
D. handler.lambda

Solution

  1. Step 1: Understand handler format

    The handler is specified as filename.functionname. Commonly, the file is index and function is handler.
  2. Step 2: Match options

    Only index.handler matches the correct format; others reverse or misuse parts.
  3. Final Answer:

    index.handler -> Option B
  4. Quick Check:

    Handler = filename.function [OK]
Hint: Handler format is filename.functionname [OK]
Common Mistakes:
  • Swapping filename and function name
  • Using invalid handler names
  • Confusing handler with runtime
3. Given this AWS Lambda function code snippet in Python:
def handler(event, context):
    return event.get('key', 'default')

What will be the output if the event is {}?
medium
A. "default"
B. None
C. Error
D. "key"

Solution

  1. Step 1: Analyze the handler function

    The function returns the value of 'key' from event, or 'default' if 'key' is missing.
  2. Step 2: Check the event input

    The event is an empty dictionary, so 'key' is not present, so it returns 'default'.
  3. Final Answer:

    "default" -> Option A
  4. Quick Check:

    Missing key returns default [OK]
Hint: Missing dict key returns default value [OK]
Common Mistakes:
  • Assuming missing key returns None
  • Expecting an error on missing key
  • Confusing key name with value
4. You created a Lambda function but it fails with a permissions error when invoked. What is the most likely cause?
medium
A. The deployment package is too large
B. The handler name is incorrect
C. The runtime is not supported
D. The Lambda execution role lacks necessary permissions

Solution

  1. Step 1: Understand permissions in Lambda

    Lambda functions need an IAM role with permissions to run and access resources.
  2. Step 2: Identify cause of permissions error

    A permissions error usually means the execution role is missing required permissions.
  3. Final Answer:

    The Lambda execution role lacks necessary permissions -> Option D
  4. Quick Check:

    Permissions error = missing IAM role rights [OK]
Hint: Check IAM role permissions for Lambda [OK]
Common Mistakes:
  • Blaming handler name for permissions error
  • Ignoring IAM role setup
  • Assuming runtime causes permissions error
5. You want to create a Lambda function that processes images uploaded to an S3 bucket. Which combination of settings is required to ensure the Lambda runs automatically when a new image is uploaded?
hard
A. Set Lambda runtime to Node.js and upload images directly to Lambda
B. Manually invoke Lambda after uploading images to S3
C. Set S3 event trigger on bucket for 'ObjectCreated' and assign Lambda execution role with S3 read permissions
D. Create an EC2 instance to monitor S3 and call Lambda

Solution

  1. Step 1: Configure S3 event trigger

    To run Lambda automatically on uploads, configure S3 to trigger Lambda on 'ObjectCreated' events.
  2. Step 2: Assign correct IAM role permissions

    Lambda needs an execution role with permissions to read from S3 to process images.
  3. Final Answer:

    Set S3 event trigger on bucket for 'ObjectCreated' and assign Lambda execution role with S3 read permissions -> Option C
  4. Quick Check:

    S3 trigger + IAM role = automatic Lambda run [OK]
Hint: Use S3 event triggers with proper IAM role [OK]
Common Mistakes:
  • Thinking manual invocation is automatic
  • Confusing runtime with event triggers
  • Using EC2 unnecessarily for Lambda triggers
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard