AWS OpsWorks Environment variables not working

前端 未结 3 2074
面向向阳花
面向向阳花 2020-12-15 11:14

I am running Ubuntu 14.04 LTS 64 bit Rails Application and I am unable to access my App environment variables.

In OpsWorks App panel, I set my environment variables,

3条回答
  •  甜味超标
    2020-12-15 12:09

    I (with some help from Bruno at the AWS PopUp Loft in NYC) added some custom Chef code inside the after_restart.rb deploy hook, simply add the folder "deploy" to your apps root directory and inside add "after_restart.eb." In it ....

    Chef::Log.info("Running deploy/after_restart.rb")
    
    contents = []
    
    node[:deploy].each do |application, deploy|
      deploy[:environment_variables].each do |key, value|
        contents << "export #{key}=\"'#{value}'\""
      end
    end
    
    
    Chef::Log.info("Adding the environment variables to /etc/profile.d/startup_env_config.sh")
    
    bash "create_startup_env_config.sh" do
      user "root"
      cwd  "/etc/profile.d"
      code <<-EOH
        echo \''#{contents.join(" ")}\'' > startup_env_config.sh
        source startup_env_config.sh
        cd #{release_path}
    
        EOH
      end
    

    And that's it. If you update the environment variables inside the OpsWorks panel remember to restart your instances.

提交回复
热议问题