1

I have a list of boto3 client methods that I want to iterate through, create a client, and do something with that.

e.g.

methods = ['allocate_address', 'allocate_address', 'attach_volume']

client = boto3.client('ec2')

for method in methods:
    # below doesn't work
    bound_method = client.method # <-- I want to use the variable to set this

Can I do this?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
maafk
  • 6,176
  • 5
  • 35
  • 58
  • 3
    Would using the getattr method in Python help? Example: `getattr(client, api_action)(**parameters)`. api_action will be the method. **parameters will be the parameter for each method. – krishna_mee2004 Jul 05 '19 at 14:29

1 Answers1

1

Based on a comment from @krishna_mee2004, I was able to do this using:

methods = ['allocate_address', 'allocate_address', 'attach_volume']

client = boto3.client('ec2')

for method in methods:
    bound_method = getattr(client, method)
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
maafk
  • 6,176
  • 5
  • 35
  • 58