LoginSignup
2
0

More than 3 years have passed since last update.

AWS Lambdaでのbundle install

Last updated at Posted at 2019-08-06

Lambdaでアプリ作成時にgemインストールできなくてモヤモヤしたので、備忘録。

知らなかったのですが、Lambdaは実行時、ディレクトリを一つずつ実行するようです。
なので、もしそのディレクトリ直下にgemのpathがなければ、いくらbundle installしてもgemが反映されないよ、という話でした。
解決してみれば、それだけ!?という内容ですが、そこに至るまでかなり時間がかかったので、記録に残しておきます。

bundle installする前に得ていたエラー

{
  "errorType": "Function\u003cNameError\u003e",
  "errorMessage": "uninitialized constant HTTParty",
  "stackTrace": [
    "/var/task/post_to_slack.rb:96:in `post_request'",
    "/var/task/post_to_slack.rb:44:in `lambda_handler'"
  ]
}

gemを使用するためにしたこと

ということで、例えば hello_world というディレクトリがあったら、まずその中のGemfileにgemを追加。

そして下記コマンドでbundle installするPathを指定します。

$ cd hello_world
$ bundle install --path vendor/bundle

├── README.md                   
├── event.json                  
├── hello_world                
│   ├── app.rb                 
│   ├── Gemfile
│   └── vendor
│         └── bundle   <-- 追加!
├── template.yaml           
├── Gemfile                   
└── tests                   
    └── unit
        └── test_handler.rb

これで、無事gemを使用することができました!

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0