Skip to content

dekokun/json2env

Repository files navigation

json2env

Test Status Coverage Status MIT License GoDoc

json2env execute commands with environment variables made from JSON.

Click here for an explanation in Japanese : https://dekotech.dekokun.info/entry/2020/10/04/162635

Synopsis

$ export SECRETS='{"key":"value"}'; json2env --envname SECRETS --keys "key" /path/to/command [...]
$ export VARS='{"examplekey1":"value1", "examplekey2":"value2", "examplekey3":"value3"}'; json2env --keys "examplekey1,examplekey2" --envname VARS env | grep examplekey
examplekey1=value1
examplekey2=value2

Motivation

I wanted to pass secret information as an environment variable to the ECS container in Fargate via the Secrets Manager, but I was unable to retrieve some data by specifying a key in the JSON of the Secrets Manager as shown below. Of course, you can get the entire JSON as an environment variable.

Since this feature is implemented in ECS on EC2, this feature will probably be implemented in Fargate in the future, so I wanted something to convert JSON to environment variables that can be used in the meantime.

And I made it mandatory to specify the name of the environment variable to use so that I can safely remove this tool when I no longer use it.

Installation

$ go install github.com/dekokun/json2env/cmd/json2env

Author

dekokun