kasei_sanのブログ

かせいさんのIT系のおぼえがきです。胡乱の方はnoteとtwitterへ

serverless のバージョンが古いまま、lambda ruby 2.7 を使うと The security token included in the request is invalid エラーが出てハマるので最新版にしよう

というお話です

出てくるエラー

ruby 2.7 で serverless invoke を実行すると --aws-profile を設定していても The security token included in the request is invalid が出ます

Error raised from handler method
{ 
  "errorMessage": "The security token included in the request is invalid.",
  "errorType": "Function<Aws::SSM::Errors::UnrecognizedClientException>",
  "stackTrace": [
    "/var/runtime/gems/aws-sdk-core-3.94.1/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'",
    "/var/runtime/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'",
    "/var/runtime/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/idempotency_token.rb:17:in `call'",
    "/var/runtime/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/param_converter.rb:24:in `call'",
    "/var/runtime/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'",
    "/var/runtime/gems/aws-sdk-core-3.94.1/lib/seahorse/client/plugins/response_target.rb:23:in `call'",
    "/var/runtime/gems/aws-sdk-core-3.94.1/lib/seahorse/client/request.rb:70:in `send_request'",
    "/var/runtime/gems/aws-sdk-ssm-1.76.0/lib/aws-sdk-ssm/client.rb:7859:in `send_command'",
    "/var/task/handler.rb:6:in `hoge'"
  ]
}

原因

serverlessのバグです

github.com

対応方法

最新版の serverless をインストールしましょう