Function Properties
Jets ultimately translate Ruby code into Lambda functions. Each Lambda function’s properties can be controlled with Jets. Here are the ways to set the function properties and their order of precedence:
- function specific properties - highest precedence
- class-wide function properties
- global function properties set - lowest precedence
Function Specific Properties
Specific function properties are set right above the method definition like so:
app/events/cool_event.rb
class CoolEvent < ApplicationEvent
timeout 18 # function specific property for the index lambda function
def dig
puts "dig"
end
end
Class-wide Function Properties
Class-wide function properties set in the same class file and with a prefix of class_
.
app/events/cool_event.rb
class CoolEvent < ApplicationEvent
class_timeout 22
timeout 18 # function specific property for the index lambda function
def dig
puts "dig"
end
def lift
puts "lift"
end
end
For the code above, the new
method will have a function timeout of 22 seconds and the index
method will have a function timeout of 18 seconds.
Global Function Properties
To set function properties globally, edit the function key under the config object in:
config/jets/deploy.rb
Jets.deploy.configure do
...
config.lambda.function.timeout = 30
# config.lambda.function.memory_size = 3008
config.lambda.function.environment = {
key1: "value1",
key2: "value2",
}
end
Controllers vs Events
You only have fine-grain control of function properties for Events, not Controllers. This is because each Event method is deployed as a separate discrete Lambda Function. Whereas, a single Lambda Function is deployed to handle all controller requests.
Function Properties Method
In the above example, we use the timeout
and class_timeout
method to set function properties. These convenience methods delegate to the more general properties
and class_properties
methods respectively. The general methods also allow you to change any property for the lambda function. So you could have done this also:
class CoolEvent < ApplicationEvent
class_properties(timeout: 22)
properties(timeout: 18) # function specific property for the index lambda function
def dig
puts "dig"
end
end
Generally all the properties associated with Lambda functions have equivalent convenience methods. Here’s a list:
Function Specific | Class Wide |
---|---|
dead_letter_config | class_dead_letter_config |
description | class_description |
environment | class_environment |
function_name | class_function_name |
handler | class_handler |
kms_key_arn | class_kms_key_arn |
memory_size | class_memory_size |
reserved_concurrent_executions | class_reserved_concurrent_executions |
role | class_role |
runtime | class_runtime |
timeout | class_timeout |
tracing_config | class_tracing_config |
vpc_config | class_vpc_config |
tags | class_tags |
Refer to the AWS::Lambda::Function CloudFormation docs for a list of the properties. You can also refer to the source code itself: lambda/dsl.rb