我正在使用AWSBoto3SDK进行一些自动化工作。我无法知道客户端(低级)和资源(高级)之间的区别
这里的低级(客户端)和高级(资源)有什么区别?
根据我的理解,这里提到的是API编程中使用的低级和高级接口。开始了,
high-level interface, are designed to enable the programmer to write code in shorter amount of time and to be less involved with the details of the software module or hardware device that is performing the required services. Which is in direct contrast with the other one.
low-level interface, are more detailed allowing the programmer to manipulate functions within a software module or within hardware at very granular level.
AWS,当您使用Boto3进行API编程时,客户端提供的低级接口与服务API非常接近。这意味着,客户端将支持所有服务操作。然而,参考资料提供了一个高级接口,这意味着不同于客户端提供的原始低级调用。
>
客户端提供AWS服务的低级接口。它们的定义由botocore库中的JSON服务描述生成。botocore包在boto3和AWSCLI之间共享。
s3=boto3. client("s3")response=s3.list_buckets()
print("现有桶:")用于响应['桶']中的桶:print(f'{bucket["Name"]}')
与客户端相比,资源是更高级别的抽象。它们是从boto库本身中存在的JSON资源描述生成的。例如,这是S3的资源定义。
资源提供了一个面向对象的接口,用于与各种AWS服务交互。资源可以像下面这样实例化:
# S3 bucket identifier
s3 = boto3.resource("s3")
bucket = s3.Bucket(name="my_bucket")
总而言之,与客户端相比,资源是AWS服务的更高级别的抽象。资源是使用boto3的推荐模式,因为您在与AWS服务交互时不必担心许多底层细节。因此,使用Resources编写的代码往往更简单。
但是,资源并不适用于所有AWS服务。在这种情况下,别无选择,只能使用客户端。