将环境变量从appsettings.json添加到AWS C#中

huangapple go评论85阅读模式
英文:

Add environment variables to AWS from appsettings.json C#

问题

在我的C# API项目的appsettings.json文件中,例如,我有以下变量:

"Recursos":{
   "tipoRecurso":"plasticos",
   "ValorRecurso":"2000",
   "TieneExpedicion":"no"
},
"OtherProperty": "some value"

如何将该对象属性添加到AWS的环境中?我不知道这是否正确:

英文:

In the appsettings.json file of my API project in C#, I have this variable for example:

"Recursos":{
   "tipoRecurso":"plasticos",
   "ValorRecurso":"2000",
   "TieneExpedicion":"no"
},
"OtherProperty": "some value"

How to add that object property in the environment of AWS? I don't know if this is correct:

将环境变量从appsettings.json添加到AWS C#中

答案1

得分: 1

You need to address every JSON field as a separate environment variable rather than addressing the object as a string of JSON.

Environment Variable Field Value
Recursos__tipoRecurso plasticos
Recursos__ValorRecurso 2000
Recursos__TieneExpedicion no
OtherProperty some value

Because : can't typically be used as part of an environment variable's name, you have to use double underscore instead, __, to get to the fields of a complex object.

Ankush's comment references this.

Minor note: If Recursos__TieneExpedicion is a boolean, and not a string, you might need to set the field value to false.

英文:

You need to address every JSON field as a separate environment variable rather than addressing the object as a string of JSON.

Environment Variable Field Value
Recursos__tipoRecurso plasticos
Recursos__ValorRecurso 2000
Recursos__TieneExpedicion no
OtherProperty some value

Because : can't typically be used as part of an evironment variable's name, you have to use double underscore instead, __, to get to the fields of a complex object.

Ankush's comment references this.

> Minor note: If Reursos_TieneExpedicion is a boolean, and not a string, you might need to set the field value to false.

huangapple
  • 本文由 发表于 2023年6月29日 00:14:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575009.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定