# 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.increment] require "logger" # A function that increments a whole number by one (1) and logs the result. # Requires a manually-provided runtime parameter, 'number', which must be Int # # @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 incremented_number [String] The incremented number. def lambda_handler(event:, context:) logger = Logger.new($stdout) log_level = ENV["LOG_LEVEL"] logger.level = case log_level when "debug" Logger::DEBUG when "info" Logger::INFO else Logger::ERROR end logger.debug("This is a debug log message.") logger.info("This is an info log message. Code executed successfully!") number = event["number"].to_i incremented_number = number + 1 logger.info("You provided #{number.round} and it was incremented to #{incremented_number.round}") incremented_number.round.to_s end # snippet-end:[ruby.example_code.lambda.handler.increment]