Complete the code to define a serverless function handler in AWS Lambda.
def lambda_handler(event, context): return [1]
The Lambda handler must return a response, here a simple string message.
Complete the code to create an AWS Lambda function with a runtime environment.
resource "aws_lambda_function" "example" { function_name = "my_lambda" runtime = [1] handler = "index.lambda_handler" role = aws_iam_role.lambda_role.arn filename = "function.zip" }
Using a modern supported runtime like python3.9 ensures better performance and support.
Fix the error in the AWS SAM template to define a serverless function with correct memory size.
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.9
MemorySize: [1]MemorySize must be an integer value in MB without units.
Fill both blanks to configure an API Gateway trigger for a Lambda function in Terraform.
resource "aws_lambda_permission" "apigw" { statement_id = "AllowAPIGatewayInvoke" action = [1] function_name = aws_lambda_function.my_lambda.function_name principal = [2] source_arn = aws_api_gateway_rest_api.myapi.execution_arn }
The action must be 'lambda:InvokeFunction' and the principal is 'apigateway.amazonaws.com' to allow API Gateway to invoke Lambda.
Fill all three blanks to define a serverless function with environment variables and timeout in AWS SAM.
Resources:
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.9
Timeout: [1]
Environment:
Variables:
STAGE: [2]
LOG_LEVEL: [3]Timeout is set to 30 seconds, STAGE environment variable to 'prod', and LOG_LEVEL to 'INFO' as strings.