简体   繁体   English

如何从 S3 存储桶中的 React 应用程序的 .env 文件中读取环境变量?

[英]How do I read environment variables from .env file for a React app from an S3 bucket?

I created environment variables in a .env file for my React project.我在我的 React 项目的.env文件中创建了环境变量。

I have added the.env in my .gitignore file.我在我的.gitignore文件中添加了 the.env。

How do I read these environment variables from my Amazon S3 bucket since my React app is hosted there?由于我的 React 应用程序托管在那里,我该如何从我的 Amazon S3 存储桶中读取这些环境变量?

eg process.env.REACT_APP_MY_VARIABLE例如process.env.REACT_APP_MY_VARIABLE

1 - Make sure your .env file is in the root folder of your project. 1 - 确保您的.env文件位于项目的根文件夹中。 It should be something like:它应该是这样的:

REACT_APP_MY_VARIABLE = 'my-app-var'

2 - Build your project before sending it to S3 and install the dotenv dependency. 2 - 在将项目发送到 S3 之前构建您的项目并安装dotenv依赖项。

npm install dotenv --save

3 - Import the dotenv in your project. 3 - 在您的项目中导入dotenv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从S3 bucket中直接读取图片文件到memory? - How to read image file from S3 bucket directly into memory? 如何创建预签名 URL 以使用 Boto3 从 S3 存储桶下载文件? - How do I create a Presigned URL to download a file from an S3 Bucket using Boto3? 使用 boto3 从 S3 存储桶中读取文件内容 - Read file content from S3 bucket with boto3 Elasticsearch 和 S3 存储桶:如何获取 Python 来检测来自 s3 存储桶的数据是否已经在 elasticsearch 中? - Elasticsearch and S3 bucket: how do I get Python to detect if data from s3 bucket are already in elasticsearch? 如何使用 python 从 S3 存储桶中的文件夹读取文件内容? - How to read content of a file from a folder in S3 bucket using python? 如何使用 Python 中的 Pandas 从 s3 存储桶中读取 csv 文件 - How to read a csv file from an s3 bucket using Pandas in Python 如何从 Amazon S3 存储桶中读取数据并调用 AWS 服务 - How to read from an Amazon S3 Bucket and call AWS services 如何为 s3 存储桶设置允许经过身份验证的用户列出存储桶或从存储桶中获取任何文件的策略 - How can I set a policy for an s3 bucket that allows authenticated users to list the bucket or get any file from the bucket 如何通过 API 从 S3 存储桶下载私有文件 - How to dowload a private file from S3 bucket through API 从 /tmp/ 上传文件到 S3 Bucket - Uploading file to S3 Bucket from /tmp/
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM