Aws-cli: Cloudformation 外部参数文件不支持 YAML 文件

创建于 2016-11-03  ·  143评论  ·  资料来源: aws/aws-cli

我使用 aws-cli 更新我的堆栈,并希望使用外部 yaml 文件 (dev.yaml) 作为参数文件,如下所示:

aws cloudformation update-stack --stack-name test --template-body file://./api-test.yaml --parameters file://./dev.yaml

dev.yaml中,它只有:

---
- ParameterKey: APICacheClusterSize
  ParameterValue: '1.6'

但是,当我运行上面的更新命令时,我收到了这个错误消息:

Error parsing parameter '--parameters': Expected: '=', received: '-' for input:

---
- ParameterKey: APICacheClusterSize
^
  ParameterValue: '1.6'

如果我使用具有与以下相同上下文的 JSON 文件,并使用它而不是dev.yaml ,它可以正常工作:

[
  {
    "ParameterKey": "APICacheClusterSize",
    "ParameterValue": "1.6"
  }
]

那么,aws cloudformation 的外部参数文件可以是 YAML 文件吗? 还是会……?

feature-request

最有用的评论

我将支持此功能请求。

所有143条评论

您好,我们目前没有任何计划支持 YAML 作为命令行参数的一部分。 我会将其标记为功能请求,因为我可以看到它对某些人可能有用。

您提供给 --parameters 的文件的内容被加载并直接作为参数转储,因此您只能将文件内容采用以下两种格式之一:
简写语法:
ParameterKey=string,ParameterValue=string,UsePreviousValue=boolean
或 JSON 语法:

[
    {
         "ParameterKey": "string",
         "ParameterValue": "string",
         "UsePreviousValue": true|false
     }
]

我将支持此功能请求。

我也会附和

+1

请。 这对我们来说至关重要。

+1

绝对+1

+1 允许--template-body的 YAML 格式数据但不允许--parameters的数据很尴尬

👍

+1

+1

+1

因为你可以在 yaml 中提供模板,所以你应该也可以在 yaml 中提供参数
我认为这个功能是必须的

+1

+100

+1

+100

+1

" https://gist.github.com/mbailey/2f7c878eed123cab6fb125117f35aecc
"
" yamlise - 在 vi​​m 中编辑 JSON 文件时请参阅 YAML。
"
" 为有 JSON 恐惧症的人创建,这应该
" 仅在所有尝试掌握 JSON 时使用
"失败了。http://www.json.org/
"
“我希望这些人还为时不晚!
“‘求你了。这对我们来说很重要。’
" https://github.com/aws/aws-cli/issues/2275#issuecomment -277829948
"
“ 安装
" ============
" 1. 安装cfn-flip https://github.com/awslabs/aws-cfn-template-flip
" 2. 在你的 ~/.vimrc 中包含这个文件
" 3. vim cloudformation-params.json
“你现在应该看到你渴望的 YAML
" 4. :wq
" 该文件现在应包含 Amazon CLI 预期的 JSON
"
:augroup yamlise
: 自动命令!
: autocmd BufReadPost,FileReadPost *.json '[,']!cfn-flip
: autocmd BufWritePre,FileWritePre *.json '[,']!cfn-flip
: autocmd FileAppendPre *.json '[,']!cfn-flip
:augroup 结束

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

+999

+1

+1

+1

+1

+2

+1

+1

+1

+1

+1

+1

+1

+10000000

+1

+信息

+1

+1

+1

+1

+1

这是使用Bash 进程替换cfn-flip的简单解决方法:
aws cloudformation ... --parameters file://<(cfn-flip parameters.yml)

+1

+1

++

+0.5

+1

++

+1!

不明白为什么要在 YAML 中使用模板,然后在 JSON 中使用参数。 似乎是一个奇怪的遗漏,我希望 AWS 正在努力……拜托?

+1

+1

早上好!

我们将在 GitHub 上关闭此问题,作为我们迁移到UserVoice以处理涉及 AWS CLI 的功能请求的一部分。

这将使我们能够更轻松地搜索和显示对您最关心的功能的支持,从而为您提供最重要的功能,而不会因错误报告而淡化对话。

作为 UserVoice 快速入门(如果还不熟悉):发布想法后,人们可以对想法进行投票,产品团队将直接响应最受欢迎的建议。

我们已从 GitHub 导入现有功能请求 - 在那里搜索此问题!

