简体   繁体   English

AWS iam 和 JQ 过滤角色的问题

[英]Problem with AWS iam and JQ filtering roles

I'm trying to make a simple filtering script using AWS cli + jq (powershell or cmd in Windows).我正在尝试使用 AWS cli + jq(Windows 中的 powershell 或 cmd)制作一个简单的过滤脚本。

aws iam list-roles | jq -c '.Roles[].RoleName | select(startswith ("blabla"))'

But getting this error:但是得到这个错误:

jq: error: AD_/0 is not defined at <top-level>, line 1:
.Roles[].RoleName | select(startswith (AD_))
jq: 1 compile error

But using jqplay.org with same JSON everything works well.但是使用具有相同 JSON 的 jqplay.org 一切正常。 Any thoughts?有什么想法吗?

thanks!谢谢!

aws iam list-roles | aws iam 角色列表 | jq -c '.Roles[].RoleName | jq -c '.Roles[].角色名 | select(startswith ("blabla"))'选择(开始于(“blabla”))'

blabla_rolename_1 blabla_rolename_1

It looks like you might be missing a string after the startswith function.看起来您可能在startswith函数之后缺少一个字符串。 Try adding a string in quotes after startswith:尝试在startswith:

aws iam list-roles | jq -c '.Roles[].RoleName | select(startswith("blabla"))'

If you still get an error, you can try running the jq command without the -c flag to see the full output from jq , which might give you more information about the error.如果仍然出现错误,您可以尝试运行不带-c标志的jq命令以查看jq的完整输出,这可能会为您提供有关该错误的更多信息。

aws iam list-roles | jq '.Roles[].RoleName | select(startswith("blabla"))

AFAIK Powershell does not support single quotes. AFAIK Powershell 不支持单引号。 Use double quotes and escaped double quotes instead:改用双引号和转义双引号:

aws iam list-roles | jq -c ".Roles[].RoleName | select(startswith (\"blabla\"))"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM