rails-lambda / lamby

🐑🛤 Simple Rails & AWS Lambda Integration
https://lamby.cloud
MIT License
602 stars 29 forks source link

cannot load such file -- config/environment #158

Closed hopewise closed 1 year ago

hopewise commented 1 year ago

Trying to use lamby in an existing rails app, I am getting this error when access the app in aws lambda url:

Executing 'config/environment.Lamby.cmd' in function directory '/tmp'
Init error when loading handler 
{
"errorMessage": "cannot load such file -- config/environment",
"errorType": "Init<LoadError>",
"stackTrace": [
"/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'",
"/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'",
"/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric.rb:41:in `run'",
"/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric/bootstrap.rb:35:in `bootstrap_handler'",
"/usr/local/bundle/gems/aws_lambda_ric-2.0.0/lib/aws_lambda_ric/bootstrap.rb:8:in `start'",
"/usr/local/bundle/gems/aws_lambda_ric-2.0.0/bin/aws_lambda_ric:10:in `<top (required)>'",
"/usr/local/bundle/bin/aws_lambda_ric:23:in `load'",
"/usr/local/bundle/bin/aws_lambda_ric:23:in `<main>'"
]
}
FROM ruby:2.7.2

RUN apt-get update

# Install MySQL client and server
RUN apt-get install -y --no-install-recommends default-mysql-client

# Set the working directory to /app
WORKDIR /tmp
COPY Gemfile Gemfile.lock ./

# could not get it from AWS SAM:
ARG BUNDLE_GITHUB__COM 
ARG RailsEnv
ENV RAILS_ENV=$RAILS_ENV
ENV BUNDLE_GITHUB__COM

RUN gem install 'aws_lambda_ric'
ENTRYPOINT [ "/usr/local/bundle/bin/aws_lambda_ric" ]

COPY . .

RUN rm -rf /tmp/vendor
RUN bundle install

CMD ["config/environment.Lamby.cmd"]

I do have gem "lamby" in Gemfile, shouldn't it present the entry point for Lambda function ?

Your help is appreciated.

metaskills commented 1 year ago

Your WORKDIR is tmp which means you are COPY'ing your app into a directly that the Lambda service will treat as a tmp dir, meaning it deletes everything there. Put your app into an app directory or some other run dir. Here is a Dockerfile for an example.

https://github.com/customink/lamby-cookiecutter/blob/master/%7B%7Bcookiecutter.project_name%7D%7D/Dockerfile

metaskills commented 1 year ago

Hey @hopewise, hope you are doing well. Did you get thru this issue alright?

hopewise commented 1 year ago

Hi @metaskills , that for asking! yes, I have fixed that issue, thanks very much.