例如,我有这个代码:
import boto3
ec2 = boto3.resource('ec2')
# Where is the client???
我需要打电话boto3.client('ec2')
还是有其他方法?
例如,我有这个代码:
import boto3
ec2 = boto3.resource('ec2')
# Where is the client???
我需要打电话boto3.client('ec2')
还是有其他方法?
每个资源对象都有一个名为 的特殊属性meta
,它是一个 Python 字典,其中包含有关服务、对低级客户端的访问以及有时延迟加载的资源缓存属性的信息。您可以像这样访问它:
client = ec2.meta.client
response = client.reboot_instances(InstanceIds=[...])
如果您使用您以后不想跟踪的自定义参数创建资源,这将特别有用:
ec2 = boto3.resource('ec2', region_name='us-west-2')
# This client is now a US-West-2 client
client = ec2.meta.client