doutuo7126 2019-01-03 17:18
浏览 69
已采纳

在AWS-SDK-GO中使用正则表达式过滤AWS资源

So I have some different types of aws resources tagged as xxx/yyy/<generated_id>. I need to fetch them using go-sdk.

Here is a sample code for subnets, the filters look the same for every other resource.

This doesn't work.

var resp *ec2.DescribeSubnetsOutput
resp, err = d.ec2Client().DescribeSubnets(&ec2.DescribeSubnetsInput{
    Filters: []*ec2.Filter{
        {
            Name:   aws.String("vpc-id"),
            Values: []*string{&d.VpcId},
        },
        {
            Name:   aws.String(fmt.Sprintf(`tag:"xxx/yyy.[*]"`),
            Values: []*string{aws.String("owned")},
        },
    },
})

This does: aws ec2 describe-subnets --filters `Name=tag:"xxx/yyy.[*]",Values=owned`

I'm obviously doing something wrong, can someone point out what?

  • 写回答

1条回答 默认 最新

  • downloadbooks_2014 2019-01-03 17:55
    关注

    There is nothing in the API documentation to suggest that DescribeSubnets accepts a regular expression in filter names: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeSubnets.html

    If it works in the CLI, that's likely something the CLI is doing on top of what the SDK offers. The Go SDK is like any other AWS SDK; it exposes the AWS API in a language-specific way. The AWS CLI adds convenience features on top of the API to make it more useful on the command line, but that doesn't mean those features are exposed by the API or any published SDK.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测