不用担心,为了后代,这个问题仍然存在于 GitHub 上。 由于它是原始帖子到 UserVoice 的纯文本导入,我们仍然会记住 GitHub 问题上已经存在的评论和讨论。

GitHub 仍将是报告错误的渠道。

再次,现在可以通过在以下位置搜索标题找到此问题: https ://aws.uservoice.com/forums/598381-aws-command-line-interface

-AWS 开发工具包和工具团队

此条目可以在 UserVoice 上特别找到: https ://aws.uservoice.com/forums/598381-aws-command-line-interface/suggestions/33168310-cloudformation-external-parameter-file-do-not-supp

+1

根据社区反馈,我们决定将功能请求返回给 GitHub 问题。

+1

+1

+1

+100

+1

+1

+1

+1
和 +1000 以提高整体一致性;)

+1

这个问题是2岁;_;

@matthewflannery不,实际上只有 587 天。

+1

@Yaowenjie 587/365 = 1.608 ~ 2 years

+1

更多 11!1!1one!!1!11

:+1:

:heavy_plus_sign: :100:

👍

+1

距离本期二周年庆典还有两个月,各位! 👨‍👩‍👧‍👦🎉🎉🎊🎊👨‍👨‍👧‍👦

因为我的团队习惯于 YAML(我们所有的模板都在 YAML 中),所以我有一些 shell 自动化,可以将 YAML 文件转换为 json 文件,然后将其传递给 CF。 这表明(至少对我而言)这个功能是多么需要 - 让客户围绕这样的基本功能构建自己的自动化并不是一个答案。

此外,我们应该注意,CloudFormation 的整个 parametersKey/ParamaterValue 工作方式是愚蠢的。

我们可以在 YAML 中使用 CloudFormation 模板并在 JSON 中提供参数文件吗?

@Yashswarnkar是的-您可以使用 YAML 中的模板和 JSON 中的参数。 这个问题是因为参数只能是 JSON - 尽管模板在 YAML 中,但不支持 YAML 文件。

+1 真的希望能够向我的参数文件添加注释并从 CLI 运行它们。 是否计划使用 --parameters 为 create-stack CLI 命令添加 .yaml 支持以支持 yaml?

此功能的任何预计到达时间?

+1

差不多 2 年了,仍然没有参数的 yaml ...... :(

+1

+1

+1

随着 SSM 现在可以使用安全字符串和解码它们的方法,我正在考虑运行脚本将变量放入 AWS 帐户,然后从 cloudformation 模板中引用它们......任何人都有其他想法,例如这样?

根据上面的评论,您可以使用cfn-flip
https://github.com/awslabs/aws-cfn-template-flip

在 bash - 将 parameters.yaml 显示为带有 <( ) 运算符的 json 文件

pip install cfn_flip

cat <(cfn-flip parameters.yaml)

在 cli 命令中与 <( ) 一起使用

aws cloudformation update-stack --stack-name test --template-body file://./api-test.yaml --parameters file://<(cfn-flip parameters.yaml)

+100

这显然是一个需求量很大的功能——为什么尽管看起来有数百人在请求它,但它却没有任何进展?

+1
真正的用例是必须在参数中指定 JSON,在这种情况下 JSON 是一场噩梦,必须转义引号......

[
    {
        "ParameterKey": "DistributionJSON",
        "ParameterValue": "{\"Account_ID_1\":\"region_1,region_2\",\"Account_ID_2\":\"region_1\"}"
    }
]

相比:

- ParameterKey: DistributionJSON
  ParameterValue: '{"Account_ID_1":"region_1,region_2","Account_ID_2":"region_1"}'

好吧? 没有更多更新了吗?

好吧? 没有更多更新了吗?

冷静点,才2019年1月

嘿,这些家伙是如何合并 PR 的?

如果我知道团队定期合并来自其组织外部的 PR,我会考虑写这篇文章。

不知道。 我认为对此有足够的需求,他们最终会实施。

这也许应该永远保持开放,参与其中的每个人都可以成为朋友,并且每年都有一个名为“Paymeter Fam”(如 yaml 参数 fam)的会议,我们大家聚在一起讨论我们的反 yaml 创伤。

+1

👍

+1

+1

3 年,90% 的 API 使用 YAML,很多烦人的 +1 和 AWS 挠头......

我真的很希望 yaml 只是为配置文件/取消注释项目/等使用注释

+1

现在是 2019 年 6 月,我不明白为什么 AWS 仍然没有解决这个问题。 他们每年招聘这么多人

来真的吗? 让我们动起来

+1

+1

+1

+1

+1

+1

+1

等……等……

还在等待!

参数仍然只有 Json 吗?

这个问题已经足够大,可以开始学前班了。

如果有人想就这个问题联系起来并与 Jeff Barr 等人谈废话,我将参加 re:Invent 2019。 人在推特上。

这会很可爱

+1

+1

+1

+1
刚碰到这块石头,请问我可以获得 YAML 参数支持吗?
我目前的项目喜欢 YAML(我不是:))

