Skip to content

SSM not applying ENV in rails console #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
christianbradley opened this issue Oct 30, 2019 · 4 comments
Closed

SSM not applying ENV in rails console #13

christianbradley opened this issue Oct 30, 2019 · 4 comments

Comments

@christianbradley
Copy link

Running latest Rails (6.x)

If I run rails console, the ENV vars are not applied from SSM. Seems to load OK when running rails server.

Here's my application.rb (first lines)

require_relative 'boot'

require "rails"
require 'psenv-rails'
@atomaka
Copy link
Owner

atomaka commented Nov 6, 2019

I'm having trouble replicating this:

|-> PARAMETER_STORE_PATH=/psenv/test/ bundle exec rails console
Loading development environment (Rails 6.0.0)
irb(main):001:0> ENV['API_KEY']
=> "api_key_value"

It might be an issue with require order. I am testing using the sample app in https://github.com/atomaka/psenv/tree/master/spec/rails which does not explicitly load the psenv-rails gem and instead relies on bundler to do it.

@atomaka
Copy link
Owner

atomaka commented Nov 6, 2019

@christianbradley Any chance you're using the spring application preloader? I have seen this issue with the spring gem:

|-> bundle exec rails console
Running via Spring preloader in process 91069
Loading development environment (Rails 6.0.0)
irb(main):001:0> ENV.fetch('API_KEY') # not here since PARAMETER_STORE_PATH not provided
Traceback (most recent call last):
        2: from (irb):1
        1: from (irb):1:in `fetch'
KeyError (key not found: "API_KEY")
irb(main):002:0> exit
|-> PARAMETER_STORE_PATH=/psenv/test/ bundle exec rails console
Running via Spring preloader in process 91126
Loading development environment (Rails 6.0.0)
irb(main):001:0> ENV.fetch('API_KEY') # expected to be found, but isn't
Traceback (most recent call last):
        2: from (irb):1
        1: from (irb):1:in `fetch'
KeyError (key not found: "API_KEY")
irb(main):002:0> exit
|-> bundle exec spring stop
Spring stopped.
[09:29:39] [email protected] ~/Source/psenv/spec/rails [master]
|-> PARAMETER_STORE_PATH=/psenv/test/ bundle exec rails console
Running via Spring preloader in process 91269
Loading development environment (Rails 6.0.0)
irb(main):001:0> ENV.fetch('API_KEY') # now available since we restarted spring
=> "api_key_value"

@atomaka
Copy link
Owner

atomaka commented Nov 6, 2019

rails/spring#420 and rails/spring#490 appear to be relevant but unresolved issues.

Can you try using bundle exec spring stop and then loading the console (making sure to load PARAMETER_STORE_PATH before running any rails command either inline with the command or via export?

@atomaka
Copy link
Owner

atomaka commented Nov 14, 2019

Feel free to pop a comment in here if the suggested fix doesn't fix anything for you!

@atomaka atomaka closed this as completed Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants