使用 Packer 查询 AWS

Querying AWS using Packer

我正在使用 Packer 查询 AWS 以查找要用作源 AMI 的 AMI。我想通过标签找到 AMI。这是我的代码。

"source_ami_filter": {
  "filters": {
    "tag": "type=Ubuntu Base"
  },
  "owners": ["self"],
  "most_recent": true
}

收到此错误

amazon-ebs: Error querying AMI: InvalidParameterValue: The filter 'Filter.tag' is invalid

我这辈子都想不出如何设置过滤器的格式。任何帮助将不胜感激。

您的示例代码非常接近,但应在过滤器键而不是值中指定标签名称。

您的代码的这种修改应该可以找到带有包含值 "Ubuntu Base":

的 "type" 标签的 AMI
"source_ami_filter": {
  "filters": {
    "tag:type": "Ubuntu Base"
  },
  "owners": ["self"],
  "most_recent": true
}

source_ami_filter 的 Packer 文档解释说 "any filter described in the docs for DescribeImages is valid."

然后 DescribeImages 的 AWS EC2 文档显示,针对给定标签中包含的值的过滤器应使用格式 tag:key=value:

tag:key=value - The key/value combination of a tag assigned to the resource. Specify the key of the tag in the filter name and the value of the tag in the filter value. For example, for the tag Purpose=X, specify tag:Purpose for the filter name and X for the filter value.