-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathlambda_function.rb
More file actions
34 lines (31 loc) · 1.32 KB
/
lambda_function.rb
File metadata and controls
34 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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]