Sign in
agent:

List all the resource ARNs in a given region

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This script lists all the resource ARNs in a region using the AWS Resource Groups Tagging API.

import boto3 import json # Initialize a session using Amazon Resource Names (ARNs) aws_access_key_id = getEnvVar('AWS_ACCESS_KEY_ID') aws_secret_access_key = getEnvVar('AWS_SECRET_ACCESS_KEY') resources = {} for region_name in region_names: session = boto3.Session( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=region_name ) # Initialize the resource groups tagging client client = session.client('resourcegroupstaggingapi') # Initialize variables resource_arns = [] # Paginate through all resources paginator = client.get_paginator('get_resources') for page in paginator.paginate(): for resource in page['ResourceTagMappingList']: resource_arns.append(resource['ResourceARN']) resources[region_name] = resource_arns # Print inputs and outputs print("Resources: ") print(json.dumps(resources, indent=4))
copied