Codebuild: How to send JSON body to a ENV file in buildspec?

Viewed 97

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
0 Answers
Related