Injecting runtime environment variables for a React App #2001
-
Hi, I tried to add Environment Variables without any success. I'm using React in the frontend.
I don't get the value in my code injected. I don't understand how I get the env's in my Docker-Image. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @vonphlpp ! The steps that you have taken look good to me, the only difference that I see between the docs and above is the When you open up the console do you see the environment variables available under the containers tab? I believe the reason why this is happening is that your React application expects the environment variables at "build-time" (while building the docker image), whereas Copilot passes down these variables at runtime (running your built image). I believe you'd need to wrap your React service around an API like with Express.js. The explanation under "Runtime variables" in this blog post (https://medium.com/@adostes/using-environment-variables-in-a-react-application-ac3b6c307373) should apply to your service as well. |
Beta Was this translation helpful? Give feedback.
Hi @vonphlpp !
The steps that you have taken look good to me, the only difference that I see between the docs and above is the
type
of the SSM parameter:String
instead ofSecureString
.When you open up the console do you see the environment variables available under the containers tab?
I believe the reason why this is happening is that your React application expects the environment variables at "build-time" (while building the docker image), whereas Copilot passes down these variables at runtime (running your built image). I believe you'd need to wrap your React service around an API like with Express.js. The explanation under "Runtime variables" in this blog post (https://medium.com/@a…