Open
Description
While executing test event in AWS Lambda console for a Ruby 3.3 lambda function, which bundles the json
gem version 2.9 (bundled via MailchimpTransactional) I get the following error:
{
"errorMessage": "undefined method `parse' for class JSON::Ext::Parser",
"errorType": "Init<NoMethodError>",
"stackTrace": [
"/var/task/vendor/bundle/ruby/3.3.0/gems/json-2.9.0/lib/json/common.rb:221:in `parse'",
"/var/runtime/gems/aws_lambda_ric-3.0.0/lib/aws_lambda_ric/aws_lambda_marshaller.rb:15:in `marshall_request'",
"/var/runtime/gems/aws_lambda_ric-3.0.0/lib/aws_lambda_ric.rb:76:in `wait_for_invocation'",
"/var/runtime/gems/aws_lambda_ric-3.0.0/lib/aws_lambda_ric.rb:65:in `start_runtime_loop'",
"/var/runtime/gems/aws_lambda_ric-3.0.0/lib/aws_lambda_ric.rb:49:in `run'",
"/var/runtime/gems/aws_lambda_ric-3.0.0/lib/aws_lambda_ric.rb:221:in `bootstrap_handler'",
"/var/runtime/gems/aws_lambda_ric-3.0.0/lib/aws_lambda_ric.rb:203:in `start'",
"/var/runtime/index.rb:4:in `<main>'"
]
}
Using json
gem version 2.5.1 with 3.2 ruby runtime works fine.
Activity
ravi-bebble commentedon Jan 3, 2025
Hey I am also getting the same error on my ruby 3.3 Lambda
But upon checking more logs I am also getting an initialization error as
Wanted to know if you were able to fix it
coreystinson2 commentedon Feb 12, 2025
I started seeing this issue yesterday on Lambda's we deployed readme updates to. e.g. no code changes.
Ruby 3.3.0 runtime with no reference to "json" in the Gemfile, explicitly adding version 2.5.0 resolved the issue.
gem "json", "~> 2.5.0"
Curious as to how this breaks all of a sudden, we have cached build assets so this is 100% a Lambda problem.
mullermp commentedon Feb 23, 2025
The gem does not declare any dependency on the json gem - it is bundled with your installation in ruby. Both of the stack traces are different - one is actually for the AWS SDK and the other in Lambda. I'm inclined to believe this is related to Ruby 3.3 and JSON 2.9. Can you try using the latest
json
2.10?halo commentedon Jun 12, 2025
For others who googled their way here because of a similar error:
When you run your lambda app in a local docker container, make sure you call it using POST and not GET.
On AWS lambda in the cloud (running that very same container), however, this error does not occur, both GET and POST work fine for some reason.
Also, I tried to reproduce the error originally posted here (
undefined method 'parse' for class JSON::Ext::Parser
) with ruby 3.2, 3.3, 3.4 and various combinations of the json gem 2.5, 2.9, 2.12, but it always worked fine.