Elastic Beanstalkで稼働しているアプリケーション(Ruby, Sinatra)をAmazon Linux AMIからAmazon Linux2へ移行
Systems ManagerのメンテナンスウィンドウでというSSMドキュメントにより、インスタンスにパッチ適用を定期的に実行するようにしていました。
管理している一部のインフラ内にセキュリティチェックを導入したのですが、一部のサーバーのみセキュリティ要件に引っかかり続けている状態が発生しました。理由はOS内の各種ライブラリが最新版になっていないことによるものでした。
Amazon Linux AMI は、2020 年 12 月 31 日をもって標準サポートを終了しました。現在、メンテナンスサポート段階にあります。サポートされるパッケージとサポートされないパッケージの詳細なリストはこちらにあります。
アップデートできなかったのは、放置し続けていたため、当然といえば当然ですね。
これらのサーバーはElastic Beanstalkで管理しているものでした。PlatformとしてPuma with Ruby 2.6 running on 64bit Amazon Linuxとして元々稼働していました。これをRuby 2.7 running on 64bit Amazon Linux 2に移行することにしました。
Elastic Beanstalkの公式ドキュメントにはAmazon Linux AMIからAmazon Linux 2に移行するためのガイドが用意されています。
2021/09/29 11:53:18.758807 [ERROR] An error occurred during execution of command [app-deploy] - [stage ruby application]. Stop running the command. Error: install dependencies in Gemfile failed with error Command /bin/sh -c bundle config set --local deployment true failed with error exit status 1. Stderr:/opt/rubies/ruby-2.7.4/lib/ruby/site_ruby/2.7.0/rubygems.rb:281:in `find_spec_for_exe': Could not find 'bundler' (1.17.2) required by your /var/app/staging/Gemfile.lock. (Gem::GemNotFoundException)To update to the latest version installed on your system, run `bundle update --bundler`.To install the missing version, run `gem install bundler:1.17.2` from /opt/rubies/ruby-2.7.4/lib/ruby/site_ruby/2.7.0/rubygems.rb:300:in `activate_bin_path' from /opt/elasticbeanstalk/.rbenv/versions/2.7.4/bin/bundle:23:in `<main>'
[2105] ! Unable to start worker
[2105] /opt/rubies/ruby-2.7.4/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:85:in `require'
[2105] Early termination of worker
[2107] + Gemfile in context: /var/app/current/Gemfile
Creating load balancer named: arn:aws:elasticloadbalancing:ap-northeast-1:012345678901:loadbalancer/app/awseb-AWSEB-XXXXXXXXXXXXX/xxxxxxxxxxxxxxxx failed Reason: The value of 'access_logs.s3.prefix' cannot start or end with '/' (Service: AmazonElasticLoadBalancing; Status Code: 400; Error Code: ValidationError; Request ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; Proxy: null)
Elastic BeantalkでELB(ALB)の設定をする際に、アクセスログのパス名の先頭および最後に/を含めてはいけないにも関わらず設定されていて、Beanstalkの環境のセットアップに失敗していました。
そこで編集しようとしても、Environment named **** is in an invalid state for this operation. Must be Ready.というエラーで編集できない状態が発生しました。