- Le plus récent
- Le plus de votes
- La plupart des commentaires
Hi,
I couldn't find the attachment anywhere in this page.
The environment variables you defined in the buildspec will override what you defined in the project environment configuration (environment tab in console) if they have the same name. The recommend way is to use either ParameterStore or SecretsManager to store your secrets and specify that in the buildspec. Documentation for how to use these in the buildspec:
https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#parameter-store-build-spec
https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#secrets-manager-build-spec
Regards,
Kaixiang
Edited by: Kaixiang-AWS on May 21, 2020 2:32 PM
@Kaixiang-AWS
Thanks for the reply and the reference. I've attached the screenshots where the environment tab that i'm referring to.
-
But just to let you know that REACT_APP_CONTENTFUL_TOKEN down below is the environment variable I use it for the front end to access via process.env.REACT_APP_CONTENTFUL_TOKEN and the
CONTENTFUL_TOKEN down below is what is defined in the project environment variables in the aws console. And so both are different. -
Secondly based on the example below I've defined the project environment variable in aws console as CONTENTFUL_TOKEN as "123#$$" in plain text and I provided the reference in the buildspec.yml as mentioned below. And when I try to access process.env.REACT_APP_CONTENTFUL_TOKEN, my expectation is it should show "123#$$". But rather It is showing as string "${CONTENTFUL_TOKEN}". The main question here is how do I access the environment variables defined in the project environment console, so it can be accessed on the front end in react.
-
The above question applies for parameter store as well
env:
variables:
REACT_APP_CONTENTFUL_TOKEN: ${CONTENTFUL_TOKEN} //
...
Kindly advise
Regards,
Bt
Hi,
The environment variable section in buildspec doesn't allow evaluating a variable. The recommend way for your use case would be
- Directly specify REACT_APP_CONTENTFUL_TOKEN in the environment tab or in buildspec. I don't see a reason why you need an intermediate CONTENTFUL_TOKEN variable. An example in the buildspec would be
env:
variables:
REACT_APP_CONTENTFUL_TOKEN: "123#$$"
- You can keep what you did for CONTENTFUL_TOKEN and assign its value to REACT_APP_CONTENTFUL_TOKEN in install phase. An example would be
phases:
install:
commands:
- REACT_APP_CONTENTFUL_TOKEN=$CONTENTFUL_TOKEN
Hope this could solve your issue.
Regards,
Kaixiang
@Kaixiang-AWS
Thanks for your reply. My use case was to get the token or secret_key from process.env.token from the react front end, so I can make API calls. Also the reason why I don't want to specify the token or secret key directly in the builspec.yml is, I don't want to expose this in my commit in the repo. But I found export the variables like the following does the job.
phases:
install:
commands:
- export REACT_APP_CONTENTFUL_TOKEN=${CONTENTFUL_TOKEN}
I found that variables in the build command phase can be exported in order to access it outside (i.e,, from the front end via process.env.somethingimportant) provided the environment variables are defined in the proeject environment variables console
Contenus pertinents
- demandé il y a un an
- demandé il y a 2 ans
- demandé il y a 3 mois
- demandé il y a un an
- AWS OFFICIELA mis à jour il y a 6 mois
- AWS OFFICIELA mis à jour il y a 2 ans
- AWS OFFICIELA mis à jour il y a 2 ans