I'm trying to use the AWS SecretsManager SDK in Ruby and I'm getting the following error:
.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/aws-sdk-core-3.186.0/lib/aws-sdk-core/ini_parser.rb:28:in `block in ini_parse': undefined method `[]' for nil:NilClass (NoMethodError)
if current_prefix.nil? && previous_item[2].strip.empty?
The code is the standard suggested by AWS when you upload secrets into the secrets manager:
require 'aws-sdk-secretsmanager'
# Retrieves secrets from AWS Secrets Manager
module SecretsManager
def aws_secret(secret)
client = Aws::SecretsManager::Client.new(region: 'eu-central-1')
begin
get_secret_value_response = client.get_secret_value(secret_id: secret)
rescue StandardError => e
raise e
end
get_secret_value_response.secret_string
end
def secrets
secrets ||= aws_secret('test')
JSON.parse(secrets)
end
end
My guess is the SDK is failing trying to parse the ~/.aws/config
file but there is nothing wrong with that file as far as I can tell and I can log in into AWS and use the SecretsManager with CLI to retrieve secrets successfully.
Any ideas? Thanks!
I managed to reproduce the issue on my machine.
This was the
~/.aws/config
that made the error happen. Notice the empty line betweenaws_access_key_id
andaws_secret_access_key
and the spaces just before theaws_secret_access_key
.By removing the empty line and unnecessary spaces, the SDK could parse my configuration without issue.