How can I access a low-level client from an instance of a Boto 3 resource?

For example, I have this code:

import boto3 ec2 = boto3.resource('ec2') # Where is the client??? 

Do I need to call boto3.client('ec2') or is there another way?

+6
source share
1 answer

Each resource object has a special meta attribute, which is a Python type that contains information about the service, access to a low-level client, and sometimes lazy loaded cached resource attributes. You can access it like this:

 client = ec2.meta.client response = client.reboot_instances(InstanceIds=[...]) 

This is especially useful if you created a resource using custom parameters that you do not want to track later:

 ec2 = boto3.resource('ec2', region_name='us-west-2') # This client is now a US-West-2 client client = ec2.meta.client 

As always, be sure to check out the official documentation. Note : this interface is changed in boto3 # 45 . meta used to be a dict .

+8
source

Source: https://habr.com/ru/post/978039/


All Articles