'Boto3 - describe_security_groups accross linked accounts
I am wondering if it is possible to find and describe all security groups of the same name across linked accounts.
I did something similar for cost explorer:
masterAcc = boto3.Session(aws_access_key_id='foo',aws_secret_access_key='bar',region_name='eu-west-1')
org = masterAcc.client('organizations')
costEx = masterAcc.client('ce')
paginator = org.get_paginator('list_accounts')
page_iterator = paginator.paginate()
for page in page_iterator:
for acct in page['Accounts']:
listAccountAWS.append(acct['Id'])
listNameAWS.append(acct['Name'])
zipAWS = list(zip(listAccountAWS,listNameAWS))
for accountAWS, nameAWS in zipAWS:
print(nameAWS)
sr1 = costEx.get_cost_and_usage(
Granularity = 'DAILY',
Metrics = ['UnblendedCost'],
Filter = {
'Dimensions': {
'Key': 'LINKED_ACCOUNT',
'Values': [accountAWS],
},},)
I am attempting to do the same for security groups, but I am not sure if it is possible without creating sessions for the other accounts.
for accountAWS, nameAWS in zipAWS:
print(nameAWS)
response = client.describe_security_groups(GroupNames=['Access From Lilac'])
for ii in response['SecurityGroups'][0]['IpPermissions'][0]['IpRanges']:
print(ii['Description'],'-',ii['CidrIp'])
Is there a way to specify the linked account you want to use for the 'describe_security_groups' call? Any help would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
