2

I have code that takes in a local test.env.json that is injected into the start of the test.

However, now that I am running it through codebuild and using secrets manager, if I don't have a test.env.json file then it will not run correctly.

So far I was able to set up the env variables in the buildspec file correctly but I need to send them to a test.env.json file in the commands.

How do I do this?

version: 0.2
phases:
  install:
    runtime-versions:
      nodejs: latest
    commands:
      - npm install
  pre_build:
    commands:
      - SECRET="$(aws secretsmanager get-secret-value --secret-id arn:aws:secretsmanager:{secret} | jq '.SecretString | fromjson')"
  build:
    commands:
      - echo $SECRET.   (outputs the correct JSON body)
      - need to send $SECRET to a file called `test.env.json` before npm run
      - npm run test:run
Steve
  • 197
  • 7
  • 17
  • I think it can work, you can also use environment variables directly with ```env: secrets-manager or parameter-store``` (https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.secrets-manager) – Franxi Hidro Jul 10 '22 at 19:10
  • You can always do `echo $SECRET > test.env.json`, but what @FranxiHidro said is the good practice. – palvarez Jul 11 '22 at 16:45

0 Answers0