Pass variable to .env file at Elastic Beanstalk for dockerized Reactjs app

0

Hi,

I have React app running at EB with docker and nginx. I have .env like REACT_APP_API_BASE_URL=${ADMIN_BACKEND_API} REACT_APP_SIGNUP_ENDPOINT=$REACT_APP_API_BASE_URL/api/v1/auth/signup

Also my Dockerfile is: `FROM node:17.1-alpine as build-stage WORKDIR /app COPY package*.json ./ RUN npm install COPY . .

RUN npm run build:production

FROM nginx:1.22.1-alpine as prod-stage COPY --from=build-stage /app/build /usr/share/nginx/html COPY --from=build-stage /app/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]`

I confgured ADMIN_BACKEND_API at AWS Beanstalk console. I assume it will be passed to .env and sibstitute REACT_APP_API_BASE_URL=${ADMIN_BACKEND_API} when I run eb deploy, but it does not. How can I do that?

Kirill
asked 7 months ago238 views
1 Answer
1
Accepted Answer

Hello, hope you are doing good. In case of using ElasticBeanstalk Docker platform it is suggested to pass your environment variables for containers either via .env file or if you are using docker-compose.yml file then you can define the environment variables in the docker-compose file. If you are using the Docker Compose tool on the Amazon Linux 2 Docker platform, Elastic Beanstalk generates a Docker Compose environment file called .env in the root directory of your application project. This file stores the environment variables you configured for Elastic Beanstalk.If you include a .env file in your application bundle, Elastic Beanstalk will not generate an .env file. For more information, check out this documentation : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html#docker-env-cfg.env-variables

Now you can consider using either of these two scenarios(defining env variables in docker-compose or using the .env file in your source bundle) to get the environment variables and retrieve environment variables from the .env file. One way to get environment variables defined in .env file is mentioned here : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html#docker-env-cfg.env-variables

AWS
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions