how to filter on list_gateways() aws boto3

131 Views Asked by At

got following code and it shows all my storage gateways. I need to get info on only 1 gateway

import boto3
sg = boto3.client('storagegateway', 'us-east-1')
sg.list(gateways)
print (sg.list_gateways)

any idea how to filter out and print only a specific gw?

1

There are 1 best solutions below

0
Tyler On

Try something like this to filter on the specific gateway name...

import boto3
sg = boto3.client('storagegateway', 'us-east-1')
response = sg.list_gateways()
for gw in response['Gateways']:
    if gw['GatewayName'] == 'YOUR_GATEWAY_NAME':
        print(gw)

You can filter on other response elements as well (e.g. ARN, ID, etc.) by updating the IF statement. Also, if you have more than 100 storage gateway instances, you will need to handle the Marker element to retrieve all results. For more information, see Boto3 documentation here:

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/storagegateway.html#StorageGateway.Client.list_gateways