When trying to run the default project with ruby2.5 runtime, get the following error:
{
"errorType": "Init\u003cLoadError\u003e",
"errorMessage": "cannot load such file -- httparty",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/app.rb:1:in `\u003ctop (required)\u003e'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
// Install Docker and start service
// Install Ruby 2.5 via rvm
// Install SAM local 0.9.0 via python pip venv
$ sam init --runtime ruby2.5
$ cd sam-app/
$ bundle install
$ bundle install --deployment --path hello_world/vendor/bundle
$ sam local start-api
When trying to navigate to http://localhost:3000/hello
daver@localhost:[~/code/sam-app]: sam local start-api
2019-01-07 15:50:23 Found credentials in shared credentials file: ~/.aws/credentials
2019-01-07 15:50:23 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2019-01-07 15:50:23 You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2019-01-07 15:50:23 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2019-01-07 15:50:41 Invoking app.lambda_handler (ruby2.5)
Fetching lambci/lambda:ruby2.5 Docker container image......
2019-01-07 15:50:42 Mounting /home/daver/code/sam-app/hello_world as /var/task:ro inside runtime container
Init error when loading handler app.lambda_handler
{
"errorMessage": "cannot load such file -- httparty",
"errorType": "Init<LoadError>",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/app.rb:1:in `<top (required)>'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
START RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Version: $LATEST
END RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72
REPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Duration: 0.00 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 16 MB
{
"errorType": "Init\u003cLoadError\u003e",
"errorMessage": "cannot load such file -- httparty",
"stackTrace": [
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/task/app.rb:1:in `\u003ctop (required)\u003e'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'",
"/var/lang/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'"
]
}
2019-01-07 15:50:44 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received:
2019-01-07 15:50:44 127.0.0.1 - - [07/Jan/2019 15:50:44] "GET /hello HTTP/1.1" 502 -
No error
sam --version: 0.9.0@daveroberts Is the httparty gem/code in the correct folder?
Note: You should upgrade to 0.10.0 and use sam build. v0.10.0 supports building ruby functions.
The gem / code is here: bundle install --deployment --path hello_world/vendor/bundle
Whether or not that's the correct folder I don't know.
When I try to upgrade SAM I get this error:
Requirement already satisfied, skipping upgrade: PyYAML~=3.12 in /home/daver/venv/lib/python3.6/site-packages (from aws-sam-cli) (3.13)
Will not install to the user site because it will lack sys.path precedence to aws-lambda-builders in /home/daver/venv/lib/python3.6/site-packages
@daveroberts How are you upgrading?
pip install --user --upgrade aws-sam-cli
I was able to get sam 0.10 by blowing away all python on my machine and just reinstalling from scratch though.
@daveroberts Does the sam build remove this problem you are seeing? The build support for ruby will do the right thing, so its a littler easier to dig into than the manual approach we had before.
sam build will create a vendor/bundle directory under .aws-sam/build/function_name_here, but sam package won't upload that vendor/bundle directory to the zip file in S3, only the app.rb, Gemfile and Gemfile.lock
When using build with the package command, you can omit the --template-file option. SAM CLI will then default to the built template and code. If you provide that option, you are telling SAM to use that (which probably doesn't have your built code).
That was 100% the issue. So the template file should be used on the build step but not the package step?
Thank you for your help and your patience
If using build, yes.
When we added build support, we changed some of the default options behaviors. sam local [invoke|start-api|start-lambda] will pick up the built template (and therefore the built code) if -t|--template options are not used. If you didn't build or the built template is not available, then we default to the template.[yml|yaml] like we did previously. To easy the pain of packaging and so you didn't have to provide the built template, we added this same default behavior to the sam package command. So now you can omit the option from sam package and will behave identical to how our other sam local commands operate.
Does that clear up some of the "when should I provide vs not provide a template?
Yes, a bit, but it's a mystery unless explained. Thank you again
No problem. We are working on getting the init examples updated so that its a little more clear. I have seen this confusion a couple times now, so you aren't alone and gives an indication of more documentation needed in this area.
Most helpful comment
When using build with the package command, you can omit the
--template-fileoption. SAM CLI will then default to the built template and code. If you provide that option, you are telling SAM to use that (which probably doesn't have your built code).