简体   繁体   English

使用 AWS EC2 查询 API

[英]Using the AWS EC2 Query API

I am currently writing an interface layer to the AWS EC2 Query API, and I was having a relative degree of success until I started digging deeper into its features.我目前正在为 AWS EC2 查询 API 编写一个接口层,在我开始深入研究它的功能之前,我取得了一定程度的成功。

I can run the following query request with no problems:我可以毫无问题地运行以下查询请求:

?Action=DescribeInstances&DryRun=False&MaxResults=1000&Version=2016-11-15

However, when I start using Filters on the DescribeInstances action, I run into unexplanable errors.但是,当我开始对DescribeInstances操作使用过滤器时,我遇到了无法解释的错误。

Howver this query, which uses the ip-address filter describe here : ?Action=DescribeInstances&DryRun=False&Filter.1.Name=ip%2Daddress&Filter.1.Value=52%2E204%2E71%2E190&MaxResults=1000& Version=2016-11-15然而,这个使用 ip-address 过滤器的查询在这里描述: ?Action=DescribeInstances&DryRun=False&Filter.1.Name=ip%2Daddress&Filter.1.Value=52%2E204%2E71%2E190&MaxResults=1000& Version=2016-11-15

Thanks in advance.提前致谢。 ..:will result in the following error: ..:将导致以下错误:

AWS was not able to validate the provided access credentials (AuthFailure) AWS 无法验证提供的访问凭证 (AuthFailure)

Can someone give me pointers on where I am going wrong?有人可以指点我哪里出错了吗?

UPDATE : To reiterate, I suspect that this error message is a red herring.更新:重申一下,我怀疑这个错误消息是一个红鲱鱼。 I have tried both of the above queries on an EC2 Image with the Administrator IAM role attached, and I still get the same behavior.我已经在附加了管理员 IAM 角色的 EC2 映像上尝试了上述两个查询,但我仍然得到相同的行为。 So unless there is a good reason to suspect a traditional AuthFailure, ask yourselves why an Adminisrator can access the DescribeImages action without issue, but causes an AuthFailure when a Filter is added.因此,除非有充分的理由怀疑传统的AuthFailure ,否则问问自己为什么管理员可以毫无问题地访问 DescribeImages 操作,但在添加过滤器时会导致 AuthFailure。 I hope this is due to my use of said Filters and that its my implementation that is at issue.我希望这是由于我使用了上述过滤器,并且我的实现存在问题。 Thanks.谢谢。

UPDATE2 : While a few responses have been helpful, this question still has not yet been answered to my satisfaction. UPDATE2 :虽然一些回答很有帮助,但这个问题仍未得到令我满意的回答。

UPDATE3 : It looks like Amazon has fixed this issue on its own.更新3 :亚马逊似乎已经自行解决了这个问题。

In your URL-encoded request, there seems to be a space in '& Version...' .在您的 URL 编码请求中, '& Version...'中似乎有一个空格。

Back to the larger picture, perhaps you should consider running awscli from your code (in a subprocess), rather than trying to make your own requests and sign them yourself?回到更大的图景,也许您应该考虑从您的代码(在子进程中)运行awscli ,而不是尝试提出自己的请求并自己签名?

Also, awscli itself is really quite handy (and complete).此外,awscli 本身确实非常方便(而且完整)。 For starters, it helps formulate the request and quickly see what gets returned.对于初学者来说,它有助于制定请求并快速查看返回的内容。

Also, you can use it with --debug to observe (among other things) the request and the response sent over the wire.此外,您可以将它与--debug一起使用来观察(除其他外)通过网络发送的请求和响应。

Example:例子:

aws ec2 describe-instances --region us-east-1 \
  --filters "Name=ip-address,Values=${IP}" \
            "Name=instance-state-name,Values=running" \
  --max-items 10 \
  --query 'Reservations[*].Instances[*].PrivateIpAddress' \
  --output json \
  --debug

Output: Output:

2020-12-27 xx:xx:xx,xxx - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=DescribeInstances) with params:
  {'body': {u'Filter.1.Name': u'ip-address', u'Filter.2.Value.1': u'running',
  u'Filter.2.Name': u'instance-state-name', 'Version': u'2016-11-15',
  'Action': u'DescribeInstances', u'Filter.1.Value.1': u'xx.xxx.xxx.xxx'},
  'url': u'https://ec2.us-east-1.amazonaws.com/', 'headers': {'Content-Type':
  'application/x-www-form-urlencoded; charset=utf-8',
  (...), 'method': u'POST'}

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

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