End of support notice: On October 31, 2025, AWS
will discontinue support for Amazon Lookout for Vision. After October 31, 2025, you will
no longer be able to access the Lookout for Vision console or Lookout for Vision resources.
For more information, visit this
blog post.
Call an Amazon Lookout for Vision operation
Run the following code to confirm that you can make calls to the Amazon Lookout for Vision API. The code lists
the projects in your AWS account, in the current AWS Region. If you haven't previously created a project,
the response is empty, but does confirm that you can call the ListProjects
operation.
In general, calling an example function requires an AWS SDK Lookout for Vision client and any
other required parameters. The AWS SDK Lookout for Vision client is declared in the main function.
If the code fails, check that the user that you use has the correct permissions. Also
check the AWS Region that you using as Amazon Lookout for Vision is not available in all AWS Regions.
To call an Amazon Lookout for Vision operation
-
If you haven't already done so, install and configure the AWS CLI and the AWS SDKs. For more information, see
Step 4: Set up the AWS CLI and AWS SDKs.
-
Use the following example code to view your projects.
- CLI
-
Use the list-projects
command to list the
projects in your account.
aws lookoutvision list-projects \
--profile lookoutvision-access
- Python
-
This code is taken from the AWS Documentation SDK examples GitHub repository. See the full example
here.
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
from botocore.exceptions import ClientError
import boto3
class GettingStarted:
@staticmethod
def list_projects(lookoutvision_client):
"""
Lists information about the projects that are in 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:
raise
def main():
session = boto3.Session(profile_name='lookoutvision-access')
lookoutvision_client = session.client("lookoutvision")
GettingStarted.list_projects(lookoutvision_client)
if __name__ == "__main__":
main()
- Java V2
-
This code is taken from the AWS Documentation SDK examples GitHub repository. See the full example
here.
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package com.example.lookoutvision;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.services.lookoutvision.LookoutVisionClient;
import software.amazon.awssdk.services.lookoutvision.model.ProjectMetadata;
import software.amazon.awssdk.services.lookoutvision.paginators.ListProjectsIterable;
import software.amazon.awssdk.services.lookoutvision.model.ListProjectsRequest;
import software.amazon.awssdk.services.lookoutvision.model.LookoutVisionException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GettingStarted {
public static final Logger logger = Logger.getLogger(GettingStarted.class.getName());
/**
* Lists the Amazon Lookoutfor Vision projects in the current AWS account and
* AWS Region.
*
* @param lfvClient An Amazon Lookout for Vision client.
* @return List<ProjectMetadata> Metadata for each project.
*/
public static List<ProjectMetadata> listProjects(LookoutVisionClient lfvClient)
throws LookoutVisionException {
logger.log(Level.INFO, "Getting projects:");
ListProjectsRequest listProjectsRequest = ListProjectsRequest.builder()
.maxResults(100)
.build();
List<ProjectMetadata> projectMetadata = new ArrayList<>();
ListProjectsIterable projects = lfvClient.listProjectsPaginator(listProjectsRequest);
projects.stream().flatMap(r -> r.projects().stream())
.forEach(project -> {
projectMetadata.add(project);
logger.log(Level.INFO, project.projectName());
});
logger.log(Level.INFO, "Finished getting projects.");
return projectMetadata;
}
public static void main(String[] args) throws Exception {
try {
// Get the Lookout for Vision client.
LookoutVisionClient lfvClient = LookoutVisionClient.builder()
.credentialsProvider(ProfileCredentialsProvider.create("lookoutvision-access"))
.build();
List<ProjectMetadata> projects = Projects.listProjects(lfvClient);
System.out.printf("Projects%n--------%n");
for (ProjectMetadata project : projects) {
System.out.printf("Name: %s%n", project.projectName());
System.out.printf("ARN: %s%n", project.projectArn());
System.out.printf("Date: %s%n%n", project.creationTimestamp().toString());
}
} catch (LookoutVisionException lfvError) {
logger.log(Level.SEVERE, "Could not list projects: {0}: {1}",
new Object[] { lfvError.awsErrorDetails().errorCode(),
lfvError.awsErrorDetails().errorMessage() });
System.out.println(String.format("Could not list projects: %s", lfvError.getMessage()));
System.exit(1);
}
}
}