其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

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

GG网络技术分享 2025-03-18 16:15 30


问题描述:

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?

网友观点:

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.

如何使用Amazon Rekognition从Ruby中检测图像内容?


Rekognition是一种新的亚马逊网络服务,"它能使您可以轻松地将图像分析添加到应用程序中"。同时,Rekognition可以检测脸部和对象,甚至可以设置面部储存库以供将来识别。

如果您曾经使用过Ruby的AWS服务,那么就可以直接进行简单的图像重新识别(sic)。

使用AWS账号创建.env文件

AWS_REGION=us-east-1

AWS_ACCESS_KEY_ID=[put that key here]

AWS_SECRET_ACCESS_KEY=[and the other one here]

与其他服务一样,需要先申请AWS账号。(为了提高安全性,仅限于使用IAM创建Rekognition账号。)但请注意,它目前仅在美国西部,美国东部和欧盟爱尔兰地区可用。

创建Gemfile以获取一个简单project



将dotenv gem存入.env file作为程序的环境变量。aws-sdk gem是AWS的亚马逊官方Ruby SDK.版本

 编写一个Ruby程序来查询Amazon Rekognition



首先,载入我们数据,然后存入从env是环境变量中,AWS SDK将自动识别你的身份。

接下来,创建一个客户端对象,并使用detect_labels方法(是的,其实就是Rekognition的DetectLabels方法)通过第一个命令行参数(ARGV.first)将名称传入致文件的原始数据

最后,我们需要输入返回的标签和置信度。

做一些检测

如果上述文件形式为detect.rb,你可以这样运行:

ruby detect.rb myimage.jpg

myimage.jpg看起来像是这样:



上述Ruby脚本可以像这样输出:

Freeway-64

Road-64

Dirt Road-63

Gravel-63

Asphalt-56

Tarmac-56

Intersection-55

检测到的标签在左侧,检测算法的置信度百分比在右侧。

玩得开心,但要记得每1000张图片亚马逊会收取1美元,当然你如果是会员就不用担心了。

 在你无聊时产生的天马行空的想法能做的事

· 浏览Twitter / Instagram上的图片,检测其中的内容,然后使用检测到的标签自动回复,例如"I love [label]!"或"Oh wow your [label] is [superlative]!",甚至你还可以让Twitter/Instagram比它们现在更糟,不过你会得到更多的关注者。

· 留意任何的图片资源,并选择所有具有高信度的 "cats"和"pizza"。然后创建一个Facebook帐户或电子邮件通讯,只发布那些接近比萨的猫的照片。

· 这种detect_labels方法返回图像的方向是否正确必须进行检测并纠正,所以你可以把它作为一个昂贵的图像定位检测方式。

· 浏览你的使用者具体上传资料,别让闲杂人等使用这款app,因为他们很难识别统一化。

· 使用网络摄像头加以及数字门锁,并且在摄像头关注你孩子的时候能自动解锁。当然,有时候这可能会失效,但是,你的孩子会发现在户外睡觉会更加刺激。

· 像面部检测识这样不道德的事,我当然没做。我相信亚马逊建议在"digital billboards'"中使用的通过人们走动来识别人物信息的技术肯定会发挥积极的效果。

如想学习更多软件测试文章,请前往51Testing软件测试网-中国软件测试人的精神家园。

标签:

提交需求或反馈

Demand feedback