文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 Lookout for Vision 的代码示例 AWS SDKs
以下代码示例向您展示了如何将 Amazon Lookout for Vision 与 AWS 软件开发套件 (SDK) 一起使用。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
场景是向您演示如何通过在一个服务中调用多个函数或与其他 AWS 服务结合来完成特定任务的代码示例。
开始使用
以下代码示例演示了如何开始使用 Lookout for Vision。
- Python
-
- 适用于 Python 的 SDK(Boto3)
-
"""
This example shows how to list your Amazon Lookout for Vision projects.
If you haven't previously created a project in the current AWS Region,
the response is an empty list, however it confirms that you can call the
Lookout for Vision API.
"""
from botocore.exceptions import ClientError
import boto3
class Hello:
"""Hello class for Amazon Lookout for Vision"""
@staticmethod
def list_projects(lookoutvision_client):
"""
Lists information about the projects that are in your AWS account
and in the current AWS Region.
: param lookoutvision_client: A Boto3 Lookout for Vision client.
"""
try:
response = lookoutvision_client.list_projects()
for project in response["Projects"]:
print("Project: " + project["ProjectName"])
print("ARN: " + project["ProjectArn"])
print()
print("Done!")
except ClientError as err:
print(f"Couldn't list projects. \n{err}")
raise
def main():
session = boto3.Session(profile_name="lookoutvision-access")
lookoutvision_client = session.client("lookoutvision")
Hello.list_projects(lookoutvision_client)
if __name__ == "__main__":
main()