能否请您也添加 XML 支持? 我不能通过 SOAP 提交这个。 AWS 支持在 Windows 窗体中是必不可少的。

+1

+1

+1

任何更新 :/ ?

+1

+1
我希望能够通过拆分 cloudformation 可升级参数和不可升级参数来在我的参数文件中进行评论。
例如。 我尝试升级我的卷的快照 ID。
-> AutoEnableIO、类型、大小和 IOPS 以外的卷属性无法更新。 将属性更改回以前的值并再次更新堆栈。

试图使用以下命令创建堆栈: aws cloudformation create-stack --stack-name myfirsttest --region us-west-2 --template-body file://testcfn.yml
但收到以下错误消息:
解析参数“--template-body”时出错:无法加载参数文件文件://testcfn.yml :[Errno 2] 没有这样的文件或目录:“testcfn.yml”

我的 testcfn.yml 文件如下:
Description: > Vritika / Udacity project This template deploys a VPC Resources: UdacityVPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 EnableDnsHostnames: true

› aws ssm get-parameters-by-path help                                                                               

# ...

SYNOPSIS
            get-parameters-by-path
          --path <value>
          [--recursive | --no-recursive]
          [--parameter-filters <value>]
          [--with-decryption | --no-with-decryption]
          [--cli-input-json | --cli-input-yaml]
          [--starting-token <value>]
          [--page-size <value>]
          [--max-items <value>]
          [--generate-cli-skeleton <value>]
          [--cli-auto-prompt <value>]

# ...

       --generate-cli-skeleton  (string)  Prints  a  JSON skeleton to standard
       output without sending an API request. If provided with no value or the
       value input, prints a sample input JSON that can be used as an argument
       for --cli-input-json. Similarly, if provided yaml-input it will print a
       sample  input  YAML that can be used with --cli-input-yaml. If provided
       with the value output, it validates the command inputs  and  returns  a
       sample output JSON for that command.

耶,支持yaml!!!

› aws ssm get-parameters-by-path --path "/foo/bar/" --recursive --generate-cli-skeleton yaml-input
Path: ''  # [REQUIRED] The hierarchy for the parameter.
Recursive: true # Retrieve all parameters within a hierarchy.
ParameterFilters: # Filters to limit the request results.
- Key: ''  # [REQUIRED] The name of the filter.
  Option: '' # For all filters used with DescribeParameters, valid options include Equals and BeginsWith.
  Values: # The value you want to search for.
  - ''
WithDecryption: true # Retrieve all parameters in a hierarchy with their value decrypted.
MaxResults: 0 # The maximum number of items to return for this call.
NextToken: '' # A token to start the list.

这还不是一回事吗?? 还是我错过了它在某个地方?

对于有兴趣在其参数中使用 .yaml 的任何人,请参阅此
https://github.com/realestate-com-au/stackup

我认为 AWS 应该敲门购买此代码并将其移动到他们的 IP 中......

+1

不喜欢用 hacky 方法解决问题,因为 hacky 很快就会变得一团糟。
但是对于任何有兴趣在他们的测试环境中使用 params 文件执行此操作的人。

s3template.yml

AWSTemplateFormatVersion: '2010-09-09'
Description: create a single S3 bucket
Parameters: 
  BucketName:
    Description: Unique name for bucket.
    Type: String
  AccessControl:
    Description: Access Control of the bucket
    Type: String
    AllowedValues:
      - Private
      - PublicRead

Resources:
  SampleBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref BucketName
      AccessControl: !Ref AccessControl

s3template.params

BucketName=sample-unique-bucket-123456
AccessControl=Private

跑步 :
aws cloudformation deploy --template-file ./s3template.yml --stack-name sample-testbucket --region us-east-1 --parameter-overrides $(cat s3template.params)

+1 用于 YAML 形式的参数文件。 为什么要强迫某人混合标记?

此页面是否有帮助?
0 / 5 - 0 等级