[英]How to list the AWS instance id in Resource group
我正在嘗試在我的資源組 (hello-rg) 中獲取 EC2 InstanceId。 這是我的代碼:
client = boto3.client('resource-groups', region_name='us-east-1', aws_access_key_id="key", aws_secret_access_key="id")
response = client.list_group_resources(
GroupName='hello-rg',
Filters=[
{
'Name': 'resource-type',
'Values': [
'instance',
]
},
],
)
print(response) ```
I am getting the error:
文件“rg.py”,第 21 行,在“實例”中,文件“/root/.local/lib/python3.6/site-packages/botocore/client.py”,第 357 行,在 _api_call return self._make_api_call( operation_name, kwargs) 文件“/root/.local/lib/python3.6/site-packages/botocore/client.py”,第 676 行,在 _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.BadRequestException: 發生錯誤(BadRequestException) 調用 ListGroupResources 操作時:檢測到 1 個驗證錯誤:'filters.1.member.values' 的值'[instance]' 無法滿足約束:成員必須滿足約束:[成員的長度必須小於或等於128、成員長度必須大於等於1,成員必須滿足正則表達式模式:AWS::[a-zA-Z0-9]+::[a-zA-Z0-9]+]```
我知道已經太遲了。 但這可能會幫助其他人
如錯誤所示, Values
需要是字符串列表,匹配正則表達式模式AWS::[a-zA-Z0-9]+::[a-zA-Z0-9]+]
。 要獲取實例,值字符串必須是['AWS::EC2::Instance']
這樣的事情應該工作
response = client.list_group_resources(
GroupName='hello-rg',
Filters=[
{
'Name': 'resource-type',
'Values': [
'AWS::EC2::Instance',
]
},
],
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.