Ruby handler param bugs
See original GitHub issueDescribe the issue There are several weird bugs happening in sandbox for Ruby lambdas:
- When setting the handler method arguments as
def handler(event, context)
.....
end
You get the following error: handler': wrong number of arguments (given 0, expected 2) (ArgumentError)
- To fix the above error, you can provide a default empty hash to the arguments:
def handler(event={}, context={})
.....
end
However, this causes different issues when introducing an error into the code. If I were to then intentionally cause a bug, the function is now executed twice in a row, and the value of the arguments are empty the second time around.
def handler(event = {}, context = {})
puts event
puts context
puts foo # raise an undefined local variable error
{ body: 'hello world' }
end
Result:
/Users/jeremycohenhoffing/projects/lambda-test-app/src/http/get-index/index.rb:9:in `handler': undefined local variable or method `foo' for main:Object (NameError)
from -e:16:in `rescue in <main>'
from -e:12:in `<main>'
{:event=>{"version"=>"2.0", "routeKey"=>"GET /", "rawPath"=>"/", "rawQueryString"=>"", "cookies"=>["some_cookies"], "headers"=>{"host"=>"localhost:3333", "cache-control"=>"max-age=0", "sec-ch-ua"=>"\", "accept"=>"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-language"=>"en-US,en;q=0.9", "sec-gpc"=>"1"}, "requestContext"=>{"http"=>{"method"=>"GET", "path"=>"/"}, "routeKey"=>"GET /"}, "isBase64Encoded"=>false}, :context=>{"aws_request_id"=>"xxxxxx", "function_name"=>"sandbox-get-index", "function_version"=>"$LATEST", "invoked_function_arn"=>"sandbox", "memory_limit_in_mb"=>1152}}
{}
{} # second time the function is executed with arguments now empty
{}
Please also see this discussion: https://discord.com/channels/880272256100601927/884128391341678742/953697307528929280
Steps to reproduce Steps to reproduce the behavior:
- I created a boilerplate Architect v10.1.0 project here: https://github.com/jcohenho/ruby-lambda-test-arc-app
- Run the app with
npx arc sandbox
- For the first issue, change the handler arguments to
def handler(event, context)
- For the second issue, intentionally add a bug and see that the handler is executed twice
Expected behavior
- I expect the lambda handler to run only once
- I expect the lambda to not have weird params issues and show correct errors
Screenshots If applicable, add screenshots to help explain your problem
Desktop Please complete the following information (if appropriate):
- OS: MacOS Catalina 10.15.6
- Browser: Chrome
- Version: 98.0.4758.109
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
lots of stuff on the go but I’ll do my best to have a look today 🙏
@brianleroux @ryanblock I would love to help contribute to this but I need a little help and guidance for how to run and test this sandbox code locally. I’m not sure where to begin so any advice would be much appreciated 🙏