With the simple function I am able to get data stored in response variable. With a print statement I can get the data showing correctly.
ec2_client = boto3.client("ec2")
def instance_list(instance_name):
response = ec2_client.describe_instances(
Filters=[
{
'Name': 'tag:Name',
'Values': [ instance_name ]
}
]
)['Reservations']
return response
#print(response)
if __name__ == '__main__':
my_instance_list = instance_list("example-*")
However while trying to import the value of response from the above function to another function, getting error as NameError: name 'response' is not defined
def my_list():
list = instance_list(response)
print(list)
Looks like something unidentified.
response, you called itmy_instance_list, and you did so in a place that deliberately doesn't get executed when youimportthe file. Also why would you want to pass that to the function that returns it? Your code doesn't make any sense.instance_list?