2022-10-06 14:10:53 -06:00
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# frozen_string_literal: true
# snippet-start:[ruby.example_code.lambda.handler.multiply]
2024-09-25 15:25:54 -04:00
require 'logger'
2022-10-06 14:10:53 -06:00
# A function that multiplies two whole numbers and logs the result.
# Requires two whole numbers provided at runtime: 'first_number' and 'second_number'.
#
# @param event [Hash] Parameters sent when the function is invoked.
# @param context [Hash] Methods and properties that provide information.
# about the invocation, function, and execution environment.
# @ return product [String] The product of the two numbers.
def lambda_handler ( event : , context : )
logger = Logger . new ( $stdout )
2024-09-25 15:25:54 -04:00
log_level = ENV [ 'LOG_LEVEL' ]
2022-10-06 14:10:53 -06:00
logger . level = case log_level
2024-09-25 15:25:54 -04:00
when 'debug'
2022-10-06 14:10:53 -06:00
Logger :: DEBUG
2024-09-25 15:25:54 -04:00
when 'info'
2022-10-06 14:10:53 -06:00
Logger :: INFO
else
Logger :: ERROR
end
2024-09-25 15:25:54 -04:00
first_number = event [ 'first_number' ] . to_f
second_number = event [ 'second_number' ] . to_f
2022-10-06 14:10:53 -06:00
product = first_number . round * second_number . round
logger . info ( " The product of #{ first_number . round } and #{ second_number . round } is #{ product } " )
product . to_s
end
# snippet-end:[ruby.example_code.lambda.handler.multiply]