dongyi2993 2019-02-14 09:00
浏览 87
已采纳

在构建期间将AWS Parameter Store环境变量导出到PHP?

I have a simple Laravel installation that I am trying to set up to run through a AWS CodePipeline using ECS.

What have I done?

My Codepipeline is set up with a buildspec.yml file, where I have specified that it should use a value from the Parameter Store, like

env:
    parameter-store:
        TEST_STRING: "TEST"

My TEST variable does exist in the Parameter Store and I can get it using the cli.

What do I want to do?

I want my environment variable to be accessible to my Laravel installation, so I can use the Parameter Store to save passwords and usernames for e.g. databases and apis.

What actually happens?

When I try to access the environment variable through php, I'm not getting any value. If I var_dump $_ENV, then I cannot see my TEST_STRING in the given array.

I'm quite sure that the environment variable only exists in the build process, but I cannot figure out how to "transfer" the environment variable from my build process to the deployed code.

Question

What am I missing to make the environment variables from the build process available to the deployed code?

  • 写回答

1条回答 默认 最新

  • duanan1946 2019-02-14 12:54
    关注

    Go to your cluster and the find your Task Definitions for the relevant task you want to add some environment variables to.

    Click to create a new revision of the task you wish to add variables to.

    Under "Container definitions" you have a list of containers on that task. Select the relevant container and a modal will roll from the right of the screen.

    Scroll down a bit and find Environment > Environment Variables. Here you can add environment variables. You can either set a static value (by using "value") or a Parameter Store value (by using "valueFrom").

    Save your new revision and remember to update your service to use the new definition.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?