I have this python output that retrieves a dictionary like below. I want to get the value of TopicArn that falls inside NotificationConfiguration.
This is my output looks like.
output of clusters
{ 'Marker': 'string', 'CacheClusters': [ { 'CacheClusterId': 'string', 'ConfigurationEndpoint': { 'Address': 'string', 'Port': 123 }, 'ClientDownloadLandingPage': 'string',, 'PendingModifiedValues': { 'NumCacheNodes': 123, 'CacheNodeIdsToRemove': [ 'string', ], 'EngineVersion': 'string', 'CacheNodeType': 'string', 'AuthTokenStatus': 'SETTING'|'ROTATING' }, 'NotificationConfiguration': { 'TopicArn': 'string', 'TopicStatus': 'string' }, 'ReplicationGroupId': 'string', }, ] } This is what I tried:
def get_ec_cache_Arn(region, clusters): ec_client = boto3.client('elasticache', region_name=region) count = 1 for cluster in clusters['CacheClusters']: cluster_arn = cluster['NotificationConfiguration'][0]['TopicArn'] But this doesn't work. gives no output. But clusters has a value I am passing from some other function. When I print clusters it produces the above-mentiond dictionary. That means clusters is not empty.
Can someone help me?
KeyError, so please edit your question with a PROPER minimal reproducible example and the full matching traceback. Also note that python has a very comprehe,sive tutorial, a full documentation, an interactive shell and a step debugger, so use all those features before posting here.