awspecの認証エラー on Cloud9


背景

Cloud9でawspecを試そうとしたらエラーでた

$ rake spec
/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/ruby -I/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-support-3.8.2/lib:/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-core-3.8.2/lib /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-core-3.8.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

ecs_cluster 'cluster-4cb3167'
  should exist (FAILED - 1)

Failures:

  1) ecs_cluster 'cluster-4cb3167' should exist
     Failure/Error: it { should exist }

     Aws::Errors::MissingCredentialsError:
       unable to sign request without credentials set
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/signature_v4.rb:119:in `rescue in apply_signature'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/signature_v4.rb:111:in `apply_signature'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/signature_v4.rb:65:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/transfer_encoding.rb:26:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/helpful_socket_errors.rb:10:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/retry_errors.rb:174:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/json/handler.rb:11:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/user_agent.rb:13:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/endpoint_pattern.rb:28:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/endpoint_discovery.rb:78:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/seahorse/client/plugins/endpoint.rb:45:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/param_validator.rb:24:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/seahorse/client/plugins/raise_response_errors.rb:14:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/idempotency_token.rb:17:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/param_converter.rb:24:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/seahorse/client/plugins/response_target.rb:23:in `call'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-core-3.58.0/lib/seahorse/client/request.rb:70:in `send_request'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sdk-ecs-1.43.0/lib/aws-sdk-ecs/client.rb:2018:in `describe_clusters'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/awspec-1.17.4/lib/awspec/helper/client_wrap.rb:26:in `method_missing'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/awspec-1.17.4/lib/awspec/helper/finder/ecs.rb:5:in `find_ecs_cluster'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/awspec-1.17.4/lib/awspec/type/ecs_cluster.rb:9:in `resource_via_client'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/awspec-1.17.4/lib/awspec/type/base.rb:26:in `respond_to_missing?'
     # ./spec/ecs_spec.rb:12:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Aws::Sigv4::Errors::MissingCredentialsError:
     #   unable to sign request without credentials set
     #   /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/aws-sigv4-1.1.0/lib/aws-sigv4/signer.rb:665:in `get_credentials'

Finished in 7.48 seconds (files took 11.26 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/ecs_spec.rb:12 # ecs_cluster 'cluster-4cb3167' should exist

/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/ruby -I/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-support-3.8.2/lib:/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-core-3.8.2/lib /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-core-3.8.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed

原因

Aws::Errors::MissingCredentialsError と出てるので、認証関連が原因ぽい
認証関連設定した覚えがなかったが、spec/spec_helper.rb
Awsecrets.load(secrets_path: File.expand_path('./secrets.yml', File.dirname(__FILE__)))と記載があった
ここ通りに$ awspec init実行すると作られたみたい

対応方法

spec/spec_helper.rbのAwsecretsの部分を削除して

require 'awspec'
- Awsecrets.load(secrets_path: File.expand_path('./secrets.yml', File.dirname(__FILE__)))

再実行すればいけた!

$ rake spec
/home/ec2-user/.rvm/rubies/ruby-2.6.3/bin/ruby -I/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-support-3.8.2/lib:/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-core-3.8.2/lib /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rspec-core-3.8.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb

ecs_cluster 'cluster-cb481a9'
  should exist

Finished in 0.06648 seconds (files took 3.71 seconds to load)
1 example, 0 failures

参考