【问题标题】:Read environment properties from Elastic Beanstalk in .ebextensions从 .ebextensions 中的 Elastic Beanstalk 读取环境属性
【发布时间】:2017-08-14 23:20:34
【问题描述】:

我在 Amazon 上的 Elastic Beanstalk 中设置了一些属性及其值。一个例子是:

我有一个 .NET 应用程序,我将在带有 IIS 的 EC2 Windows 服务器上部署它。 .NET 项目包含一个.ebextensions 文件夹,我们在其中包含.config 文件以进行进一步的配置。

现在是我的问题。我是否能够读取属性的值(所以从 .ebextensions 文件夹中的 .config 文件中的属性 DB.Username 中读取“root”?

我尝试了类似的方法,但似乎 Elastic Beanstalk 的属性不是真正的 Windows 环境变量

commands:
  010-01-test:
    command: echo %DB.Username%

我知道我的项目中的web.config 也使用了这些变量。但是从这个文件中获取值对我来说似乎是一个丑陋的解决方案?

【问题讨论】:

  • 在 AWS 中,缩写 EBS 代表 Elastic Block Store,而不是 Elastic Beanstalk。
  • @MarkB 你是对的。我已经编辑了我的问题。

标签: .net iis amazon-elastic-beanstalk windows-server ebextensions


【解决方案1】:

我有类似的问题。我在这里找到了解决方案https://blog.corpinfo.com/how-to-call-and-export-variables-in-elastic-beanstalk

对于 unix,你可以简单地写

commands:
  010-01-test:
    command: echo $(/opt/elasticbeanstalk/bin/get-config environment -k DB.Username)

甚至$(get-config environment -k DB.Username):

我不知道如何在windows中公开这个内联,但应该有办法。

您可以尝试更详细的解决方案

commands:
  010-01-test:
    command: echo %DBUsername%
    env:
      DBUsername: 
        "Fn::GetOptionSetting":
          Namespace: "aws:elasticbeanstalk:application:environment"
          OptionName: DB.Username

【讨论】:

  • 以上需要直接在beantalk的EC2实例上运行吗?我可以以类似于“describe-environments”的方式运行它吗?
  • 如果您需要 CLI,您可以尝试 describe-configuration-settings
  • 这确实有效!对于其他人来说,如果您尝试获取特定值,您可能需要yum install jq。示例:aws elasticbeanstalk describe-configuration-settings --application-name appname --environment-name envname | jq '.ConfigurationSettings[].OptionSettings'| jq '.[] | select(.OptionName=="IMPORTANT_CONFIG_VALUE")'|jq '.Value'
猜你喜欢
  • 2017-05-06
  • 2015-07-20
  • 2021-11-25
  • 2016-02-01
  • 2023-03-26
  • 2017-08-19
  • 1970-01-01
  • 2017-07-21
  • 2018-06-05
相关资源
最近更新 更多