9

Hi React experts (especially with CI/CD knowledge),

Please read this carefully and provide a possible solution.

Background:

  • I have created a react app using 'create-react-app'
  • I have created 3 .env files for different environments - .env.development, .env.staging and .env.production.
  • For security reasons, we should not push those .env files to public Github repo
  • I have taken the necessary steps with the .gitignore file

Now I want to deploy my code from Github directly to AWS S3 bucket with those env variables set.

How does one go about doing this?

Note: I have not pushed my .env files to Github. So, my Github repo doesn't contain those .env files.

1

1 Answer 1

5

According to here. We can't set environment variables in S3. S3 is just a static object store, not a dynamic content server.

According to react documentation all the environment variables in the runtime are set to final build (inside build folder) after executing npm run build. when building React app all the secret variables in the .env file are in the runtime environment and after finishing npm run build those environment variables(secret variables) are added to the build folder (final app).

Because S3 is not a runtime environment we need to build a react app and upload the build folder to the S3 bucket after creating a bucket or we can provide that environment variables using GitHub action.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.