I am trying to get the EC2 InstanceId in my resource group(hello-rg). Here is my code:
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:
File "rg.py", line 21, in 'instance', File "/root/.local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call return self._make_api_call(operation_name, kwargs) File "/root/.local/lib/python3.6/site-packages/botocore/client.py", line 676, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the ListGroupResources operation: 1 validation error detected: Value '[instance]' at 'filters.1.member.values' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 128, Member must have length greater than or equal to 1, Member must satisfy regular expression pattern: AWS::[a-zA-Z0-9]+::[a-zA-Z0-9]+] ```
I know it is already too late. But this might help others
As the error indicates, Values
need to be a list of strings, matching the regex pattern AWS::[a-zA-Z0-9]+::[a-zA-Z0-9]+]
. For getting the instances, the Value string has to be ['AWS::EC2::Instance']
Something like this should work
response = client.list_group_resources(
GroupName='hello-rg',
Filters=[
{
'Name': 'resource-type',
'Values': [
'AWS::EC2::Instance',
]
},
],
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.