aws / aws-codedeploy-agent

Host Agent for AWS CodeDeploy
https://aws.amazon.com/codedeploy
Apache License 2.0
328 stars 188 forks source link

Error on credential file load for local codedeploy agent #352

Open domcneil-vassar opened 1 year ago

domcneil-vassar commented 1 year ago

Error on credential file load for local codedeploy agent

2023-03-10 16:54:50 ERROR [codedeploy-agent(18416)]: booting child: error during start or run: RuntimeError - Failed to load credentials from path credentials - /opt/codedeploy-agent/lib/instance_agent/file_credentials.rb:18:in refresh' /opt/codedeploy-agent/vendor/gems/aws-sdk-core-3.121.1/lib/aws-sdk-core/refreshing_credentials.rb:22:ininitialize' /opt/codedeploy-agent/lib/instance_agent/file_credentials.rb:11:in initialize' /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/onpremise_config.rb:38:innew' /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/onpremise_config.rb:38:in configure' /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:37:ininitialize' /opt/codedeploy-agent/lib/instance_agent/agent/base.rb:10:in new' /opt/codedeploy-agent/lib/instance_agent/agent/base.rb:10:inrunner' /opt/codedeploy-agent/lib/instance_agent/runner/child.rb:32:in block in prepare_run' /opt/codedeploy-agent/lib/instance_agent/runner/child.rb:78:inwith_error_handling' /opt/codedeploy-agent/lib/instance_agent/runner/child.rb:31:in prepare_run' /opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:64:inblock in prepare_run_with_error_handling'

Debian GNU/Linus 9.13

alboyadjian commented 1 year ago

I'm getting the same. I believe it's due to the packaged version of aws-sdk-core (3.121.1) and aws-sigv4 (1.5.1)

Running it with aws-sdk-core (3.170.0) and aws-sigv4 (1.5.2) (which happened to be installed under the system ruby gems) it worked just fine.

alboyadjian commented 1 year ago

^^ cc @mwjones-aws

domcneil-vassar commented 1 year ago

@alboyadjian Adam. How do you run it with the 3.170.0 version of aws-sdk-core instead of the 3.121.1 version?

alboyadjian commented 1 year ago

@domcneil-vassar

We were installing another unrelated gem that happened to use the aws-sdk core and that was installed in the system gems directory. By changing the env variables GEM_PATH and GEM_HOME from the aws-codedeploy-agent vendor directory to our system gems directory the agent could be run.

However, as a more stable workaround, what we ended up doing is installing from source from our own fork of the gem that's ruby 3.1 compatible.

Our fork/branch: https://github.com/vhl/aws-codedeploy-agent/tree/ruby3.x

The diff: https://github.com/aws/aws-codedeploy-agent/pull/347/files

We use chef for provisioning, so I can share a snippet of chef code for how to do the install from source. It's designed to match the organization of the files in the .deb package, so there are a couple of extra hoops to jump through to reorganize the gems:

    git '/opt/codedeploy-agent' do
      repository "https://github.com/vhl/aws-codedeploy-agent.git"
      revision 'ruby3.x'
      action :sync
    end

    execute 'copy_codedeploy_gems' do
      action :nothing
      cwd '/opt/codedeploy-agent'
      command "find vendor/ruby/3.1.0/gems/ -maxdepth 1 -mindepth 1 -exec cp -r '{}' vendor/gems \\;"
    end

    execute 'copy_codedeploy_specifications' do
      action :nothing
      cwd '/opt/codedeploy-agent'
      command "find vendor/ruby/3.1.0/specifications/ -maxdepth 1 -mindepth 1 -exec cp -r '{}' vendor/specifications \\;"
    end

    execute 'bundle_codedeploy_agent' do
      action :nothing
      cwd '/opt/codedeploy-agent'
      command 'bundle install --path vendor --without test'
      subscribes :run, 'gem_package[vhl_ruby_bundler]', :immediately
      notifies :run, 'execute[copy_codedeploy_gems]', :immediately
      notifies :run, 'execute[copy_codedeploy_specifications]', :immediately
    end

You will also want to create a systemd unit or initd script like the one that comes in the deb package.