1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS CodeBuildを使ってRuby lambda functionにデプロイする

Last updated at Posted at 2019-06-26

方法論的なものが少なかったので。
Rubyだけでなく、他の言語でも応用が効くはず。
CodePipelineと組み合わせると強力。

TLDR

buildspec.yml
# 抜粋
phases:
  install:
    runtime-versions:
      ruby: 2.6
    commands:
      - rbenv install 2.5.5 && rbenv global 2.5.5
      # bundler install --path vendor/bundle等
post_build:
    commands:
      - zip data.zip *.rb -r vendor && aws lambda update-function-code --function-name 'FUNCTION_NAME' --zip-file 'fileb://data.zip'

解説

bundle install した状態のファイル群をまとめてlambdaに投げたい。

Rubyバージョンの乖離

2019/06/26現在、lambdaのRubyは通常2.5しか選択できない。
CodeBuildはRuby2.6しか選択できない。
bundle install --path vendor/bundle したときに困ってしまう。
CodeBuildのログを見る感じrbenvが入っているので使いたいRubyバージョン入れてしまおうというアプローチ。

lambdaへの反映

awsコマンドが使えるので使う。zipを作って普通にアップロード。CodeBuildの権限ロールにlambdaのアクセス権限つけるのを忘れずに。(AWSLambdaFullAccessをつければ動くことは確認)

別のアプローチ

カスタムコンテナ使えば解決ではあるが・・・。

補足

実際の buildspec.yml のコマンド欄には hoge.sh みたいにシェルスクリプトを指定したほうが見通しや管理が楽。
zipするところは必要なファイル群を入れておくこと。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?