前提・実現したいこと
Amazon Linux 2 の使用からEnvがexport されないようになり、 Env を exportできず困っております。
実装方法_ドキュメント
https://aws.amazon.com/jp/premiumsupport/knowledge-center/elastic-beanstalk-env-variables-linux2/
.platform/hooks/postdeploy/01_set_env.sh AND .platform/confighooks/postdeploy/01_set_env.sh ----- #!/bin/bash #Create a copy of the environment variable file. cp /opt/elasticbeanstalk/deployment/env /opt/elasticbeanstalk/deployment/custom_env_var #Set permissions to the custom_env_var file so this file can be accessed by any user on the instance. You can restrict permissions based on your requirements. chmod 644 /opt/elasticbeanstalk/deployment/custom_env_var #Remove duplicate files upon deployment. rm -f /opt/elasticbeanstalk/deployment/*.bak # Add the following code to the 'ec2-user' bash profile to avoid manually sourcing the file on the instance. source_cmd="source <(sed -E -n 's/[^#]+/export &/ p' /opt/elasticbeanstalk/deployment/custom_env_var)" bash_profile_path=/home/ec2-user/.bash_profile grep -qxF -- "$source_cmd" "$bash_profile_path" || echo $source_cmd >> $bash_profile_path
chmod +x .platform/hooks/postdeploy/01_set_env.sh chmod +x .platform/confighooks/postdeploy/01_set_env.sh
追加部分1
.platform/hooks/postdeploy/00_myscript.sh
#!/bin/bash echo "myscript start." export $(sudo cat /opt/elasticbeanstalk/deployment/env | xargs) echo "myscript finish."
追加部分2
.ebextensions/env.config
"/usr/local/bin/myscript.sh": mode: "000755" owner: root group: root content: | #!/bin/bash echo "myscript start." export $(sudo cat /opt/elasticbeanstalk/deployment/env | xargs) echo "myscript finish."
試したこと
サーバーないで直接 export $(sudo cat /opt/elasticbeanstalk/deployment/env | xargs)
を実行すれば問題なく動くのですが、config,shで実行するとうまく動作しません。
ご教授お願いいたします。
あなたの回答
tips
プレビュー