From a6fb0f9354935ac10959d81c53d005b9b946e9d4 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Fri, 12 Dec 2025 23:31:25 -0500 Subject: [PATCH 01/28] Update SPECIFICATION.md to latest version --- scenarios/basics/inspector/SPECIFICATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scenarios/basics/inspector/SPECIFICATION.md b/scenarios/basics/inspector/SPECIFICATION.md index 51eece5c95f..95a1456fd3c 100644 --- a/scenarios/basics/inspector/SPECIFICATION.md +++ b/scenarios/basics/inspector/SPECIFICATION.md @@ -1,6 +1,6 @@ # Amazon Inspector Specification -This document contains a draft proposal for an *Amazon Inspector Basics Scenario*, generated by the Code Examples SpecGen AI tool. The specifications describe a potential code example scenario based on research, usage data, service information, and AI-assistance. The following should be reviewed for accuracy and correctness before proceeding on to a final specification. +This document contains a proposal for an *Amazon Inspector Basics Scenario*, generated by the Code Examples SpecGen AI tool. The specifications describe a potential code example scenario based on research, usage data, service information, and AI-assistance. The following should be reviewed for accuracy and correctness before proceeding on to a final specification. ### Relevant documentation From e1b097de3639604f97f7e0017d5c1cddfe4c4ab9 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Fri, 12 Dec 2025 23:37:10 -0500 Subject: [PATCH 02/28] Update SPECIFICATION.md --- scenarios/basics/inspector/SPECIFICATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scenarios/basics/inspector/SPECIFICATION.md b/scenarios/basics/inspector/SPECIFICATION.md index 95a1456fd3c..8586a4af7e9 100644 --- a/scenarios/basics/inspector/SPECIFICATION.md +++ b/scenarios/basics/inspector/SPECIFICATION.md @@ -1,6 +1,6 @@ # Amazon Inspector Specification -This document contains a proposal for an *Amazon Inspector Basics Scenario*, generated by the Code Examples SpecGen AI tool. The specifications describe a potential code example scenario based on research, usage data, service information, and AI-assistance. The following should be reviewed for accuracy and correctness before proceeding on to a final specification. +This SDK Basics scenario demonstrates how to interact with Amazon Inspector, a basics scenario that showcases AWS services and SDKs. It is primarily intended for the AWS code examples team to use while developing this example in additional languages. ### Relevant documentation From a21f7689323f87840c669c7b9abec619697a968f Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Fri, 12 Dec 2025 23:49:50 -0500 Subject: [PATCH 03/28] add Java files --- javav2/example_code/inspector/.gitignore | 38 + javav2/example_code/inspector/pom.xml | 118 +++ .../com/java/inspector/HelloInspector.java | 236 ++++++ .../com/java/inspector/InspectorActions.java | 710 ++++++++++++++++++ .../com/java/inspector/InspectorScenario.java | 185 +++++ .../org/example/InspectorFindingsDemo.java | 203 +++++ .../src/test/java/InspectorTests.java | 147 ++++ 7 files changed, 1637 insertions(+) create mode 100644 javav2/example_code/inspector/.gitignore create mode 100644 javav2/example_code/inspector/pom.xml create mode 100644 javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java create mode 100644 javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java create mode 100644 javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java create mode 100644 javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java create mode 100644 javav2/example_code/inspector/src/test/java/InspectorTests.java diff --git a/javav2/example_code/inspector/.gitignore b/javav2/example_code/inspector/.gitignore new file mode 100644 index 00000000000..5ff6309b719 --- /dev/null +++ b/javav2/example_code/inspector/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/javav2/example_code/inspector/pom.xml b/javav2/example_code/inspector/pom.xml new file mode 100644 index 00000000000..f559deabe0f --- /dev/null +++ b/javav2/example_code/inspector/pom.xml @@ -0,0 +1,118 @@ + + + 4.0.0 + + org.example + Inspector + 1.0-SNAPSHOT + + + UTF-8 + 17 + 17 + 17 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 21 + 21 + --enable-preview + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.2 + + + + + + + software.amazon.awssdk + bom + 2.29.45 + pom + import + + + org.apache.logging.log4j + log4j-bom + 2.23.1 + pom + import + + + + + + org.junit.jupiter + junit-jupiter + 5.11.4 + test + + + software.amazon.awssdk + netty-nio-client + + + software.amazon.awssdk + secretsmanager + + + com.google.code.gson + gson + 2.10.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.17.0 + + + software.amazon.awssdk + inspector2 + + + software.amazon.awssdk + sso + + + software.amazon.awssdk + ssooidc + + + org.apache.logging.log4j + log4j-core + + + org.slf4j + slf4j-api + 2.0.13 + + + org.apache.logging.log4j + log4j-slf4j2-impl + + + software.amazon.awssdk + acm + + + org.apache.logging.log4j + log4j-1.2-api + + + software.amazon.awssdk + url-connection-client + 2.18.13 + + + \ No newline at end of file diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java new file mode 100644 index 00000000000..1f241895f09 --- /dev/null +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java @@ -0,0 +1,236 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.java.inspector; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.inspector2.Inspector2Client; +import software.amazon.awssdk.services.inspector2.model.BatchGetAccountStatusRequest; +import software.amazon.awssdk.services.inspector2.model.BatchGetAccountStatusResponse; +import software.amazon.awssdk.services.inspector2.model.AccountState; +import software.amazon.awssdk.services.inspector2.model.ResourceState; +import software.amazon.awssdk.services.inspector2.model.State; +import software.amazon.awssdk.services.inspector2.model.ListFindingsRequest; +import software.amazon.awssdk.services.inspector2.model.ListFindingsResponse; +import software.amazon.awssdk.services.inspector2.model.Finding; +import software.amazon.awssdk.services.inspector2.model.ListUsageTotalsRequest; +import software.amazon.awssdk.services.inspector2.model.ListUsageTotalsResponse; +import software.amazon.awssdk.services.inspector2.model.UsageTotal; +import software.amazon.awssdk.services.inspector2.model.Inspector2Exception; +import software.amazon.awssdk.services.inspector2.paginators.ListFindingsIterable; +import software.amazon.awssdk.services.inspector2.paginators.ListUsageTotalsIterable; +import java.util.List; +import java.util.ArrayList; + +// snippet-start:[inspector.java2.hello.main] +/** + * Before running this Java V2 code example, set up your development + * environment, including your credentials. + * + * For more information, see the following documentation topic: + * + * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html + */ +public class HelloInspector { + private static final Logger logger = LoggerFactory.getLogger(HelloInspector.class); + public static void main(String[] args) { + logger.info(" Hello Amazon Inspector!"); + try (Inspector2Client inspectorClient = Inspector2Client.builder() + .build()) { + + logger.info("Checking Inspector account status..."); + checkAccountStatus(inspectorClient); + logger.info(""); + + logger.info("Checking for recent findings..."); + listRecentFindings(inspectorClient); + logger.info(""); + + logger.info("Checking usage totals..."); + showUsageTotals(inspectorClient); + logger.info(""); + + logger.info("The Hello Inspector example completed successfully."); + + } catch (Inspector2Exception e) { + logger.info(" Error: {}" , e.getMessage()); + logger.info(" Troubleshooting:"); + logger.info("1. Verify AWS credentials are configured"); + logger.info("2. Check IAM permissions for Inspector2"); + logger.info("3. Ensure Inspector2 is enabled in your account"); + logger.info("4. Verify you're using a supported region"); + } + } + + /** + * Checks the account status using the provided Inspector2Client. + * This method sends a request to retrieve the account status and prints the details of each account's resource states. + * + * @param inspectorClient The Inspector2Client used to interact with the AWS Inspector service. + */ + public static void checkAccountStatus(Inspector2Client inspectorClient) { + try { + BatchGetAccountStatusRequest request = BatchGetAccountStatusRequest.builder().build(); + BatchGetAccountStatusResponse response = inspectorClient.batchGetAccountStatus(request); + + List accounts = response.accounts(); + if (accounts == null || accounts.isEmpty()) { + logger.info(" No account information returned."); + return; + } + + for (AccountState account : accounts) { + logger.info(" Account: " + account.accountId()); + ResourceState resources = account.resourceState(); + if (resources == null) { + System.out.println(" No resource state data available."); + continue; + } + + logger.info(" Resource States:"); + printState("EC2", resources.ec2()); + printState("ECR", resources.ecr()); + printState("Lambda", resources.lambda()); + printState("Lambda Code", resources.lambdaCode()); + System.out.println(); + } + + } catch (Inspector2Exception e) { + System.err.println(" Failed to retrieve account status: " + e.awsErrorDetails().errorMessage()); + } + } + + public static void printState(String name, State state) { + if (state == null) { + logger.info(" - {} : (no data)", name); + return; + } + String err = state.errorMessage() != null ? " (Error: " + state.errorMessage() + ")" : ""; + logger.info(" - {}: {}{}", name, state.status(), err); + } + + /** + * Lists recent findings from AWS Inspector2 using the synchronous client with a paginator. + * + * @param inspectorClient an instance of {@link Inspector2Client} used to call AWS Inspector2 + * @throws Inspector2Exception if there is an error communicating with the Inspector2 service + */ + /** + * Lists up to 10 recent findings from AWS Inspector2 using the synchronous client. + * + *

This method retrieves findings in pages and logs details for each finding, + * including title, severity, status, and last observed time. Only the first + * 10 findings are logged, even if more exist. + * + * @param inspectorClient an instance of {@link Inspector2Client} used to call AWS Inspector2 + * @throws Inspector2Exception if there is an error communicating with the Inspector2 service + */ + public static void listRecentFindings(Inspector2Client inspectorClient) { + final int MAX_FINDINGS = 10; + int totalLogged = 0; + + try { + // Build initial request with page size + ListFindingsRequest request = ListFindingsRequest.builder() + .maxResults(MAX_FINDINGS) + .build(); + + // Paginator returns an iterable over responses + ListFindingsIterable responses = inspectorClient.listFindingsPaginator(request); + + for (ListFindingsResponse response : responses) { + List findings = response.findings(); + if (findings == null || findings.isEmpty()) { + continue; + } + + for (Finding finding : findings) { + if (totalLogged >= MAX_FINDINGS) { + break; + } + + logger.info(" Title: {}", finding.title()); + logger.info(" Severity: {}", finding.severity()); + logger.info(" Status: {}", finding.status()); + logger.info(" Last Observed: {}", finding.lastObservedAt()); + logger.info(""); + + totalLogged++; + } + + if (totalLogged >= MAX_FINDINGS) { + break; + } + } + + if (totalLogged == 0) { + logger.info(" No findings found."); + } else { + logger.info(" Displayed {} recent finding(s).", totalLogged); + } + + } catch (Inspector2Exception e) { + logger.info(" Error listing findings: {}", e.awsErrorDetails().errorMessage()); + } + } + + + /** + * Displays the usage totals for the Inspector2 service. + * + * @param inspectorClient the {@code Inspector2Client} used to make the API call to + * retrieve the usage totals. + * + * @throws Inspector2Exception if there is an error while retrieving the usage totals. + * The error message is printed to the standard error output. + */ + public static void showUsageTotals(Inspector2Client inspectorClient) { + try { + logger.info("Listing usage totals using paginator..."); + ListUsageTotalsRequest request = ListUsageTotalsRequest.builder() + .maxResults(10) + .build(); + + // Create paginator. + ListUsageTotalsIterable paginator = inspectorClient.listUsageTotalsPaginator(request); + List allTotals = new ArrayList<>(); + + // Iterate through all pages. + for (ListUsageTotalsResponse response : paginator) { + List totals = response.totals(); + if (totals != null && !totals.isEmpty()) { + allTotals.addAll(totals); + } + } + + // Display results. + if (allTotals.isEmpty()) { + logger.info(" No usage data available yet."); + logger.info(" Usage data appears after Inspector has been active for some time."); + } else { + logger.info(" Usage Totals (Last 30 days):"); + for (UsageTotal total : allTotals) { + logger.info(" Account: {}" , total.accountId()); + if (total.usage() != null && !total.usage().isEmpty()) { + total.usage().forEach(u -> { + logger.info(" - {}: {}", u.type(), u.total()); + + if (u.estimatedMonthlyCost() != null) { + logger.info(" Estimated Monthly Cost: {} {}", u.estimatedMonthlyCost(), u.currency()); + } + }); + } + logger.info(""); + } + } + + } catch (Inspector2Exception e) { + logger.info(" Error getting usage totals: {}" , e.awsErrorDetails().errorMessage()); + throw e; + } catch (Exception e) { + throw new RuntimeException("Unexpected error while listing usage totals: " + e.getMessage(), e); + } + } +} +// snippet-end:[inspector.java2.hello.main] \ No newline at end of file diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java new file mode 100644 index 00000000000..c51a7788cc0 --- /dev/null +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java @@ -0,0 +1,710 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.java.inspector; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; +import software.amazon.awssdk.core.retry.RetryMode; +import software.amazon.awssdk.http.async.SdkAsyncHttpClient; +import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; +import software.amazon.awssdk.services.inspector2.Inspector2AsyncClient; +import software.amazon.awssdk.services.inspector2.model.*; +import software.amazon.awssdk.services.inspector2.paginators.ListFiltersPublisher; +import software.amazon.awssdk.services.inspector2.paginators.ListFindingsPublisher; +import software.amazon.awssdk.services.inspector2.paginators.ListUsageTotalsPublisher; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.stream.Collectors; + +// snippet-start:[inspector.java2_actions.main] +public class InspectorActions { + private static Inspector2AsyncClient inspectorAsyncClient; + private static final Logger logger = LoggerFactory.getLogger(InspectorActions.class); + + private static Inspector2AsyncClient getAsyncClient() { + if (inspectorAsyncClient == null) { + SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder() + .maxConcurrency(100) + .connectionTimeout(Duration.ofSeconds(60)) + .readTimeout(Duration.ofSeconds(60)) + .writeTimeout(Duration.ofSeconds(60)) + .build(); + + ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder() + .apiCallTimeout(Duration.ofMinutes(2)) + .apiCallAttemptTimeout(Duration.ofSeconds(90)) + .retryStrategy(RetryMode.STANDARD) + .build(); + + inspectorAsyncClient = Inspector2AsyncClient.builder() + .httpClient(httpClient) + .overrideConfiguration(overrideConfig) + .build(); + } + return inspectorAsyncClient; + } + + // snippet-start:[inspector.java2.enable.main] + + /** + * Enables AWS Inspector for the provided account(s) and default resource types. + * + * @param accountIds Optional list of AWS account IDs. + */ + public CompletableFuture enableInspectorAsync(List accountIds) { + + // The resource types to enable. + List resourceTypes = List.of( + ResourceScanType.EC2, + ResourceScanType.ECR, + ResourceScanType.LAMBDA, + ResourceScanType.LAMBDA_CODE + ); + + // Build the request. + EnableRequest.Builder requestBuilder = EnableRequest.builder() + .resourceTypes(resourceTypes); + + if (accountIds != null && !accountIds.isEmpty()) { + requestBuilder.accountIds(accountIds); + } + + EnableRequest request = requestBuilder.build(); + return getAsyncClient().enable(request) + .whenComplete((response, exception) -> { + if (exception != null) { + Throwable cause = exception.getCause(); + if (cause instanceof ValidationException) { + throw new CompletionException( + "Inspector may already be enabled for this account: %s".formatted(cause.getMessage()), + cause + ); + + } + + if (cause instanceof Inspector2Exception) { + Inspector2Exception e = (Inspector2Exception) cause; + throw new CompletionException( + "AWS Inspector2 service error: %s".formatted(e.awsErrorDetails().errorMessage()), + cause + ); + } + + throw new CompletionException( + "Failed to enable Inspector: %s".formatted(exception.getMessage()), + exception + ); + } + }) + .thenApply(response -> { + StringBuilder summary = new StringBuilder("Enable results:\n"); + + if (response.accounts() == null || response.accounts().isEmpty()) { + summary.append("Inspector may already be enabled for all target accounts."); + return summary.toString(); + } + + for (Account account : response.accounts()) { + String accountId = account.accountId() != null ? account.accountId() : "Unknown"; + String status = account.status() != null ? account.statusAsString() : "Unknown"; + summary.append(" • Account: ").append(accountId) + .append(" → Status: ").append(status).append("\n"); + } + + return summary.toString(); + }); + } + // snippet-end:[inspector.java2.enable.main] + + // snippet-start:[inspector.java2.list_coverage.stats.main] + + /** + * Retrieves and prints the coverage statistics using a paginator. + */ + public CompletableFuture listCoverageStatisticsAsync() { + ListCoverageStatisticsRequest request = ListCoverageStatisticsRequest.builder() + .build(); + + return getAsyncClient().listCoverageStatistics(request) + .whenComplete((response, exception) -> { + if (exception != null) { + Throwable cause = exception.getCause(); + + if (cause instanceof ValidationException) { + throw new CompletionException( + "Validation error listing coverage statistics: %s".formatted(cause.getMessage()), + cause + ); + } + + if (cause instanceof Inspector2Exception) { + Inspector2Exception e = (Inspector2Exception) cause; + + throw new CompletionException( + "Inspector2 service error: %s".formatted(e.awsErrorDetails().errorMessage()), + e + ); + } + + throw new CompletionException( + "Unexpected error listing coverage statistics: %s".formatted(exception.getMessage()), + exception + ); + } + }) + .thenApply(response -> { + List countsList = response.countsByGroup(); + StringBuilder sb = new StringBuilder(); + + if (countsList == null || countsList.isEmpty()) { + sb.append("No coverage statistics available.\n"); + return sb.toString(); + } + + sb.append("Coverage Statistics:\n"); + + for (Counts c : countsList) { + sb.append(" Group: ").append(c.groupKey()).append("\n") + .append(" Total Count: ").append(c.count()).append("\n\n"); + } + + return sb.toString(); + }); + } + // snippet-end:[inspector.java2.list_coverage.stats.main] + + // snippet-start:[inspector.java2.list_usage_totals.main] + + /** + * Asynchronously lists Inspector2 usage totals using a paginator. + * + * @param accountIds optional list of account IDs + * @param maxResults maximum results per page + * @return CompletableFuture completed with formatted summary text + */ + public CompletableFuture listUsageTotalsAsync( + List accountIds, + int maxResults) { + + logger.info("Starting usage totals paginator…"); + + ListUsageTotalsRequest.Builder builder = ListUsageTotalsRequest.builder() + .maxResults(maxResults); + + if (accountIds != null && !accountIds.isEmpty()) { + builder.accountIds(accountIds); + } + + ListUsageTotalsRequest request = builder.build(); + ListUsageTotalsPublisher paginator = getAsyncClient().listUsageTotalsPaginator(request); + StringBuilder summaryBuilder = new StringBuilder(); + + return paginator.subscribe(response -> { + if (response.totals() != null && !response.totals().isEmpty()) { + response.totals().forEach(total -> { + if (total.usage() != null) { + total.usage().forEach(usage -> { + logger.info("Usage: {} = {}", usage.typeAsString(), usage.total()); + summaryBuilder.append(usage.typeAsString()) + .append(": ") + .append(usage.total()) + .append("\n"); + }); + } + }); + } else { + logger.info("Page contained no usage totals."); + } + }).thenRun(() -> logger.info("Successfully listed usage totals.")) + .thenApply(v -> { + String summary = summaryBuilder.toString(); + return summary.isEmpty() ? "No usage totals found." : summary; + }).exceptionally(ex -> { + Throwable cause = ex.getCause() != null ? ex.getCause() : ex; + + if (cause instanceof ValidationException ve) { + throw new CompletionException( + "Validation error listing usage totals: %s".formatted(ve.getMessage()), + ve + ); + } + + throw new CompletionException("Failed to list usage totals", cause); + }); + } + + // snippet-end:[inspector.java2.list_usage_totals.main] + + // snippet-start:[inspector.java2.get_account_status.main] + + /** + * Retrieves the account status using the Inspector2Client. + */ + public CompletableFuture getAccountStatusAsync() { + BatchGetAccountStatusRequest request = BatchGetAccountStatusRequest.builder() + .accountIds(Collections.emptyList()) + .build(); + + return getAsyncClient().batchGetAccountStatus(request) + .whenComplete((response, exception) -> { + if (exception != null) { + Throwable cause = exception.getCause(); + if (cause instanceof AccessDeniedException) { + throw new CompletionException( + "You do not have sufficient access: %s".formatted(cause.getMessage()), + cause + ); + + } + + if (cause instanceof Inspector2Exception) { + Inspector2Exception e = (Inspector2Exception) cause; + + throw new CompletionException( + "Inspector2 service error: %s".formatted(e.awsErrorDetails().errorMessage()), + e + ); + } + + throw new CompletionException( + "Unexpected error getting account status: %s".formatted(exception.getMessage()), + exception + ); + } + }) + .thenApply(response -> { + + StringBuilder sb = new StringBuilder(); + List accounts = response.accounts(); + + if (accounts == null || accounts.isEmpty()) { + sb.append("No account status returned.\n"); + return sb.toString(); + } + + sb.append("Inspector Account Status:\n"); + for (AccountState account : accounts) { + + String accountId = account.accountId() != null + ? account.accountId() + : "Unknown"; + + sb.append(" Account ID: ").append(accountId).append("\n"); + + // Overall account state + if (account.state() != null && account.state().status() != null) { + sb.append(" Overall State: ") + .append(account.state().status()) + .append("\n"); + } else { + sb.append(" Overall State: Unknown\n"); + } + + // Resource state (only status available) + ResourceState resources = account.resourceState(); + if (resources != null) { + sb.append(" Resource Status: available\n"); + } + + sb.append("\n"); + } + + return sb.toString(); + }); + } + // snippet-end:[inspector.java2.get_account_status.main] + + // snippet-start:[inspector.java2.list_filters.main] + + /** + * Asynchronously lists Inspector2 filters using a paginator. + * + * @param maxResults maximum filters per page (nullable) + * @return CompletableFuture completed with summary text + */ + public CompletableFuture listFiltersAsync(Integer maxResults) { + logger.info("Starting async filters paginator…"); + + ListFiltersRequest.Builder builder = ListFiltersRequest.builder(); + if (maxResults != null) { + builder.maxResults(maxResults); + } + + ListFiltersRequest request = builder.build(); + + // Paginator from SDK + ListFiltersPublisher paginator = getAsyncClient().listFiltersPaginator(request); + StringBuilder collectedFilterIds = new StringBuilder(); + + return paginator.subscribe(response -> { + response.filters().forEach(filter -> { + logger.info("Filter: " + filter.arn()); + collectedFilterIds.append(filter.arn()).append("\n"); + }); + }).thenApply(v -> { + String result = collectedFilterIds.toString(); + logger.info("Successfully listed all filters."); + return result.isEmpty() ? "No filters found." : result; + }).exceptionally(ex -> { + Throwable cause = ex.getCause() != null ? ex.getCause() : ex; + + if (cause instanceof ValidationException ve) { + throw new CompletionException( + "Validation error listing filters: %s".formatted(ve.getMessage()), + ve + ); + } + + throw new RuntimeException("Failed to list filters", ex); + }); + } + // snippet-end:[inspector.java2.list_filters.main] + + // snippet-start:[inspector.java2.create.filter.main] + + /** + * Creates a new LOW severity filter in AWS Inspector2 to suppress findings. + * + * @param filterName the name of the filter to create + * @param description a descriptive string explaining the purpose of the filter + * @return a CompletableFuture that completes with the ARN of the created filter + * @throws CompletionException wraps any validation, Inspector2 service, or unexpected errors + */ + public CompletableFuture createLowSeverityFilterAsync( + String filterName, + String description) { + + // Define a filter to match LOW severity findings. + StringFilter severityFilter = StringFilter.builder() + .value(Severity.LOW.toString()) + .comparison(StringComparison.EQUALS) + .build(); + + // Create filter criteria. + FilterCriteria filterCriteria = FilterCriteria.builder() + .severity(Collections.singletonList(severityFilter)) + .build(); + + // Build the filter creation request. + CreateFilterRequest request = CreateFilterRequest.builder() + .name(filterName) + .filterCriteria(filterCriteria) + .action(FilterAction.SUPPRESS) + .description(description) + .build(); + + return getAsyncClient().createFilter(request) + .whenComplete((response, exception) -> { + if (exception != null) { + Throwable cause = exception.getCause() != null ? exception.getCause() : exception; + + if (cause instanceof ValidationException ve) { + throw new CompletionException( + "Validation error creating filter: %s".formatted(ve.getMessage()), + ve + ); + } + + if (cause instanceof Inspector2Exception e) { + throw new CompletionException( + "Inspector2 service error: %s".formatted(e.awsErrorDetails().errorMessage()), + e + ); + } + + // Unexpected async error + throw new CompletionException( + "Unexpected error creating filter: %s".formatted(exception.getMessage()), + exception + ); + } + }) + // Extract and return the ARN of the created filter. + .thenApply(CreateFilterResponse::arn); + } + // snippet-end:[inspector.java2.create.filter.main] + + // snippet-start:[inspector.java2.list_findings.main] + + /** + * Lists all AWS Inspector findings of LOW severity asynchronously. + * + * @return CompletableFuture containing either "No findings found." or the ARNs of all LOW findings. + */ + public CompletableFuture listLowSeverityFindingsAsync() { + logger.info("Starting async LOW severity findings paginator…"); + + // Build a filter criteria for LOW severity. + StringFilter severityFilter = StringFilter.builder() + .value(Severity.LOW.toString()) + .comparison(StringComparison.EQUALS) + .build(); + + FilterCriteria filterCriteria = FilterCriteria.builder() + .severity(Collections.singletonList(severityFilter)) + .build(); + + // Build the request. + ListFindingsRequest request = ListFindingsRequest.builder() + .filterCriteria(filterCriteria) + .build(); + + ListFindingsPublisher paginator = getAsyncClient().listFindingsPaginator(request); + List allArns = Collections.synchronizedList(new ArrayList<>()); + + return paginator.subscribe(response -> { + if (response.findings() != null && !response.findings().isEmpty()) { + response.findings().forEach(finding -> { + logger.info("Finding ARN: {}", finding.findingArn()); + allArns.add(finding.findingArn()); + }); + } else { + logger.info("Page contained no findings."); + } + }) + .thenRun(() -> logger.info("Successfully listed all LOW severity findings.")) + .thenApply(v -> { + if (allArns.isEmpty()) { + return "No LOW severity findings found."; + } else { + return String.join("\n", allArns); + } + }) + .exceptionally(ex -> { + Throwable cause = ex.getCause() != null ? ex.getCause() : ex; + if (cause instanceof ValidationException ve) { + throw new CompletionException( + "Validation error listing LOW severity findings: %s".formatted(ve.getMessage()), + ve + ); + } + throw new RuntimeException("Failed to list LOW severity findings", ex); + }); + } + // snippet-end:[inspector.java2.list_findings.main] + + // snippet-start:[inspector.java2.list_coverage.main] + + /** + * Lists AWS Inspector2 coverage details for scanned resources using a paginator. + * + * @param maxResults Maximum number of resources to return. + */ + public CompletableFuture listCoverageAsync( + int maxResults) { + + ListCoverageRequest request = ListCoverageRequest.builder() + .maxResults(maxResults) + .build(); + + return getAsyncClient().listCoverage(request) + .whenComplete((response, exception) -> { + if (exception != null) { + Throwable cause = exception.getCause(); + + if (cause instanceof ValidationException) { + throw new CompletionException( + "Validation error listing coverage: " + cause.getMessage(), + cause + ); + } + + if (cause instanceof Inspector2Exception) { + Inspector2Exception e = (Inspector2Exception) cause; + throw new CompletionException( + "Inspector2 service error: " + e.awsErrorDetails().errorMessage(), + e + ); + } + + throw new CompletionException( + "Unexpected error listing coverage: " + exception.getMessage(), + exception + ); + } + }) + .thenApply(response -> { + + List coveredResources = response.coveredResources(); + + // Build output summary + StringBuilder sb = new StringBuilder(); + + if (coveredResources == null || coveredResources.isEmpty()) { + sb.append("No coverage information available.\n") + .append("This likely means Inspector hasn't scanned your resources yet ") + .append("or no supported resource types are present.\n"); + + return sb.toString(); + } + + // Summary counts + sb.append("Coverage Information:\n") + .append(" Total resources covered: ") + .append(coveredResources.size()) + .append("\n"); + + // Group by resource type + Map> byType = + coveredResources.stream() + .collect(Collectors.groupingBy(CoveredResource::resourceTypeAsString)); + + byType.forEach((type, list) -> + sb.append(" ").append(type) + .append(": ").append(list.size()) + .append(" resource(s)\n") + ); + + sb.append("\nSample covered resources:\n"); + for (int i = 0; i < Math.min(coveredResources.size(), 3); i++) { + CoveredResource r = coveredResources.get(i); + + sb.append(" - ") + .append(r.resourceTypeAsString()) + .append(": ") + .append(r.resourceId()) + .append("\n"); + + sb.append(" Scan Type: ") + .append(r.scanTypeAsString()) + .append("\n"); + + if (r.scanStatus() != null) { + sb.append(" Status: ") + .append(r.scanStatus().statusCodeAsString()) + .append("\n"); + } + + if (r.accountId() != null) { + sb.append(" Account ID: ") + .append(r.accountId()) + .append("\n"); + } + + sb.append("\n"); + } + return sb.toString(); + }); + } + // snippet-end:[inspector.java2.list_coverage.main] + + // snippet-start:[inspector.java2.delete.filter.main] + + /** + * Deletes an AWS Inspector2 filter. + * + * @param filterARN The ARN of the filter to delete. + */ + public CompletableFuture deleteFilterAsync(String filterARN) { + return getAsyncClient().deleteFilter( + DeleteFilterRequest.builder() + .arn(filterARN) + .build() + ) + .handle((response, exception) -> { + if (exception != null) { + Throwable cause = exception.getCause() != null ? exception.getCause() : exception; + + if (cause instanceof ResourceNotFoundException rnfe) { + String msg = "Filter not found for ARN: %s".formatted(filterARN); + logger.warn(msg, rnfe); + throw new CompletionException(msg, rnfe); + } + + throw new RuntimeException("Failed to delete the filter: " + cause, cause); + } + return null; + }); + } + // snippet-end:[inspector.java2.delete.filter.main] + + // snippet-start:[inspector.java2.finding.details.main] + /** + * Retrieves detailed information about a specific AWS Inspector2 finding asynchronously. + * + * @param findingArn The ARN of the finding to look up. + * @return A {@link CompletableFuture} that, when completed, provides a formatted string + * containing all available details for the finding. + * @throws RuntimeException if the async call to Inspector2 fails. + */ + public CompletableFuture getFindingDetailsAsync(String findingArn) { + BatchGetFindingDetailsRequest request = BatchGetFindingDetailsRequest.builder() + .findingArns(findingArn) + .build(); + + return getAsyncClient().batchGetFindingDetails(request) + .thenApply(response -> { + if (response.findingDetails() == null || response.findingDetails().isEmpty()) { + return String.format("No details found for ARN: ", findingArn); + } + + StringBuilder sb = new StringBuilder(); + response.findingDetails().forEach(detail -> { + sb.append("Finding ARN: ").append(detail.findingArn()).append("\n") + .append("Risk Score: ").append(detail.riskScore()).append("\n"); + + // ExploitObserved timings + if (detail.exploitObserved() != null) { + sb.append("Exploit First Seen: ").append(detail.exploitObserved().firstSeen()).append("\n") + .append("Exploit Last Seen: ").append(detail.exploitObserved().lastSeen()).append("\n"); + } + + // Reference URLs + if (detail.hasReferenceUrls()) { + sb.append("Reference URLs:\n"); + detail.referenceUrls().forEach(url -> sb.append(" • ").append(url).append("\n")); + } + + // Tools + if (detail.hasTools()) { + sb.append("Tools:\n"); + detail.tools().forEach(tool -> sb.append(" • ").append(tool).append("\n")); + } + + // TTPs + if (detail.hasTtps()) { + sb.append("TTPs:\n"); + detail.ttps().forEach(ttp -> sb.append(" • ").append(ttp).append("\n")); + } + + // CWEs + if (detail.hasCwes()) { + sb.append("CWEs:\n"); + detail.cwes().forEach(cwe -> sb.append(" • ").append(cwe).append("\n")); + } + + // Evidence + if (detail.hasEvidences()) { + sb.append("Evidence:\n"); + detail.evidences().forEach(ev -> { + sb.append(" - Severity: ").append(ev.severity()).append("\n"); + + }); + } + + sb.append("\n"); + }); + + return sb.toString(); + }) + .exceptionally(ex -> { + Throwable cause = ex.getCause() != null ? ex.getCause() : ex; + + if (cause instanceof ResourceNotFoundException rnfe) { + return "Finding not found: %s".formatted(findingArn); + } + + // Fallback for other exceptions + throw new RuntimeException("Failed to get finding details for ARN: " + findingArn, cause); + }); + } + // snippet-end:[inspector.java2.finding.details.main] +} +// snippet-end:[inspector.java2_actions.main] \ No newline at end of file diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java new file mode 100644 index 00000000000..52e7ae8da1c --- /dev/null +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java @@ -0,0 +1,185 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.java.inspector; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Scanner; + +// snippet-start:[inspector.java2_scenario.main] + +/** + * Before running this Java V2 code example, set up your development + * environment, including your credentials. + *

+ * For more information, see the following documentation topic: + *

+ * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html + */ +public class InspectorScenario { + + public static final String DASHES = new String(new char[80]).replace("\0", "-"); + private static final Logger logger = LoggerFactory.getLogger(InspectorScenario.class); + private static final Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + InspectorActions inspectorActions = new InspectorActions(); + logger.info("Amazon Inspector Basics Scenario"); + + logger.info(""" + Amazon Inspector is a security assessment service provided by Amazon Web Services (AWS) that helps + improve the security and compliance of applications deployed on AWS. It automatically assesses + applications for vulnerabilities or deviations from best practices. By leveraging Amazon Inspector, + users can gain insights into the overall security state of their application and identify potential + security risks. + + This service operates by conducting both network and host-based assessments, allowing it to detect a + wide range of security issues, including those related to operating systems, network configurations, + and application dependencies. + """); + + waitForInputToContinue(); + + try { + runScenario(inspectorActions); + + logger.info(""); + logger.info("Scenario completed successfully!"); + logger.info(""); + logger.info("What you learned:"); + logger.info(" - How to check Inspector account status"); + logger.info(" - How to enable Inspector"); + logger.info(" - How to list and analyze findings"); + logger.info(" - How to check coverage information"); + logger.info(" - How to create and manage filters"); + logger.info(" - How to track usage and costs"); + logger.info(""); + + } catch (Exception ex) { + logger.error("Scenario failed due to unexpected error: {}", ex.getMessage(), ex); + + } finally { + scanner.close(); + logger.info("Exiting..."); + } + } + + /** + * Runs the Inspector scenario in a step-by-step sequence. + * + * All InspectorActions methods are asynchronous and return CompletableFutures. + * Each step ends with .join(). + * + * + * Error handling: + * • runScenario() intentionally does not catch any exceptions + * • Any async exception thrown during .join() will bubble up + * • The main() method contains a single top-level try/catch, + * which logs failures and ends the scenario gracefully + * + * This design keeps the scenario readable while still demonstrating proper + * asynchronous Inspector2 usage, pagination, and exception propagation. + */ + public static void runScenario(InspectorActions actions) { + + // Step 1 + logger.info(DASHES); + logger.info("Step 1: Checking Inspector account status..."); + String status = actions.getAccountStatusAsync().join(); + logger.info(status); + waitForInputToContinue(); + + // Step 2 + logger.info(DASHES); + logger.info("Step 2: Enabling Inspector..."); + String message = actions.enableInspectorAsync(null).join(); + logger.info(message); + waitForInputToContinue(); + + // Step 3 + logger.info(DASHES); + logger.info("Step 3: Listing findings..."); + String allFindings = actions.listLowSeverityFindingsAsync().join(); + + if (!allFindings.equals("No findings found.")) { + // Split by newline and get the last ARN + String[] arns = allFindings.split("\\r?\\n"); + String lastArn = arns[arns.length - 1]; + + // Looks up details + logger.info("Look up details on: {}" , lastArn); + waitForInputToContinue(); + String details = actions.getFindingDetailsAsync(lastArn).join() ; + logger.info(details); + } else { + System.out.println("No findings found."); + } + + waitForInputToContinue(); + + // Step 4 + logger.info(DASHES); + logger.info("Step 4: Listing coverage..."); + String coverage = actions.listCoverageAsync(5).join(); + logger.info(coverage); + waitForInputToContinue(); + + // Step 5 + logger.info(DASHES); + logger.info("Step 5: Creating filter..."); + String filterName = "suppress-low-" + System.currentTimeMillis(); + String filterArn = actions + .createLowSeverityFilterAsync(filterName, "Suppress low severity findings") + .join(); + logger.info("Created filter: {}", filterArn); + waitForInputToContinue(); + + // Step 6 + logger.info(DASHES); + logger.info("Step 6: Listing filters..."); + String filters = actions.listFiltersAsync(10).join(); + logger.info(filters); + waitForInputToContinue(); + + // Step 7 + logger.info(DASHES); + logger.info("Step 7: Usage totals..."); + String usage = actions.listUsageTotalsAsync(null, 10).join(); + logger.info(usage); + waitForInputToContinue(); + + // Step 8 + logger.info(DASHES); + logger.info("Step 8: Coverage statistics..."); + String stats = actions.listCoverageStatisticsAsync().join(); + logger.info(stats); + waitForInputToContinue(); + + // Step 9 + logger.info(DASHES); + logger.info("Step 9: Delete filter?"); + logger.info("Filter ARN: {}", filterArn); + logger.info("Delete filter? (y/n)"); + + if (scanner.nextLine().trim().equalsIgnoreCase("y")) { + actions.deleteFilterAsync(filterArn).join(); + logger.info("Filter deleted."); + } + + waitForInputToContinue(); + } + + // Utility Method + private static void waitForInputToContinue() { + while (true) { + logger.info(""); + logger.info("Enter 'c' to continue:"); + String input = scanner.nextLine().trim(); + if (input.equalsIgnoreCase("c")) break; + logger.info("Invalid input, try again."); + } + } +} +// snippet-end:[inspector.java2_scenario.main] \ No newline at end of file diff --git a/javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java b/javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java new file mode 100644 index 00000000000..6baa49268cc --- /dev/null +++ b/javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java @@ -0,0 +1,203 @@ +package org.example; + + +import org.reactivestreams.Subscriber; +import org.reactivestreams.Subscription; +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.inspector2.Inspector2AsyncClient; +import software.amazon.awssdk.services.inspector2.model.*; +import software.amazon.awssdk.services.inspector2.paginators.ListFindingsPublisher; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +public class InspectorFindingsDemo { + + private final Inspector2AsyncClient asyncClient; + + public InspectorFindingsDemo(Inspector2AsyncClient client) { + this.asyncClient = client; + } + + private Inspector2AsyncClient getAsyncClient() { + return asyncClient; + } + + /** + * ✅ Stable async pagination — DOES NOT hang + * ✅ Manual nextToken loop + * ✅ Safe, predictable, production-grade + */ + + public CompletableFuture listFindingsAsync(int maxResults, + FilterCriteria filterCriteria) { + + System.out.println("[DEBUG] Starting async paginator…"); + + final int PAGE_LIMIT = 4; // ✅ demo-safe limit + + // Request builder + ListFindingsRequest.Builder builder = + ListFindingsRequest.builder() + .maxResults(maxResults); + + if (filterCriteria != null) { + builder.filterCriteria(filterCriteria); + } + + ListFindingsRequest request = builder.build(); + + ListFindingsPublisher paginator = + getAsyncClient().listFindingsPaginator(request); + + List allFindings = + Collections.synchronizedList(new ArrayList<>()); + + CompletableFuture future = new CompletableFuture<>(); + + paginator.subscribe(new Subscriber() { + + private Subscription subscription; + private int pageCount = 0; + + @Override + public void onSubscribe(Subscription s) { + this.subscription = s; + + System.out.println("[DEBUG] onSubscribe → requesting first page"); + + s.request(1); // request the first page + } + + @Override + public void onNext(ListFindingsResponse page) { + pageCount++; + + System.out.println("[DEBUG] onNext → received page " + pageCount); + + if (page.findings() != null) { + System.out.println("[DEBUG] Page contains " + page.findings().size() + " findings."); + allFindings.addAll(page.findings()); + } + + // ✅ Stop after PAGE_LIMIT pages + if (pageCount >= PAGE_LIMIT) { + System.out.println("[DEBUG] Page limit reached → completing future."); + future.complete(buildSummary(allFindings)); + subscription.cancel(); + return; + } + + // ✅ Otherwise request the next page + subscription.request(1); + } + + @Override + public void onError(Throwable t) { + System.out.println("[DEBUG] paginator error: " + t); + future.completeExceptionally(t); + } + + @Override + public void onComplete() { + System.out.println("[DEBUG] paginator completed normally."); + future.complete(buildSummary(allFindings)); + } + }); + + return future; + } + + + // ---------------------------------------------------------- + // ✅ Summary Builder + // ---------------------------------------------------------- + private String buildSummary(List findings) { + + if (findings.isEmpty()) { + System.out.println("[DEBUG] No findings collected."); + + return "No findings found.\n" + + "This could mean:\n" + + " • Inspector hasn't completed its initial scan yet\n" + + " • Your resources don't have any vulnerabilities\n" + + " • All findings were suppressed by filters\n"; + } + + System.out.println("[DEBUG] Building summary."); + + StringBuilder sb = new StringBuilder(); + sb.append("Found ") + .append(findings.size()) + .append(" finding(s):\n"); + + Map> bySeverity = + findings.stream() + .collect(Collectors.groupingBy(Finding::severityAsString)); + + bySeverity.forEach((sev, list) -> { + sb.append(" ") + .append(sev) + .append(": ") + .append(list.size()) + .append(" finding(s)\n"); + + System.out.println("[DEBUG] Severity " + sev + ": " + list.size()); + }); + + sb.append("\nRecent findings:\n"); + + for (int i = 0; i < Math.min(5, findings.size()); i++) { + Finding f = findings.get(i); + + sb.append(" ") + .append(i + 1) + .append(". ") + .append(f.title()) + .append("\n"); + + System.out.println("[DEBUG] Recent: " + f.title()); + } + + return sb.toString(); + } + + // ---------------------------------------------------------- + // ✅ MAIN METHOD + // ---------------------------------------------------------- + public static void main(String[] args) { + + System.out.println("[DEBUG] Creating Inspector2 async client…"); + + Inspector2AsyncClient client = + Inspector2AsyncClient.builder() + .region(Region.US_EAST_1) + .credentialsProvider(DefaultCredentialsProvider.create()) + .build(); + + InspectorFindingsDemo demo = new InspectorFindingsDemo(client); + + try { + System.out.println("[DEBUG] Calling listFindingsAsync()…"); + + String output = demo + .listFindingsAsync(50, null) + .join(); // waits for async completion + + System.out.println("[DEBUG] join() returned. Output:"); + System.out.println(output); + + } catch (Exception e) { + System.out.println("[DEBUG] Exception in main()"); + e.printStackTrace(); + } + + System.out.println("[DEBUG] Closing client…"); + client.close(); + } +} diff --git a/javav2/example_code/inspector/src/test/java/InspectorTests.java b/javav2/example_code/inspector/src/test/java/InspectorTests.java new file mode 100644 index 00000000000..3252a2985b2 --- /dev/null +++ b/javav2/example_code/inspector/src/test/java/InspectorTests.java @@ -0,0 +1,147 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import com.java.inspector.InspectorScenario; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.java.inspector.HelloInspector; +import com.java.inspector.InspectorActions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestMethodOrder; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.inspector2.Inspector2Client; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_METHOD) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class InspectorTests { + private static Inspector2Client inspector; + private static InspectorActions inspectorActions; + private static final Logger logger = LoggerFactory.getLogger(InspectorTests.class); + @BeforeAll + public static void setUp() { + inspector = Inspector2Client.builder() + .region(Region.US_EAST_1) + .build() ; + + inspectorActions = new InspectorActions(); + } + + @Test + @Tag("IntegrationTest") + @Order(1) + public void testHelloService() { + assertDoesNotThrow(() -> { + HelloInspector.checkAccountStatus(inspector); + HelloInspector.listRecentFindings(inspector); + HelloInspector.showUsageTotals(inspector); + }); + logger.info("Test 1 passed"); + } + + + /** + * Integration test for InspectorActions Async methods. + * + * This test validates that all async action methods complete successfully and + * return expected values (like filter ARN). + * + * Note that it will fail the test if any .join() throws a CompletionException. + */ + + @Test + @Tag("IntegrationTest") + @Order(2) + public void testInspectorActionsIntegration() { + assertDoesNotThrow(() -> { + int maxResults = 10; + + String filterName = "suppress-low-severity-" + System.currentTimeMillis(); + + inspectorActions.getAccountStatusAsync().join(); + + inspectorActions.enableInspectorAsync(null).join(); + + String allFindings = inspectorActions.listLowSeverityFindingsAsync().join(); + // Check if any findings were returned + if (allFindings == null || allFindings.startsWith("No LOW severity findings")) { + logger.info("No LOW severity findings available. Skipping details lookup."); + } else { + String[] arns = allFindings.split("\\r?\\n"); + String lastArn = arns[arns.length - 1]; + + // Fetch details safely + String details = inspectorActions.getFindingDetailsAsync(lastArn).join(); + logger.info("Details for last LOW severity finding:\n{}", details); + } + + + maxResults = 5; + inspectorActions.listCoverageAsync(maxResults).join(); + + String filterARN = inspectorActions.createLowSeverityFilterAsync(filterName,"Suppress low severity findings for demo purposes").join(); + + // Assert it returned a valid ARN + assertNotNull(filterARN, "Filter ARN should not be null"); + assertFalse(filterARN.isBlank(), "Filter ARN should not be empty"); + + inspectorActions.listFiltersAsync(10).join(); + + inspectorActions.listUsageTotalsAsync(null, 10).join(); + + inspectorActions.listCoverageStatisticsAsync().join(); + + inspectorActions.deleteFilterAsync(filterARN).join(); + }); + + logger.info("Test 2 passed"); + } + + + @Test + @Tag("IntegrationTest") + @Order(3) + public void testInspectorScenarioEndToEnd() { + assertDoesNotThrow(() -> { + + // The scenario calls scanner.nextLine() repeatedly. + // We simulate user input by providing many "c" lines. + String simulatedInput = String.join("\n", + Collections.nCopies(20, "c")) + "\n"; + + InputStream originalIn = System.in; + PrintStream originalOut = System.out; + + try { + // Redirect System.in to simulated input + ByteArrayInputStream testIn = new ByteArrayInputStream(simulatedInput.getBytes()); + System.setIn(testIn); + + // Capture System.out so logs don’t spam the console + System.setOut(new PrintStream(new ByteArrayOutputStream())); + + // Run the scenario + InspectorScenario.main(new String[]{}); + + } finally { + // Restore original I/O streams + System.setIn(originalIn); + System.setOut(originalOut); + } + }); + + logger.info("Test 3 (Scenario end-to-end) passed"); + } +} \ No newline at end of file From 4c9e62d5896c620876f20a3b76bbe78935ca47b8 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 00:14:56 -0500 Subject: [PATCH 04/28] update the spec --- .../org/example/InspectorFindingsDemo.java | 203 ------------------ scenarios/basics/inspector/SPECIFICATION.md | 131 ++++++----- 2 files changed, 83 insertions(+), 251 deletions(-) delete mode 100644 javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java diff --git a/javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java b/javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java deleted file mode 100644 index 6baa49268cc..00000000000 --- a/javav2/example_code/inspector/src/main/java/org/example/InspectorFindingsDemo.java +++ /dev/null @@ -1,203 +0,0 @@ -package org.example; - - -import org.reactivestreams.Subscriber; -import org.reactivestreams.Subscription; -import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.inspector2.Inspector2AsyncClient; -import software.amazon.awssdk.services.inspector2.model.*; -import software.amazon.awssdk.services.inspector2.paginators.ListFindingsPublisher; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; - -public class InspectorFindingsDemo { - - private final Inspector2AsyncClient asyncClient; - - public InspectorFindingsDemo(Inspector2AsyncClient client) { - this.asyncClient = client; - } - - private Inspector2AsyncClient getAsyncClient() { - return asyncClient; - } - - /** - * ✅ Stable async pagination — DOES NOT hang - * ✅ Manual nextToken loop - * ✅ Safe, predictable, production-grade - */ - - public CompletableFuture listFindingsAsync(int maxResults, - FilterCriteria filterCriteria) { - - System.out.println("[DEBUG] Starting async paginator…"); - - final int PAGE_LIMIT = 4; // ✅ demo-safe limit - - // Request builder - ListFindingsRequest.Builder builder = - ListFindingsRequest.builder() - .maxResults(maxResults); - - if (filterCriteria != null) { - builder.filterCriteria(filterCriteria); - } - - ListFindingsRequest request = builder.build(); - - ListFindingsPublisher paginator = - getAsyncClient().listFindingsPaginator(request); - - List allFindings = - Collections.synchronizedList(new ArrayList<>()); - - CompletableFuture future = new CompletableFuture<>(); - - paginator.subscribe(new Subscriber() { - - private Subscription subscription; - private int pageCount = 0; - - @Override - public void onSubscribe(Subscription s) { - this.subscription = s; - - System.out.println("[DEBUG] onSubscribe → requesting first page"); - - s.request(1); // request the first page - } - - @Override - public void onNext(ListFindingsResponse page) { - pageCount++; - - System.out.println("[DEBUG] onNext → received page " + pageCount); - - if (page.findings() != null) { - System.out.println("[DEBUG] Page contains " + page.findings().size() + " findings."); - allFindings.addAll(page.findings()); - } - - // ✅ Stop after PAGE_LIMIT pages - if (pageCount >= PAGE_LIMIT) { - System.out.println("[DEBUG] Page limit reached → completing future."); - future.complete(buildSummary(allFindings)); - subscription.cancel(); - return; - } - - // ✅ Otherwise request the next page - subscription.request(1); - } - - @Override - public void onError(Throwable t) { - System.out.println("[DEBUG] paginator error: " + t); - future.completeExceptionally(t); - } - - @Override - public void onComplete() { - System.out.println("[DEBUG] paginator completed normally."); - future.complete(buildSummary(allFindings)); - } - }); - - return future; - } - - - // ---------------------------------------------------------- - // ✅ Summary Builder - // ---------------------------------------------------------- - private String buildSummary(List findings) { - - if (findings.isEmpty()) { - System.out.println("[DEBUG] No findings collected."); - - return "No findings found.\n" + - "This could mean:\n" + - " • Inspector hasn't completed its initial scan yet\n" + - " • Your resources don't have any vulnerabilities\n" + - " • All findings were suppressed by filters\n"; - } - - System.out.println("[DEBUG] Building summary."); - - StringBuilder sb = new StringBuilder(); - sb.append("Found ") - .append(findings.size()) - .append(" finding(s):\n"); - - Map> bySeverity = - findings.stream() - .collect(Collectors.groupingBy(Finding::severityAsString)); - - bySeverity.forEach((sev, list) -> { - sb.append(" ") - .append(sev) - .append(": ") - .append(list.size()) - .append(" finding(s)\n"); - - System.out.println("[DEBUG] Severity " + sev + ": " + list.size()); - }); - - sb.append("\nRecent findings:\n"); - - for (int i = 0; i < Math.min(5, findings.size()); i++) { - Finding f = findings.get(i); - - sb.append(" ") - .append(i + 1) - .append(". ") - .append(f.title()) - .append("\n"); - - System.out.println("[DEBUG] Recent: " + f.title()); - } - - return sb.toString(); - } - - // ---------------------------------------------------------- - // ✅ MAIN METHOD - // ---------------------------------------------------------- - public static void main(String[] args) { - - System.out.println("[DEBUG] Creating Inspector2 async client…"); - - Inspector2AsyncClient client = - Inspector2AsyncClient.builder() - .region(Region.US_EAST_1) - .credentialsProvider(DefaultCredentialsProvider.create()) - .build(); - - InspectorFindingsDemo demo = new InspectorFindingsDemo(client); - - try { - System.out.println("[DEBUG] Calling listFindingsAsync()…"); - - String output = demo - .listFindingsAsync(50, null) - .join(); // waits for async completion - - System.out.println("[DEBUG] join() returned. Output:"); - System.out.println(output); - - } catch (Exception e) { - System.out.println("[DEBUG] Exception in main()"); - e.printStackTrace(); - } - - System.out.println("[DEBUG] Closing client…"); - client.close(); - } -} diff --git a/scenarios/basics/inspector/SPECIFICATION.md b/scenarios/basics/inspector/SPECIFICATION.md index 8586a4af7e9..c8fa8a1db0e 100644 --- a/scenarios/basics/inspector/SPECIFICATION.md +++ b/scenarios/basics/inspector/SPECIFICATION.md @@ -2,6 +2,9 @@ This SDK Basics scenario demonstrates how to interact with Amazon Inspector, a basics scenario that showcases AWS services and SDKs. It is primarily intended for the AWS code examples team to use while developing this example in additional languages. +## Resources +This Basics scenario does not require any additional AWS resources. + ### Relevant documentation * [Getting started with Amazon Inspector](https://docs.aws.amazon.com/inspector/latest/user/getting_started.html) @@ -11,79 +14,111 @@ This SDK Basics scenario demonstrates how to interact with Amazon Inspector, a b ### API Actions Used +* [CreateFilter](https://docs.aws.amazon.com/inspector/v2/APIReference/API_CreateFilter.html) + * [Enable](https://docs.aws.amazon.com/inspector/v2/APIReference/API_Enable.html) + +* [ListCoverageStatistics](https://docs.aws.amazon.com/inspector/v2/APIReference/API_ListCoverageStatistics.html) + + +* [ListUsageTotals](https://docs.aws.amazon.com/inspector/v2/APIReference/API_ListUsageTotals.html) + * [BatchGetAccountStatus](https://docs.aws.amazon.com/inspector/v2/APIReference/API_BatchGetAccountStatus.html) + +* [ListFilters](https://docs.aws.amazon.com/inspector/v2/APIReference/API_ListFilters.html) + * [ListFindings](https://docs.aws.amazon.com/inspector/v2/APIReference/API_ListFindings.html) + * [BatchGetFindingDetails](https://docs.aws.amazon.com/inspector/v2/APIReference/API_BatchGetFindingDetails.html) + * [ListCoverage](https://docs.aws.amazon.com/inspector/v2/APIReference/API_ListCoverage.html) -* [Disable](https://docs.aws.amazon.com/inspector/v2/APIReference/API_Disable.html) -## Proposed example structure +* [DeleteFilter](https://docs.aws.amazon.com/inspector/v2/APIReference/API_DeleteFilter.html) -The output below demonstrates how this example would run for the customer. It includes a Hello service example (included for all services), and the scenario description. The scenario code would also be presented as Action snippets, with a code snippet for each SDK action. -### Hello +## Hello Amazon Inspector -The Hello example is a separate runnable example. - Set up the Inspector service client - Check the current account status for Inspector - Display available scan types and regions +The Hello example is intended for users not familiar with this service to easily get up and running. It sets up the Inspector service client, checks the current account status for Inspector and displays available scan types. ## Scenario -#### Setup +This scenario demonstrates the basic usage of **Amazon Inspector** using a Java program. It focuses on checking account status, enabling Inspector, listing findings, reviewing coverage, and managing filters. -* Enable Amazon Inspector for the account -* Verify Inspector is successfully activated -* Display account status and enabled scan types +--- -#### Coverage Assessment +### Setup -* List coverage statistics for EC2 instances, ECR repositories, and Lambda functions -* Display resource coverage details -* Show scanning status for different resource types +* Check Amazon Inspector account status +* Enable Inspector for available resource types (if not already enabled) +* Display account status summary -#### Findings Management +--- + +### Coverage Assessment + +* List coverage details for scanned resources +* Display overall coverage statistics +* Review scan status for resources (general overview) + +--- + +### Findings Management * List security findings across all resource types -* Filter findings by severity level (CRITICAL, HIGH, MEDIUM, LOW) -* Retrieve detailed information for specific findings +* Create an example filter to suppress low-severity findings +* List existing filters + +--- -#### Vulnerability Analysis +### Usage and Costs -* Display vulnerability details including CVE information -* Show affected resources and remediation guidance -* Filter findings by resource type (EC2, ECR, Lambda) +* Check usage totals and metrics for Inspector +* Review coverage statistics -#### Cleanup +--- -* Optionally disable Inspector scanning (with user confirmation) -* Display final account status +### Outcome + +By following this scenario, users learn how to: + +* Check Inspector account status and configuration +* Enable Inspector for different resource types +* List and analyze security findings +* Monitor scan coverage +* Create and manage filters +* Track usage and coverage statistics ## Errors -SDK Code examples include basic exception handling for each action used. The table below describes an appropriate exception which will be handled in the code for each service action. - -|Action |Error |Handling | -|--- |--- |--- | -|`Enable` |ValidationException |Validate resource types and account permissions. | -|`Enable` |AccessDeniedException |Notify user of insufficient permissions and exit. | -|`BatchGetAccountStatus` |ValidationException |Validate account IDs format. | -|`BatchGetAccountStatus` |AccessDeniedException |Handle permission errors gracefully. | -|`ListFindings` |ValidationException |Validate filter criteria and pagination parameters. | -|`ListFindings` |InternalServerException |Retry operation with exponential backoff. | -|`BatchGetFindingDetails` |ValidationException |Validate finding ARNs format. | -|`BatchGetFindingDetails` |AccessDeniedException |Handle access denied for specific findings. | -|`ListCoverage` |ValidationException |Validate filter and pagination parameters. | -|`Disable` |ValidationException |Validate resource types for disabling. | -|`Disable` |ConflictException |Handle cases where Inspector cannot be disabled. | +The table below describes the exceptions handled in the program for each action. -## Metadata +| Action | Exception | Handling | +|-------------------------------|---------------------------|--------------------------------------------------------------------------| +| `Enable` | `ValidationException` | Prints a message indicating Inspector may already be enabled. | +| `listUsageTotals` | `ValidationException` | Validation error listing usage totals. +| `BatchGetAccountStatus` | `AccessDeniedException` | Prints AWS service error details and rethrows the exception. | +| `ListFindings` | `ValidationException` | Prints validation error details. | +| `ListCoverage` | `ValidationException` | Prints validation error details. | +| `ListCoverageStatistics` | `ValidationException` | Prints validation error details. | +| `createFilter` | `ValidationException` | Prints validation error details. | +| `ListFilters` | `ValidationException` | Prints AWS service error details and rethrows the exception. | +| `deleteFilter` | `ResourceNotFoundException` | Prints AWS service error details and rethrows the exception. | +| `batchGetFindingDetails` | `ResourceNotFoundException` | Prints AWS service error details and rethrows the exception. | -|action / scenario |metadata file |metadata key | -|--- |--- |--- | -|`Enable` |inspector_metadata.yaml |inspector_Enable | -|`BatchGetAccountStatus` |inspector_metadata.yaml |inspector_BatchGetAccountStatus | -|`ListFindings` |inspector_metadata.yaml |inspector_ListFindings | -|`BatchGetFindingDetails` |inspector_metadata.yaml |inspector_BatchGetFindingDetails | -|`ListCoverage` |inspector_metadata.yaml |inspector_ListCoverage | -|`Disable` |inspector_metadata.yaml |inspector_Disable | -|`Amazon Inspector Basics Scenario` |inspector_metadata.yaml |inspector_Scenario | +## Metadata + +| Action / Scenario | Metadata File | Metadata Key | +|-----------------------------------------|------------------------|-------------------------------| +| `Enable` | inspector_metadata.yaml | inspector_EnableInspector | +| `BatchGetAccountStatus` | inspector_metadata.yaml | inspector_GetAccountStatus | +| `ListFindings` | inspector_metadata.yaml | inspector_ListFindings | +| `ListCoverage` | inspector_metadata.yaml | inspector_ListCoverage | +| `ListCoverageStatistics` | inspector_metadata.yaml | inspector_ListCoverageStatistics | +| `ListUsageTotals` | inspector_metadata.yaml | inspector_ListUsageTotals | +| `CreateFilter` | inspector_metadata.yaml | inspector_CreateFilter | +| `ListFilters` | inspector_metadata.yaml | inspector_ListFilters | +| `DeleteFilter` | inspector_metadata.yaml | inspector_DeleteFilter` | +| `batchGetFindingDetails` | inspector_metadata.yaml | inspector_BatchGetFindingDetails | +| `Amazon Inspector Hello` | inspector_metadata.yaml | inspector_Hello | +| `Amazon Inspector Basics Scenario` | inspector_metadata.yaml | inspector_Scenario \ No newline at end of file From 994451ebe659d8ca2d65d10ddb73918d33553c98 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 09:37:11 -0500 Subject: [PATCH 05/28] add logger file --- .../inspector/src/main/resources/log4j2.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 javav2/example_code/inspector/src/main/resources/log4j2.xml diff --git a/javav2/example_code/inspector/src/main/resources/log4j2.xml b/javav2/example_code/inspector/src/main/resources/log4j2.xml new file mode 100644 index 00000000000..914470047e7 --- /dev/null +++ b/javav2/example_code/inspector/src/main/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file From 4ae9637a6975d64070f4de7461552802c665ca72 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 09:47:35 -0500 Subject: [PATCH 06/28] add logger file --- javav2/example_code/inspector/.gitignore | 38 ------------------------ 1 file changed, 38 deletions(-) delete mode 100644 javav2/example_code/inspector/.gitignore diff --git a/javav2/example_code/inspector/.gitignore b/javav2/example_code/inspector/.gitignore deleted file mode 100644 index 5ff6309b719..00000000000 --- a/javav2/example_code/inspector/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file From 9ae4dd77ea66496a40031ef4801f466f752c7967 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 09:57:43 -0500 Subject: [PATCH 07/28] add logger file --- javav2/example_code/inspector/src/test/java/InspectorTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/javav2/example_code/inspector/src/test/java/InspectorTests.java b/javav2/example_code/inspector/src/test/java/InspectorTests.java index 3252a2985b2..8ff9b1b2a4b 100644 --- a/javav2/example_code/inspector/src/test/java/InspectorTests.java +++ b/javav2/example_code/inspector/src/test/java/InspectorTests.java @@ -115,7 +115,6 @@ public void testInspectorActionsIntegration() { @Order(3) public void testInspectorScenarioEndToEnd() { assertDoesNotThrow(() -> { - // The scenario calls scanner.nextLine() repeatedly. // We simulate user input by providing many "c" lines. String simulatedInput = String.join("\n", From f6670a0f62d56d8148e9596e756aac9c823f5b28 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 10:06:06 -0500 Subject: [PATCH 08/28] add YAML file --- .doc_gen/metadata/inspector_metadata.yaml | 174 ++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 .doc_gen/metadata/inspector_metadata.yaml diff --git a/.doc_gen/metadata/inspector_metadata.yaml b/.doc_gen/metadata/inspector_metadata.yaml new file mode 100644 index 00000000000..07783c71918 --- /dev/null +++ b/.doc_gen/metadata/inspector_metadata.yaml @@ -0,0 +1,174 @@ +# zexi 0.4.2 +inspector_Hello: + title: Hello &Inspector; + title_abbrev: Hello &Inspector; + synopsis: get started using &Inspector;. + category: Hello + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.hello.main + services: + inspector: {BatchGetAccountStatus, ListFindings, ListUsageTotals} +inspector_BatchGetFindingDetails: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.finding.details.main + services: + inspector: {BatchGetFindingDetails} +inspector_DeleteFilter: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.delete.filter.main + services: + inspector: {DeleteFilter} +inspector_EnableInspector: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.enable.main + services: + inspector: {Enable} +inspector_CreateFilter: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.create.filter.main + services: + inspector: {CreateFilter} +inspector_GetAccountStatus: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.get_account_status.main + services: + inspector: {BatchGetAccountStatus} +inspector_ListFindings: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.list_findings.main + services: + inspector: {ListFindings} +inspector_ListCoverageStatistics: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.list_coverage.stats.main + services: + inspector: {ListCoverageStatistics} +inspector_ListCoverage: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.list_coverage.main + services: + inspector: {ListCoverage} +inspector_ListUsageTotals: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.list_usage_totals.main + services: + inspector: {ListUsageTotals} +inspector_ListFilters: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.list_filters.main + services: + inspector: {ListFilters} +inspector_Scenario: + synopsis_list: + - Check Inspector account status. + - Ensure Inspector is enabled. + - Analyze security findings. + - Check scan coverage. + - Create a findings filter. + - List existing filters. + - Check usage and costs. + - Get coverage statistics. + category: Basics + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: Run an interactive scenario demonstrating &Inspector; features. + snippet_tags: + - inspector.java2_scenario.main + - description: A wrapper class for &Inspector; SDK methods. + snippet_tags: + - inspector.java2_actions.main + services: + inspector: {BatchGetAccountStatus, BatchGetFindingDetails, DeleteFilter, Enable, ListFindings, ListCoverage, CreateFilter, ListFilters, ListUsageTotals, ListCoverageStatistics} \ No newline at end of file From a6fcd1818a5183d199c0d591f7234f2f9d06b618 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 10:11:20 -0500 Subject: [PATCH 09/28] add Readme --- javav2/example_code/inspector/README.md | 123 ++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 javav2/example_code/inspector/README.md diff --git a/javav2/example_code/inspector/README.md b/javav2/example_code/inspector/README.md new file mode 100644 index 00000000000..754827256bc --- /dev/null +++ b/javav2/example_code/inspector/README.md @@ -0,0 +1,123 @@ +# Amazon Inspector code examples for the SDK for Java 2.x + +## Overview + +Shows how to use the AWS SDK for Java 2.x to work with Amazon Inspector. + + + + +_Amazon Inspector _ + +## ⚠ Important + +* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/). +* Running the tests might result in charges to your AWS account. +* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege). +* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). + + + + +## Code examples + +### Prerequisites + +For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav2` folder. + + + + + +### Get started + +- [Hello Amazon Inspector](src/main/java/com/java/inspector/HelloInspector.java#L26) (`BatchGetAccountStatus`) + + +### Basics + +Code examples that show you how to perform the essential operations within a service. + +- [Learn the basics](src/main/java/com/java/inspector/InspectorScenario.java) + + +### Single actions + +Code excerpts that show you how to call individual service functions. + +- [BatchGetAccountStatus](src/main/java/com/java/inspector/InspectorActions.java#L245) +- [BatchGetFindingDetails](src/main/java/com/java/inspector/InspectorActions.java#L628) +- [CreateFilter](src/main/java/com/java/inspector/InspectorActions.java#L370) +- [DeleteFilter](src/main/java/com/java/inspector/InspectorActions.java#L598) +- [Enable](src/main/java/com/java/inspector/InspectorActions.java#L54) +- [ListCoverage](src/main/java/com/java/inspector/InspectorActions.java#L493) +- [ListCoverageStatistics](src/main/java/com/java/inspector/InspectorActions.java#L126) +- [ListFilters](src/main/java/com/java/inspector/InspectorActions.java#L324) +- [ListFindings](src/main/java/com/java/inspector/InspectorActions.java#L434) +- [ListUsageTotals](src/main/java/com/java/inspector/InspectorActions.java#L183) + + + + + +## Run the examples + +### Instructions + + + + + +#### Hello Amazon Inspector + +This example shows you how to get started using Amazon Inspector. + + +#### Learn the basics + +This example shows you how to do the following: + +- Check Inspector account status. +- Ensure Inspector is enabled. +- Analyze security findings. +- Check scan coverage. +- Create a findings filter. +- List existing filters. +- Check usage and costs. +- Get coverage statistics. + + + + + + + + + +### Tests + +⚠ Running tests might result in charges to your AWS account. + + +To find instructions for running these tests, see the [README](../../README.md#Tests) +in the `javav2` folder. + + + + + + +## Additional resources + +- [Amazon Inspector User Guide](https://docs.aws.amazon.com/inspector/latest/user/what-is-inspector.html) +- [Amazon Inspector API Reference](https://docs.aws.amazon.com/inspector/latest/APIReference/Welcome.html) +- [SDK for Java 2.x Amazon Inspector reference](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/inspector/package-summary.html) + + + + +--- + +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 From 4db4c0f23381e2391822dde344d1f6ac08bdabc3 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 10:16:23 -0500 Subject: [PATCH 10/28] Fixed linter issue --- .../metadata/bedrock-runtime_metadata.yaml | 1503 +---------------- 1 file changed, 88 insertions(+), 1415 deletions(-) diff --git a/.doc_gen/metadata/bedrock-runtime_metadata.yaml b/.doc_gen/metadata/bedrock-runtime_metadata.yaml index 761fe7b7c9b..d376516b981 100644 --- a/.doc_gen/metadata/bedrock-runtime_metadata.yaml +++ b/.doc_gen/metadata/bedrock-runtime_metadata.yaml @@ -1,1502 +1,175 @@ -# zexi 0.4.0 -bedrock-runtime_Hello: - title: Hello &BR; - title_abbrev: Hello &BR; - synopsis: get started using &BR;. +# zexi 0.4.2 +inspector_Hello: + title: Hello &Inspector; + title_abbrev: Hello &Inspector; + synopsis: get started using &Inspector;. category: Hello - languages: - Go: - versions: - - sdk_version: 2 - github: gov2/bedrock-runtime - excerpts: - - description: - snippet_tags: - - gov2.bedrock-runtime.Hello - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: - snippet_files: - - javascriptv3/example_code/bedrock-runtime/hello.js - - services: - bedrock-runtime: {InvokeModel} - -# Converse -bedrock-runtime_Converse_AmazonNovaText: - title: Invoke Amazon Nova on &BR; using Bedrock's Converse API - title_abbrev: "Converse" - synopsis: send a text message to Amazon Nova, using Bedrock's Converse API. - category: Amazon Nova - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova using Bedrock's Converse API with the async Java client. - snippet_tags: - - bedrock-runtime.java2.ConverseAsync_AmazonNovaText - - description: Send a text message to Amazon Nova, using Bedrock's Converse API. - snippet_tags: - - bedrock-runtime.java2.Converse_AmazonNovaText - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API. - snippet_tags: - - javascript.v3.bedrock-runtime.Converse_AmazonNovaText - - description: Send a conversation of messages to Amazon Nova using Bedrock's Converse API with a tool configuration. - genai: some - snippet_tags: - - Bedrock.ConverseTool.javascriptv3.SendConverseRequest - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API. - snippet_tags: - - bedrock-runtime.kotlin.Converse_AmazonNovaText - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API. - snippet_tags: - - BedrockRuntime.dotnetv3.Converse_AmazonNovaText - - description: Send a conversation of messages to Amazon Nova using Bedrock's Converse API with a tool configuration. - genai: some - snippet_tags: - - Bedrock.ConverseTool.dotnetv3.SendConverseRequest - PHP: - versions: - - sdk_version: 3 - github: php/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API. - snippet_tags: - - php.example_code.bedrock-runtime.service.Converse_AmazonNovaText - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API. - snippet_tags: - - python.example_code.bedrock-runtime.Converse_AmazonNovaText - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API. - snippet_tags: - - swift.example_code.bedrock-runtime.Converse_AmazonNovaText - services: - bedrock-runtime: {Converse} - -bedrock-runtime_Scenario_ToolUse: - title: "A tool use example illustrating how to connect AI models on &BR; with a custom tool or API" - title_abbrev: "Tool use with the Converse API" - synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." - category: Scenarios - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - snippet_tags: - - bedrock.converseTool.javav2.scenario - - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - genai: some - snippet_tags: - - bedrock.converseTool.javav2.weathertool - - description: "The Converse API action with a tool configuration." - genai: some - snippet_tags: - - bedrockruntime.java2.converse.main - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime/Scenarios/ConverseToolScenario - excerpts: - - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - genai: some - snippet_tags: - - Bedrock.ConverseTool.dotnetv3.Scenario - - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - genai: some - snippet_tags: - - Bedrock.ConverseTool.dotnetv3.WeatherTool - - description: "The Converse API action with a tool configuration." - genai: some - snippet_tags: - - Bedrock.ConverseTool.dotnetv3.SendConverseRequest - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime/scenarios/converse_tool_scenario - excerpts: - - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - genai: some - snippet_tags: - - Bedrock.ConverseTool.javascriptv3.Scenario - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: "The primary execution script of the demo. This script orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - snippet_files: - - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/tool_use_demo.py - - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - snippet_files: - - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/weather_tool.py - Rust: - versions: - - sdk_version: 1 - github: rustv1/examples/bedrock-runtime - excerpts: - - description: "The primary scenario and logic for the demo. This orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use - - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.weather-tool - - description: "Utilities to print the Message Content Blocks." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.user-interface - - description: "Use statements, Error utility, and constants." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.supporting - services: - bedrock-runtime: {Converse} - -bedrock-runtime_Converse_AnthropicClaude: - title: Invoke Anthropic Claude on &BR; using Bedrock's Converse API - title_abbrev: "Converse" - synopsis: send a text message to Anthropic Claude, using Bedrock's Converse API. - category: Anthropic Claude - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. - snippet_tags: - - bedrock-runtime.java2.Converse_AnthropicClaude - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API with the async Java client. - snippet_tags: - - bedrock-runtime.java2.ConverseAsync_AnthropicClaude - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. - snippet_tags: - - BedrockRuntime.dotnetv4.Converse_AnthropicClaude - Go: - versions: - - sdk_version: 2 - github: gov2/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. - snippet_tags: - - gov2.bedrock-runtime.Converse.struct - - gov2.bedrock-runtime.ConverseClaude - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. - snippet_tags: - - python.example_code.bedrock-runtime.Converse_AnthropicClaude - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. - snippet_tags: - - javascript.v3.bedrock-runtime.Converse_AnthropicClaude - Rust: - versions: - - sdk_version: 1 - github: rustv1/examples/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude - - description: Use statements, Error utility, and constants. - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.supporting - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. - snippet_tags: - - swift.example_code.bedrock-runtime.Converse_AnthropicClaude - services: - bedrock-runtime: {Converse} - -bedrock-runtime_Converse_CohereCommand: - title: Invoke Cohere Command on &BR; using Bedrock's Converse API - title_abbrev: "Converse" - synopsis: send a text message to Cohere Command, using Bedrock's Converse API. - category: Cohere Command - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API. - snippet_tags: - - bedrock-runtime.java2.Converse_CohereCommand - - description: Send a text message to Cohere Command, using Bedrock's Converse API with the async Java client. - snippet_tags: - - bedrock-runtime.java2.ConverseAsync_CohereCommand - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API. - snippet_tags: - - BedrockRuntime.dotnetv4.Converse_CohereCommand - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API. - snippet_tags: - - python.example_code.bedrock-runtime.Converse_CohereCommand - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API. - snippet_tags: - - javascript.v3.bedrock-runtime.Converse_CohereCommand - services: - bedrock-runtime: {Converse} - -bedrock-runtime_Converse_MetaLlama: - title: Invoke Meta Llama on &BR; using Bedrock's Converse API - title_abbrev: "Converse" - synopsis: send a text message to Meta Llama, using Bedrock's Converse API. - category: Meta Llama - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API. - snippet_tags: - - bedrock-runtime.java2.Converse_MetaLlama - - description: Send a text message to Meta Llama, using Bedrock's Converse API with the async Java client. - snippet_tags: - - bedrock-runtime.java2.ConverseAsync_MetaLlama - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API. - snippet_tags: - - BedrockRuntime.dotnetv4.Converse_MetaLlama - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API. - snippet_tags: - - python.example_code.bedrock-runtime.Converse_MetaLlama - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API. - snippet_tags: - - javascript.v3.bedrock-runtime.Converse_MetaLlama - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API. - snippet_tags: - - swift.example_code.bedrock-runtime.Converse_MetaLlama - services: - bedrock-runtime: {Converse} - -bedrock-runtime_Converse_Mistral: - title: Invoke Mistral on &BR; using Bedrock's Converse API - title_abbrev: "Converse" - synopsis: send a text message to Mistral, using Bedrock's Converse API. - category: Mistral AI - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API. - snippet_tags: - - bedrock-runtime.java2.Converse_Mistral - - description: Send a text message to Mistral, using Bedrock's Converse API with the async Java client. - snippet_tags: - - bedrock-runtime.java2.ConverseAsync_Mistral - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API. - snippet_tags: - - BedrockRuntime.dotnetv4.Converse_Mistral - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API. - snippet_tags: - - python.example_code.bedrock-runtime.Converse_Mistral - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API. - snippet_tags: - - javascript.v3.bedrock-runtime.Converse_Mistral - services: - bedrock-runtime: {Converse} - -# Converse Stream -bedrock-runtime_ConverseStream_AmazonNovaText: - title: Invoke Amazon Nova on &BR; using Bedrock's Converse API with a response stream - title_abbrev: "ConverseStream" - synopsis: send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. - category: Amazon Nova - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.ConverseStream_AmazonNovaText - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - javascript.v3.bedrock-runtime.ConverseStream_AmazonNovaText - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.kotlin.ConverseStream_AmazonNovaText - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv3.ConverseStream_AmazonNovaText - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - python.example_code.bedrock-runtime.ConverseStream_AmazonNovaText - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - swift.example_code.bedrock-runtime.ConverseStream_AmazonNovaText - services: - bedrock-runtime: {ConverseStream} - -bedrock-runtime_ConverseStream_AnthropicClaude: - title: Invoke Anthropic Claude on &BR; using Bedrock's Converse API with a response stream - title_abbrev: "ConverseStream" - synopsis: send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. - category: Anthropic Claude - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.ConverseStream_AnthropicClaude - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv4.ConverseStream_AnthropicClaude - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - python.example_code.bedrock-runtime.ConverseStream_AnthropicClaude - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - javascript.v3.bedrock-runtime.ConverseStream_AnthropicClaude - Rust: - versions: - - sdk_version: 1 - github: rustv1/examples/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude and stream reply tokens, using Bedrock's ConverseStream API. - snippet_tags: - - rust.bedrock-runtime.ConverseStream_AnthropicClaude - - description: Use statements, Error utility, and constants. - snippet_tags: - - rust.bedrock-runtime.ConverseStream_AnthropicClaude.supporting - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - swift.example_code.bedrock-runtime.ConverseStream_AnthropicClaude - services: - bedrock-runtime: {ConverseStream} - -bedrock-runtime_ConverseStream_CohereCommand: - title: Invoke Cohere Command on &BR; using Bedrock's Converse API with a response stream - title_abbrev: "ConverseStream" - synopsis: send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. - category: Cohere Command - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.ConverseStream_CohereCommand - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv4.ConverseStream_CohereCommand - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - python.example_code.bedrock-runtime.ConverseStream_CohereCommand - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - javascript.v3.bedrock-runtime.ConverseStream_CohereCommand - services: - bedrock-runtime: {ConverseStream} - -bedrock-runtime_ConverseStream_MetaLlama: - title: Invoke Meta Llama on &BR; using Bedrock's Converse API with a response stream - title_abbrev: "ConverseStream" - synopsis: send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. - category: Meta Llama languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.ConverseStream_MetaLlama - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv4.ConverseStream_MetaLlama - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - python.example_code.bedrock-runtime.ConverseStream_MetaLlama - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - javascript.v3.bedrock-runtime.ConverseStream_MetaLlama - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - swift.example_code.bedrock-runtime.ConverseStream_MetaLlama - services: - bedrock-runtime: {ConverseStream} - -bedrock-runtime_ConverseStream_Mistral: - title: Invoke Mistral on &BR; using Bedrock's Converse API with a response stream - title_abbrev: "ConverseStream" - synopsis: send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. - category: Mistral AI - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.ConverseStream_Mistral - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv4.ConverseStream_Mistral - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - python.example_code.bedrock-runtime.ConverseStream_Mistral - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. - snippet_tags: - - javascript.v3.bedrock-runtime.ConverseStream_Mistral - services: - bedrock-runtime: {ConverseStream} - -# Invoke Model -bedrock-runtime_InvokeModel_AnthropicClaude: - title: Invoke Anthropic Claude on &BR; using the Invoke Model API - title_abbrev: "InvokeModel" - synopsis: send a text message to Anthropic Claude, using the Invoke Model API. - category: Anthropic Claude - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_AnthropicClaude - .NET: - versions: - - sdk_version: 4 - github: dotnetv4/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - BedrockRuntime.dotnetv4.InvokeModel_AnthropicClaude - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_AnthropicClaude - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_files: - - javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js - Go: - versions: - - sdk_version: 2 - github: gov2/bedrock-runtime - excerpts: - - description: Invoke the Anthropic Claude 2 foundation model to generate text. - snippet_tags: - - gov2.bedrock-runtime.InvokeModelWrapper.struct - - gov2.bedrock-runtime.InvokeClaude - PHP: - versions: - - sdk_version: 3 - github: php/example_code/bedrock-runtime - excerpts: - - description: Invoke the Anthropic Claude 2 foundation model to generate text. - snippet_tags: - - php.example_code.bedrock-runtime.service.invokeClaude - SAP ABAP: - versions: - - sdk_version: 1 - github: sap-abap/services/bdr - excerpts: - - description: Invoke the Anthropic Claude 2 foundation model to generate text. This example uses features of - /US2/CL_JSON which might not be available on some NetWeaver versions. - snippet_tags: - - bdr.abapv1.invokemodel_claude_v2 - - description: Invoke the Anthropic Claude 2 foundation model to generate text using L2 high level client. - snippet_tags: - - bdr.abapv1.invokemodel_l2_claude_v2 - - description: Invoke the Anthropic Claude 3 foundation model to generate text using L2 high level client. - snippet_tags: - - bdr.abapv1.invokemodel_l2_claude_v3 - services: - bedrock-runtime: {InvokeModel} - -bedrock-runtime_InvokeModel_CohereCommandR: - title: Invoke Cohere Command R and R+ on &BR; using the Invoke Model API - title_abbrev: "InvokeModel: Command R and R+" - synopsis: send a text message to Cohere Command R and R+, using the Invoke Model API. - category: Cohere Command - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_CohereCommandR - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModel_CohereCommandR - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_CohereCommandR - services: - bedrock-runtime: {InvokeModel} - -bedrock-runtime_InvokeModel_MetaLlama3: - title: Invoke Meta Llama on &BR; using the Invoke Model API - title_abbrev: "InvokeModel" - synopsis: send a text message to Meta Llama, using the Invoke Model API. - category: Meta Llama - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_MetaLlama3 - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModel_MetaLlama3 - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_MetaLlama3 - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - javascript.v3.bedrock-runtime.InvokeModel_Llama3_Quickstart - services: - bedrock-runtime: {InvokeModel} - -bedrock-runtime_InvokeModel_MistralAi: - title: Invoke Mistral AI models on &BR; using the Invoke Model API - title_abbrev: "InvokeModel" - synopsis: send a text message to Mistral models, using the Invoke Model API. - category: Mistral AI - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_Mistral - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModel_Mistral - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_MistralAi - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. - snippet_files: - - javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mistral_7b.js - services: - bedrock-runtime: {InvokeModel} - -# Invoke Model with Response Stream -bedrock-runtime_InvokeModelWithResponseStream_AnthropicClaude: - title: Invoke Anthropic Claude models on &BR; using the Invoke Model API with a response stream - title_abbrev: "InvokeModelWithResponseStream" - synopsis: send a text message to Anthropic Claude models, using the Invoke Model API, and print the response stream. - category: Anthropic Claude - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.InvokeModelWithResponseStream_AnthropicClaude - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_AnthropicClaude - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_AnthropicClaude - Go: - versions: - - sdk_version: 2 - github: gov2/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + - description: snippet_tags: - - gov2.bedrock-runtime.InvokeModelWithResponseStreamWrapper.struct - - gov2.bedrock-runtime.InvokeModelWithResponseStream - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_files: - - javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js + - inspector.java2.hello.main services: - bedrock-runtime: {InvokeModelWithResponseStream} - -bedrock-runtime_InvokeModelWithResponseStream_CohereCommandR: - title: Invoke Cohere Command R and R+ on &BR; using the Invoke Model API with a response stream - title_abbrev: "InvokeModelWithResponseStream: Command R and R+" - synopsis: send a text message to Cohere Command, using the Invoke Model API with a response stream. - category: Cohere Command + inspector: {BatchGetAccountStatus, ListFindings, ListUsageTotals} +inspector_BatchGetFindingDetails: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.InvokeModelWithResponseStream_CohereCommandR - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_CohereCommandR - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + - description: snippet_tags: - - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_CohereCommandR + - inspector.java2.finding.details.main services: - bedrock-runtime: {InvokeModel} - -bedrock-runtime_InvokeModelWithResponseStream_MetaLlama3: - title: Invoke Meta Llama on &BR; using the Invoke Model API with a response stream - title_abbrev: "InvokeModelWithResponseStream" - synopsis: send a text message to Meta Llama, using the Invoke Model API, and print the response stream. - category: Meta Llama + inspector: {BatchGetFindingDetails} +inspector_DeleteFilter: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.InvokeModelWithResponseStream_MetaLlama3 - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_MetaLlama3 - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_MetaLlama3 - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + - description: snippet_tags: - - javascript.v3.bedrock-runtime.InvokeModelWithResponseStream_Llama3_Quickstart + - inspector.java2.delete.filter.main services: - bedrock-runtime: {InvokeModelWithResponseStream} - -bedrock-runtime_InvokeModelWithResponseStream_MistralAi: - title: Invoke Mistral AI models on &BR; using the Invoke Model API with a response stream - title_abbrev: "InvokeModelWithResponseStream" - synopsis: send a text message to Mistral AI models, using the Invoke Model API, and print the response stream. - category: Mistral AI + inspector: {DeleteFilter} +inspector_EnableInspector: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - bedrock-runtime.java2.InvokeModelWithResponseStream_Mistral - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_Mistral - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + - description: snippet_tags: - - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_MistralAi + - inspector.java2.enable.main services: - bedrock-runtime: {InvokeModelWithResponseStream} - -# Reasoning -bedrock-runtime_Converse_AnthropicClaudeReasoning: - title: Use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; - title_abbrev: Reasoning - synopsis: use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; - category: Anthropic Claude + inspector: {Enable} +inspector_CreateFilter: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Use Anthropic Claude 3.7 Sonnet's reasoning capability with the asynchronous Bedrock runtime client. - snippet_tags: - - bedrock-runtime.java2.ConverseAsync_AnthropicClaudeReasoning - - description: Use Anthropic Claude 3.7 Sonnet's reasoning capability with the synchronous Bedrock runtime client. + - description: snippet_tags: - - bedrock-runtime.java2.Converse_AnthropicClaudeReasoning + - inspector.java2.create.filter.main services: - bedrock-runtime: {Converse} - -bedrock-runtime_ConverseStream_AnthropicClaudeReasoning: - title: Use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; - title_abbrev: Reasoning with a streaming response - synopsis: use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; - category: Anthropic Claude + inspector: {CreateFilter} +inspector_GetAccountStatus: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Use Anthropic Claude 3.7 Sonnet's reasoning capability to generate streaming text responses. + - description: snippet_tags: - - bedrock-runtime.java2.ConverseStream_AnthropicClaudeReasoning + - inspector.java2.get_account_status.main services: - bedrock-runtime: {Converse} - -# Image Generation Models -bedrock-runtime_InvokeModel_AmazonNovaImageGeneration: - title: Invoke Amazon Nova Canvas on &BR; to generate an image - title_abbrev: "InvokeModel" - synopsis: invoke Amazon Nova Canvas on &BR; to generate an image. - category: Amazon Nova Canvas + inspector: {BatchGetAccountStatus} +inspector_ListFindings: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Create an image with Amazon Nova Canvas. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_AmazonNovaImageGeneration - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime - excerpts: - - description: Create an image with Amazon Nova Canvas. - snippet_tags: - - javascript.v3.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime - excerpts: - - description: Create an image with Amazon Nova Canvas. - snippet_tags: - - BedrockRuntime.dotnetv3.InvokeModel_AmazonNovaImageGeneration - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Create an image with the Amazon Nova Canvas. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Create an image with Amazon Nova Canvas. + - description: snippet_tags: - - swift.example_code.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration + - inspector.java2.list_findings.main services: - bedrock-runtime: {InvokeModel} - -bedrock-runtime_InvokeModel_TitanImageGenerator: - title: Invoke Amazon Titan Image on &BR; to generate an image - title_abbrev: "InvokeModel" - synopsis: invoke Amazon Titan Image on &BR; to generate an image. - category: Amazon Titan Image Generator + inspector: {ListFindings} +inspector_ListCoverageStatistics: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: Create an image with the Amazon Titan Image Generator. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_AmazonTitanImage - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Create an image with the Amazon Titan Image Generator. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_TitanImageGenerator - Go: - versions: - - sdk_version: 2 - github: gov2/bedrock-runtime - excerpts: - - description: Create an image with the Amazon Titan Image Generator. - snippet_tags: - - gov2.bedrock-runtime.InvokeModelWrapper.struct - - gov2.bedrock-runtime.InvokeTitanImage - PHP: - versions: - - sdk_version: 3 - github: php/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Create an image with the Amazon Titan Image Generator. + - description: snippet_tags: - - php.example_code.bedrock-runtime.service.invokeTitanImage + - inspector.java2.list_coverage.stats.main services: - bedrock-runtime: {InvokeModel} - -bedrock-runtime_InvokeModel_StableDiffusion: - title: Invoke Stability.ai Stable Diffusion XL on &BR; to generate an image - title_abbrev: "InvokeModel" - synopsis: invoke Stability.ai Stable Diffusion XL on &BR; to generate an image. - category: Stable Diffusion + inspector: {ListCoverageStatistics} +inspector_ListCoverage: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Create an image with Stable Diffusion. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_StableDiffusion - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Create an image with Stable Diffusion. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_StableDiffusion - PHP: - versions: - - sdk_version: 3 - github: php/example_code/bedrock-runtime - excerpts: - - description: Create an image with Stable Diffusion. - snippet_tags: - - php.example_code.bedrock-runtime.service.invokeStableDiffusion - SAP ABAP: - versions: - - sdk_version: 1 - github: sap-abap/services/bdr - excerpts: - - description: Create an image with Stable Diffusion. - snippet_tags: - - bdr.abapv1.invokemodel_stable_diffusion - - description: Invoke the Stability.ai Stable Diffusion XL foundation model to generate images using L2 high level - client. - snippet_tags: - - bdr.abapv1.invokemodel_l2_stable_diffusion - services: - bedrock-runtime: {InvokeModel} - -# Video Generation Models -bedrock-runtime_Scenario_AmazonNova_TextToVideo: - title: Use Amazon Nova Reel to generate a video from a text prompt - title_abbrev: "Text-to-video" - synopsis: use Amazon Nova Reel to generate a video from a text prompt. - category: Amazon Nova Reel - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use Amazon Nova Reel to generate a video from a text prompt. - snippet_tags: - - python.example_code.bedrock-runtime.Scenario_AmazonNova_TextToVideo - Swift: - versions: - - sdk_version: 1 - github: swift/example_code/bedrock-runtime - excerpts: - - description: Use Amazon Nova Reel to generate a video from a text prompt. + - description: snippet_tags: - - swift.example_code.bedrock-runtime.Scenario_AmazonNova_TextToVideo + - inspector.java2.list_coverage.main services: - bedrock-runtime: {GetAsyncInvoke, StartAsyncInvoke} - -# Embedding Models -bedrock-runtime_InvokeModelWithResponseStream_TitanTextEmbeddings: - title: Invoke Amazon Titan Text Embeddings on &BR; - title_abbrev: "InvokeModel" - synopsis_list: - - Get started creating your first embedding. - - Create embeddings configuring the number of dimensions and normalization (V2 only). - category: Amazon Titan Text Embeddings + inspector: {ListCoverage} +inspector_ListUsageTotals: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Create your first embedding with Titan Text Embeddings V2. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_TitanTextEmbeddings - - description: Invoke Titan Text Embeddings V2 configuring the number of dimensions and normalization. - snippet_tags: - - bedrock-runtime.java2.InvokeModel_TitanTextEmbeddings_AdditionalFields - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Create your first embedding with Amazon Titan Text Embeddings. - snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_TitanTextEmbeddings - services: - bedrock-runtime: {InvokeModel} - -# Document understanding -bedrock-runtime_DocumentUnderstanding_AmazonNova: - title: Send and process a document with Amazon Nova on &BR; - title_abbrev: "Document understanding" - synopsis: send and process a document with Amazon Nova on &BR;. - category: Amazon Nova - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send and process a document with Amazon Nova on &BR;. - snippet_tags: - - python.example_code.bedrock-runtime.DocumentUnderstanding_AmazonNovaText - services: - bedrock-runtime: {Converse} - -bedrock-runtime_DocumentUnderstanding_AnthropicClaude: - title: Send and process a document with Anthropic Claude on &BR; - title_abbrev: "Document understanding" - synopsis: send and process a document with Anthropic Claude on &BR;. - category: Anthropic Claude - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send and process a document with Anthropic Claude on &BR;. - snippet_tags: - - python.example_code.bedrock-runtime.DocumentUnderstanding_AnthropicClaude - services: - bedrock-runtime: {Converse} - -bedrock-runtime_DocumentUnderstanding_CohereCommand: - title: Send and process a document with Cohere Command models on &BR; - title_abbrev: "Document understanding" - synopsis: send and process a document with Cohere Command models on &BR;. - category: Cohere Command - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send and process a document with Cohere Command models on &BR;. - snippet_tags: - - python.example_code.bedrock-runtime.DocumentUnderstanding_CohereCommand - services: - bedrock-runtime: {Converse} - -bedrock-runtime_DocumentUnderstanding_DeepSeek: - title: Send and process a document with DeepSeek on &BR; - title_abbrev: "Document understanding" - synopsis: send and process a document with DeepSeek on &BR;. - category: DeepSeek - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send and process a document with DeepSeek on &BR;. - snippet_tags: - - python.example_code.bedrock-runtime.DocumentUnderstanding_DeepSeek - services: - bedrock-runtime: {Converse} - -bedrock-runtime_DocumentUnderstanding_MetaLlama: - title: Send and process a document with Llama on &BR; - title_abbrev: "Document understanding" - synopsis: send and process a document with Llama on &BR;. - category: Meta Llama - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send and process a document with Llama on &BR;. - snippet_tags: - - python.example_code.bedrock-runtime.DocumentUnderstanding_MetaLlama - services: - bedrock-runtime: {Converse} - -bedrock-runtime_DocumentUnderstanding_Mistral: - title: Send and process a document with Mistral models on &BR; - title_abbrev: "Document understanding" - synopsis: send and process a document with Mistral models on &BR;. - category: Mistral AI - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Send and process a document with Mistral models on &BR;. + - description: snippet_tags: - - python.example_code.bedrock-runtime.DocumentUnderstanding_Mistral + - inspector.java2.list_usage_totals.main services: - bedrock-runtime: {Converse} - -# Tool use scenarios -bedrock-runtime_Scenario_ToolUseDemo_AmazonNova: - title: "A tool use demo illustrating how to connect AI models on &BR; with a custom tool or API" - title_abbrev: "Scenario: Tool use with the Converse API" - synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." - category: Amazon Nova + inspector: {ListUsageTotals} +inspector_ListFilters: languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime - excerpts: - - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - snippet_tags: - - bedrock.converseTool.javav2.scenario - - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - genai: some - snippet_tags: - - bedrock.converseTool.javav2.weathertool - - description: "The Converse API action with a tool configuration." - genai: some - snippet_tags: - - bedrockruntime.java2.converse.main - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/Bedrock-runtime/Scenarios/ConverseToolScenario - excerpts: - - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - genai: some - snippet_tags: - - Bedrock.ConverseTool.dotnetv3.Scenario - - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - genai: some - snippet_tags: - - Bedrock.ConverseTool.dotnetv3.WeatherTool - - description: "The Converse API action with a tool configuration." - genai: some - snippet_tags: - - Bedrock.ConverseTool.dotnetv3.SendConverseRequest - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime/scenarios/converse_tool_scenario - excerpts: - - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - genai: some - snippet_tags: - - Bedrock.ConverseTool.javascriptv3.Scenario - services: - bedrock-runtime: {Converse} - -bedrock-runtime_Scenario_ToolUseDemo_AnthropicClaude: - title: "A tool use demo illustrating how to connect AI models on &BR; with a custom tool or API" - title_abbrev: "Scenario: Tool use with the Converse API" - synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." - category: Anthropic Claude - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: "The primary execution script of the demo. This script orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - snippet_files: - - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/tool_use_demo.py - - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - snippet_files: - - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/weather_tool.py - Rust: - versions: - - sdk_version: 1 - github: rustv1/examples/bedrock-runtime - excerpts: - - description: "The primary scenario and logic for the demo. This orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use - - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.weather-tool - - description: "Utilities to print the Message Content Blocks." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.user-interface - - description: "Use statements, Error utility, and constants." - snippet_tags: - - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.supporting - services: - bedrock-runtime: {Converse} - -bedrock-runtime_Scenario_ToolUseDemo_CohereCommand: - title: "A tool use demo illustrating how to connect AI models on &BR; with a custom tool or API" - title_abbrev: "Scenario: Tool use with the Converse API" - synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." - category: Cohere Command - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: "The primary execution script of the demo. This script orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." - snippet_files: - - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/tool_use_demo.py - - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." - snippet_files: - - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/weather_tool.py - services: - bedrock-runtime: {Converse} - -# Other scenarios -bedrock-runtime_Scenario_InvokeModels: - title: Invoke multiple foundation models on &BR; - title_abbrev: "Invoke multiple foundation models on &BR;" - synopsis: prepare and send a prompt to a variety of large-language models (LLMs) on &BR; - category: Scenarios - languages: - Go: - versions: - - sdk_version: 2 - github: gov2/bedrock-runtime - excerpts: - - description: Invoke multiple foundation models on &BR;. - snippet_tags: - - gov2.bedrock-runtime.Scenario_InvokeModels - JavaScript: - versions: - - sdk_version: 3 - github: javascriptv3/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - description: - snippet_files: - - javascriptv3/example_code/bedrock-runtime/scenarios/cli_text_playground.js - PHP: - versions: - - sdk_version: 3 - github: php/example_code/bedrock-runtime/ - excerpts: - - description: Invoke multiple LLMs on &BR;. snippet_tags: - - php.example_code.bedrock-runtime.basics.scenario + - inspector.java2.list_filters.main services: - bedrock-runtime: {InvokeModel, InvokeModelWithResponseStream} - -bedrock-runtime_Scenario_GenerateVideos_NovaReel: - title: Generate videos from text prompts using &BR; and Nova-Reel - title_abbrev: "Generate videos from text prompts using &BR;" - synopsis: a Spring Boot app that generates videos from text prompts using &BR; and the Nova-Reel model. - category: Scenarios + inspector: {ListFilters} +inspector_Scenario: + synopsis_list: + - Check Inspector account status. + - Ensure Inspector is enabled. + - Analyze security findings. + - Check scan coverage. + - Create a findings filter. + - List existing filters. + - Check usage and costs. + - Get coverage statistics. + - Delete a filter. + category: Basics languages: Java: versions: - sdk_version: 2 - github: javav2/example_code/bedrock-runtime + github: javav2/example_code/inspector + sdkguide: excerpts: - - description: Generate videos from text prompts using &BR; and Nova-Reel. + - description: Run an interactive scenario demonstrating &Inspector; features. snippet_tags: - - bedrock-runtime.java2.NovaReel.VideoGeneration - services: - bedrock-runtime: {StartAsyncInvoke, GetAsyncInvoke} - -bedrock-runtime_InvokeModel_TitanText: - title: Invoke Amazon Titan Text models on &BR; using the Invoke Model API - title_abbrev: "InvokeModel" - synopsis: send a text message to Amazon Titan Text, using the Invoke Model API. - category: Amazon Titan Text - languages: - Python: - versions: - - sdk_version: 3 - github: python/example_code/bedrock-runtime - excerpts: - - description: Use the Invoke Model API to send a text message. + - inspector.java2_scenario.main + - description: A wrapper class for &Inspector; SDK methods. snippet_tags: - - python.example_code.bedrock-runtime.InvokeModel_TitanText + - inspector.java2_actions.main services: - bedrock-runtime: {InvokeModel} + inspector: {BatchGetAccountStatus, BatchGetFindingDetails, DeleteFilter, Enable, ListFindings, ListCoverage, CreateFilter, ListFilters, ListUsageTotals, ListCoverageStatistics} From 7c7020e33dcbdb923d8ee705a4f8bcfd06563cf8 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 10:32:29 -0500 Subject: [PATCH 11/28] Remove generated bedrock metadata from PR --- .../metadata/bedrock-runtime_metadata.yaml | 175 ------------------ 1 file changed, 175 deletions(-) delete mode 100644 .doc_gen/metadata/bedrock-runtime_metadata.yaml diff --git a/.doc_gen/metadata/bedrock-runtime_metadata.yaml b/.doc_gen/metadata/bedrock-runtime_metadata.yaml deleted file mode 100644 index d376516b981..00000000000 --- a/.doc_gen/metadata/bedrock-runtime_metadata.yaml +++ /dev/null @@ -1,175 +0,0 @@ -# zexi 0.4.2 -inspector_Hello: - title: Hello &Inspector; - title_abbrev: Hello &Inspector; - synopsis: get started using &Inspector;. - category: Hello - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.hello.main - services: - inspector: {BatchGetAccountStatus, ListFindings, ListUsageTotals} -inspector_BatchGetFindingDetails: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.finding.details.main - services: - inspector: {BatchGetFindingDetails} -inspector_DeleteFilter: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.delete.filter.main - services: - inspector: {DeleteFilter} -inspector_EnableInspector: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.enable.main - services: - inspector: {Enable} -inspector_CreateFilter: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.create.filter.main - services: - inspector: {CreateFilter} -inspector_GetAccountStatus: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.get_account_status.main - services: - inspector: {BatchGetAccountStatus} -inspector_ListFindings: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.list_findings.main - services: - inspector: {ListFindings} -inspector_ListCoverageStatistics: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.list_coverage.stats.main - services: - inspector: {ListCoverageStatistics} -inspector_ListCoverage: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.list_coverage.main - services: - inspector: {ListCoverage} -inspector_ListUsageTotals: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.list_usage_totals.main - services: - inspector: {ListUsageTotals} -inspector_ListFilters: - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: - snippet_tags: - - inspector.java2.list_filters.main - services: - inspector: {ListFilters} -inspector_Scenario: - synopsis_list: - - Check Inspector account status. - - Ensure Inspector is enabled. - - Analyze security findings. - - Check scan coverage. - - Create a findings filter. - - List existing filters. - - Check usage and costs. - - Get coverage statistics. - - Delete a filter. - category: Basics - languages: - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/inspector - sdkguide: - excerpts: - - description: Run an interactive scenario demonstrating &Inspector; features. - snippet_tags: - - inspector.java2_scenario.main - - description: A wrapper class for &Inspector; SDK methods. - snippet_tags: - - inspector.java2_actions.main - services: - inspector: {BatchGetAccountStatus, BatchGetFindingDetails, DeleteFilter, Enable, ListFindings, ListCoverage, CreateFilter, ListFilters, ListUsageTotals, ListCoverageStatistics} From 106fb27c7236c501cfde05d97caccdb6d76315e0 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 10:42:04 -0500 Subject: [PATCH 12/28] Restore bedrock runtime metadata file (not part of this PR) --- .../metadata/bedrock-runtime_metadata.yaml | 1502 +++++++++++++++++ 1 file changed, 1502 insertions(+) create mode 100644 .doc_gen/metadata/bedrock-runtime_metadata.yaml diff --git a/.doc_gen/metadata/bedrock-runtime_metadata.yaml b/.doc_gen/metadata/bedrock-runtime_metadata.yaml new file mode 100644 index 00000000000..761fe7b7c9b --- /dev/null +++ b/.doc_gen/metadata/bedrock-runtime_metadata.yaml @@ -0,0 +1,1502 @@ +# zexi 0.4.0 +bedrock-runtime_Hello: + title: Hello &BR; + title_abbrev: Hello &BR; + synopsis: get started using &BR;. + category: Hello + languages: + Go: + versions: + - sdk_version: 2 + github: gov2/bedrock-runtime + excerpts: + - description: + snippet_tags: + - gov2.bedrock-runtime.Hello + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: + snippet_files: + - javascriptv3/example_code/bedrock-runtime/hello.js + + services: + bedrock-runtime: {InvokeModel} + +# Converse +bedrock-runtime_Converse_AmazonNovaText: + title: Invoke Amazon Nova on &BR; using Bedrock's Converse API + title_abbrev: "Converse" + synopsis: send a text message to Amazon Nova, using Bedrock's Converse API. + category: Amazon Nova + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova using Bedrock's Converse API with the async Java client. + snippet_tags: + - bedrock-runtime.java2.ConverseAsync_AmazonNovaText + - description: Send a text message to Amazon Nova, using Bedrock's Converse API. + snippet_tags: + - bedrock-runtime.java2.Converse_AmazonNovaText + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API. + snippet_tags: + - javascript.v3.bedrock-runtime.Converse_AmazonNovaText + - description: Send a conversation of messages to Amazon Nova using Bedrock's Converse API with a tool configuration. + genai: some + snippet_tags: + - Bedrock.ConverseTool.javascriptv3.SendConverseRequest + Kotlin: + versions: + - sdk_version: 1 + github: kotlin/services/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API. + snippet_tags: + - bedrock-runtime.kotlin.Converse_AmazonNovaText + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API. + snippet_tags: + - BedrockRuntime.dotnetv3.Converse_AmazonNovaText + - description: Send a conversation of messages to Amazon Nova using Bedrock's Converse API with a tool configuration. + genai: some + snippet_tags: + - Bedrock.ConverseTool.dotnetv3.SendConverseRequest + PHP: + versions: + - sdk_version: 3 + github: php/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API. + snippet_tags: + - php.example_code.bedrock-runtime.service.Converse_AmazonNovaText + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API. + snippet_tags: + - python.example_code.bedrock-runtime.Converse_AmazonNovaText + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API. + snippet_tags: + - swift.example_code.bedrock-runtime.Converse_AmazonNovaText + services: + bedrock-runtime: {Converse} + +bedrock-runtime_Scenario_ToolUse: + title: "A tool use example illustrating how to connect AI models on &BR; with a custom tool or API" + title_abbrev: "Tool use with the Converse API" + synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." + category: Scenarios + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + snippet_tags: + - bedrock.converseTool.javav2.scenario + - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + genai: some + snippet_tags: + - bedrock.converseTool.javav2.weathertool + - description: "The Converse API action with a tool configuration." + genai: some + snippet_tags: + - bedrockruntime.java2.converse.main + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime/Scenarios/ConverseToolScenario + excerpts: + - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + genai: some + snippet_tags: + - Bedrock.ConverseTool.dotnetv3.Scenario + - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + genai: some + snippet_tags: + - Bedrock.ConverseTool.dotnetv3.WeatherTool + - description: "The Converse API action with a tool configuration." + genai: some + snippet_tags: + - Bedrock.ConverseTool.dotnetv3.SendConverseRequest + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime/scenarios/converse_tool_scenario + excerpts: + - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + genai: some + snippet_tags: + - Bedrock.ConverseTool.javascriptv3.Scenario + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: "The primary execution script of the demo. This script orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + snippet_files: + - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/tool_use_demo.py + - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + snippet_files: + - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/weather_tool.py + Rust: + versions: + - sdk_version: 1 + github: rustv1/examples/bedrock-runtime + excerpts: + - description: "The primary scenario and logic for the demo. This orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use + - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.weather-tool + - description: "Utilities to print the Message Content Blocks." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.user-interface + - description: "Use statements, Error utility, and constants." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.supporting + services: + bedrock-runtime: {Converse} + +bedrock-runtime_Converse_AnthropicClaude: + title: Invoke Anthropic Claude on &BR; using Bedrock's Converse API + title_abbrev: "Converse" + synopsis: send a text message to Anthropic Claude, using Bedrock's Converse API. + category: Anthropic Claude + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. + snippet_tags: + - bedrock-runtime.java2.Converse_AnthropicClaude + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API with the async Java client. + snippet_tags: + - bedrock-runtime.java2.ConverseAsync_AnthropicClaude + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. + snippet_tags: + - BedrockRuntime.dotnetv4.Converse_AnthropicClaude + Go: + versions: + - sdk_version: 2 + github: gov2/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. + snippet_tags: + - gov2.bedrock-runtime.Converse.struct + - gov2.bedrock-runtime.ConverseClaude + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. + snippet_tags: + - python.example_code.bedrock-runtime.Converse_AnthropicClaude + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. + snippet_tags: + - javascript.v3.bedrock-runtime.Converse_AnthropicClaude + Rust: + versions: + - sdk_version: 1 + github: rustv1/examples/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude + - description: Use statements, Error utility, and constants. + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.supporting + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API. + snippet_tags: + - swift.example_code.bedrock-runtime.Converse_AnthropicClaude + services: + bedrock-runtime: {Converse} + +bedrock-runtime_Converse_CohereCommand: + title: Invoke Cohere Command on &BR; using Bedrock's Converse API + title_abbrev: "Converse" + synopsis: send a text message to Cohere Command, using Bedrock's Converse API. + category: Cohere Command + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API. + snippet_tags: + - bedrock-runtime.java2.Converse_CohereCommand + - description: Send a text message to Cohere Command, using Bedrock's Converse API with the async Java client. + snippet_tags: + - bedrock-runtime.java2.ConverseAsync_CohereCommand + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API. + snippet_tags: + - BedrockRuntime.dotnetv4.Converse_CohereCommand + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API. + snippet_tags: + - python.example_code.bedrock-runtime.Converse_CohereCommand + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API. + snippet_tags: + - javascript.v3.bedrock-runtime.Converse_CohereCommand + services: + bedrock-runtime: {Converse} + +bedrock-runtime_Converse_MetaLlama: + title: Invoke Meta Llama on &BR; using Bedrock's Converse API + title_abbrev: "Converse" + synopsis: send a text message to Meta Llama, using Bedrock's Converse API. + category: Meta Llama + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API. + snippet_tags: + - bedrock-runtime.java2.Converse_MetaLlama + - description: Send a text message to Meta Llama, using Bedrock's Converse API with the async Java client. + snippet_tags: + - bedrock-runtime.java2.ConverseAsync_MetaLlama + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API. + snippet_tags: + - BedrockRuntime.dotnetv4.Converse_MetaLlama + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API. + snippet_tags: + - python.example_code.bedrock-runtime.Converse_MetaLlama + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API. + snippet_tags: + - javascript.v3.bedrock-runtime.Converse_MetaLlama + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API. + snippet_tags: + - swift.example_code.bedrock-runtime.Converse_MetaLlama + services: + bedrock-runtime: {Converse} + +bedrock-runtime_Converse_Mistral: + title: Invoke Mistral on &BR; using Bedrock's Converse API + title_abbrev: "Converse" + synopsis: send a text message to Mistral, using Bedrock's Converse API. + category: Mistral AI + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API. + snippet_tags: + - bedrock-runtime.java2.Converse_Mistral + - description: Send a text message to Mistral, using Bedrock's Converse API with the async Java client. + snippet_tags: + - bedrock-runtime.java2.ConverseAsync_Mistral + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API. + snippet_tags: + - BedrockRuntime.dotnetv4.Converse_Mistral + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API. + snippet_tags: + - python.example_code.bedrock-runtime.Converse_Mistral + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API. + snippet_tags: + - javascript.v3.bedrock-runtime.Converse_Mistral + services: + bedrock-runtime: {Converse} + +# Converse Stream +bedrock-runtime_ConverseStream_AmazonNovaText: + title: Invoke Amazon Nova on &BR; using Bedrock's Converse API with a response stream + title_abbrev: "ConverseStream" + synopsis: send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. + category: Amazon Nova + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.ConverseStream_AmazonNovaText + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - javascript.v3.bedrock-runtime.ConverseStream_AmazonNovaText + Kotlin: + versions: + - sdk_version: 1 + github: kotlin/services/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.kotlin.ConverseStream_AmazonNovaText + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv3.ConverseStream_AmazonNovaText + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.ConverseStream_AmazonNovaText + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Amazon Nova, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - swift.example_code.bedrock-runtime.ConverseStream_AmazonNovaText + services: + bedrock-runtime: {ConverseStream} + +bedrock-runtime_ConverseStream_AnthropicClaude: + title: Invoke Anthropic Claude on &BR; using Bedrock's Converse API with a response stream + title_abbrev: "ConverseStream" + synopsis: send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. + category: Anthropic Claude + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.ConverseStream_AnthropicClaude + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv4.ConverseStream_AnthropicClaude + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.ConverseStream_AnthropicClaude + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - javascript.v3.bedrock-runtime.ConverseStream_AnthropicClaude + Rust: + versions: + - sdk_version: 1 + github: rustv1/examples/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude and stream reply tokens, using Bedrock's ConverseStream API. + snippet_tags: + - rust.bedrock-runtime.ConverseStream_AnthropicClaude + - description: Use statements, Error utility, and constants. + snippet_tags: + - rust.bedrock-runtime.ConverseStream_AnthropicClaude.supporting + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Anthropic Claude, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - swift.example_code.bedrock-runtime.ConverseStream_AnthropicClaude + services: + bedrock-runtime: {ConverseStream} + +bedrock-runtime_ConverseStream_CohereCommand: + title: Invoke Cohere Command on &BR; using Bedrock's Converse API with a response stream + title_abbrev: "ConverseStream" + synopsis: send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. + category: Cohere Command + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.ConverseStream_CohereCommand + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv4.ConverseStream_CohereCommand + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.ConverseStream_CohereCommand + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Cohere Command, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - javascript.v3.bedrock-runtime.ConverseStream_CohereCommand + services: + bedrock-runtime: {ConverseStream} + +bedrock-runtime_ConverseStream_MetaLlama: + title: Invoke Meta Llama on &BR; using Bedrock's Converse API with a response stream + title_abbrev: "ConverseStream" + synopsis: send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. + category: Meta Llama + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.ConverseStream_MetaLlama + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv4.ConverseStream_MetaLlama + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.ConverseStream_MetaLlama + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - javascript.v3.bedrock-runtime.ConverseStream_MetaLlama + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Meta Llama, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - swift.example_code.bedrock-runtime.ConverseStream_MetaLlama + services: + bedrock-runtime: {ConverseStream} + +bedrock-runtime_ConverseStream_Mistral: + title: Invoke Mistral on &BR; using Bedrock's Converse API with a response stream + title_abbrev: "ConverseStream" + synopsis: send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. + category: Mistral AI + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.ConverseStream_Mistral + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv4.ConverseStream_Mistral + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.ConverseStream_Mistral + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Send a text message to Mistral, using Bedrock's Converse API and process the response stream in real-time. + snippet_tags: + - javascript.v3.bedrock-runtime.ConverseStream_Mistral + services: + bedrock-runtime: {ConverseStream} + +# Invoke Model +bedrock-runtime_InvokeModel_AnthropicClaude: + title: Invoke Anthropic Claude on &BR; using the Invoke Model API + title_abbrev: "InvokeModel" + synopsis: send a text message to Anthropic Claude, using the Invoke Model API. + category: Anthropic Claude + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_AnthropicClaude + .NET: + versions: + - sdk_version: 4 + github: dotnetv4/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - BedrockRuntime.dotnetv4.InvokeModel_AnthropicClaude + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_AnthropicClaude + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_files: + - javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js + Go: + versions: + - sdk_version: 2 + github: gov2/bedrock-runtime + excerpts: + - description: Invoke the Anthropic Claude 2 foundation model to generate text. + snippet_tags: + - gov2.bedrock-runtime.InvokeModelWrapper.struct + - gov2.bedrock-runtime.InvokeClaude + PHP: + versions: + - sdk_version: 3 + github: php/example_code/bedrock-runtime + excerpts: + - description: Invoke the Anthropic Claude 2 foundation model to generate text. + snippet_tags: + - php.example_code.bedrock-runtime.service.invokeClaude + SAP ABAP: + versions: + - sdk_version: 1 + github: sap-abap/services/bdr + excerpts: + - description: Invoke the Anthropic Claude 2 foundation model to generate text. This example uses features of + /US2/CL_JSON which might not be available on some NetWeaver versions. + snippet_tags: + - bdr.abapv1.invokemodel_claude_v2 + - description: Invoke the Anthropic Claude 2 foundation model to generate text using L2 high level client. + snippet_tags: + - bdr.abapv1.invokemodel_l2_claude_v2 + - description: Invoke the Anthropic Claude 3 foundation model to generate text using L2 high level client. + snippet_tags: + - bdr.abapv1.invokemodel_l2_claude_v3 + services: + bedrock-runtime: {InvokeModel} + +bedrock-runtime_InvokeModel_CohereCommandR: + title: Invoke Cohere Command R and R+ on &BR; using the Invoke Model API + title_abbrev: "InvokeModel: Command R and R+" + synopsis: send a text message to Cohere Command R and R+, using the Invoke Model API. + category: Cohere Command + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_CohereCommandR + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModel_CohereCommandR + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_CohereCommandR + services: + bedrock-runtime: {InvokeModel} + +bedrock-runtime_InvokeModel_MetaLlama3: + title: Invoke Meta Llama on &BR; using the Invoke Model API + title_abbrev: "InvokeModel" + synopsis: send a text message to Meta Llama, using the Invoke Model API. + category: Meta Llama + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_MetaLlama3 + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModel_MetaLlama3 + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_MetaLlama3 + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - javascript.v3.bedrock-runtime.InvokeModel_Llama3_Quickstart + services: + bedrock-runtime: {InvokeModel} + +bedrock-runtime_InvokeModel_MistralAi: + title: Invoke Mistral AI models on &BR; using the Invoke Model API + title_abbrev: "InvokeModel" + synopsis: send a text message to Mistral models, using the Invoke Model API. + category: Mistral AI + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_Mistral + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModel_Mistral + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_MistralAi + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_files: + - javascriptv3/example_code/bedrock-runtime/models/mistral/invoke_mistral_7b.js + services: + bedrock-runtime: {InvokeModel} + +# Invoke Model with Response Stream +bedrock-runtime_InvokeModelWithResponseStream_AnthropicClaude: + title: Invoke Anthropic Claude models on &BR; using the Invoke Model API with a response stream + title_abbrev: "InvokeModelWithResponseStream" + synopsis: send a text message to Anthropic Claude models, using the Invoke Model API, and print the response stream. + category: Anthropic Claude + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.InvokeModelWithResponseStream_AnthropicClaude + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_AnthropicClaude + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_AnthropicClaude + Go: + versions: + - sdk_version: 2 + github: gov2/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - gov2.bedrock-runtime.InvokeModelWithResponseStreamWrapper.struct + - gov2.bedrock-runtime.InvokeModelWithResponseStream + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_files: + - javascriptv3/example_code/bedrock-runtime/models/anthropicClaude/invoke_claude_3.js + services: + bedrock-runtime: {InvokeModelWithResponseStream} + +bedrock-runtime_InvokeModelWithResponseStream_CohereCommandR: + title: Invoke Cohere Command R and R+ on &BR; using the Invoke Model API with a response stream + title_abbrev: "InvokeModelWithResponseStream: Command R and R+" + synopsis: send a text message to Cohere Command, using the Invoke Model API with a response stream. + category: Cohere Command + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.InvokeModelWithResponseStream_CohereCommandR + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_CohereCommandR + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_CohereCommandR + services: + bedrock-runtime: {InvokeModel} + +bedrock-runtime_InvokeModelWithResponseStream_MetaLlama3: + title: Invoke Meta Llama on &BR; using the Invoke Model API with a response stream + title_abbrev: "InvokeModelWithResponseStream" + synopsis: send a text message to Meta Llama, using the Invoke Model API, and print the response stream. + category: Meta Llama + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.InvokeModelWithResponseStream_MetaLlama3 + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_MetaLlama3 + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_MetaLlama3 + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - javascript.v3.bedrock-runtime.InvokeModelWithResponseStream_Llama3_Quickstart + services: + bedrock-runtime: {InvokeModelWithResponseStream} + +bedrock-runtime_InvokeModelWithResponseStream_MistralAi: + title: Invoke Mistral AI models on &BR; using the Invoke Model API with a response stream + title_abbrev: "InvokeModelWithResponseStream" + synopsis: send a text message to Mistral AI models, using the Invoke Model API, and print the response stream. + category: Mistral AI + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - bedrock-runtime.java2.InvokeModelWithResponseStream_Mistral + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModelWithResponseStream_Mistral + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message and process the response stream in real-time. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModelWithResponseStream_MistralAi + services: + bedrock-runtime: {InvokeModelWithResponseStream} + +# Reasoning +bedrock-runtime_Converse_AnthropicClaudeReasoning: + title: Use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; + title_abbrev: Reasoning + synopsis: use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; + category: Anthropic Claude + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use Anthropic Claude 3.7 Sonnet's reasoning capability with the asynchronous Bedrock runtime client. + snippet_tags: + - bedrock-runtime.java2.ConverseAsync_AnthropicClaudeReasoning + - description: Use Anthropic Claude 3.7 Sonnet's reasoning capability with the synchronous Bedrock runtime client. + snippet_tags: + - bedrock-runtime.java2.Converse_AnthropicClaudeReasoning + services: + bedrock-runtime: {Converse} + +bedrock-runtime_ConverseStream_AnthropicClaudeReasoning: + title: Use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; + title_abbrev: Reasoning with a streaming response + synopsis: use Anthropic Claude 3.7 Sonnet's reasoning capability on &BR; + category: Anthropic Claude + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Use Anthropic Claude 3.7 Sonnet's reasoning capability to generate streaming text responses. + snippet_tags: + - bedrock-runtime.java2.ConverseStream_AnthropicClaudeReasoning + services: + bedrock-runtime: {Converse} + +# Image Generation Models +bedrock-runtime_InvokeModel_AmazonNovaImageGeneration: + title: Invoke Amazon Nova Canvas on &BR; to generate an image + title_abbrev: "InvokeModel" + synopsis: invoke Amazon Nova Canvas on &BR; to generate an image. + category: Amazon Nova Canvas + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Create an image with Amazon Nova Canvas. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_AmazonNovaImageGeneration + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: Create an image with Amazon Nova Canvas. + snippet_tags: + - javascript.v3.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime + excerpts: + - description: Create an image with Amazon Nova Canvas. + snippet_tags: + - BedrockRuntime.dotnetv3.InvokeModel_AmazonNovaImageGeneration + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Create an image with the Amazon Nova Canvas. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Create an image with Amazon Nova Canvas. + snippet_tags: + - swift.example_code.bedrock-runtime.InvokeModel_AmazonNovaImageGeneration + services: + bedrock-runtime: {InvokeModel} + +bedrock-runtime_InvokeModel_TitanImageGenerator: + title: Invoke Amazon Titan Image on &BR; to generate an image + title_abbrev: "InvokeModel" + synopsis: invoke Amazon Titan Image on &BR; to generate an image. + category: Amazon Titan Image Generator + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Create an image with the Amazon Titan Image Generator. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_AmazonTitanImage + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Create an image with the Amazon Titan Image Generator. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_TitanImageGenerator + Go: + versions: + - sdk_version: 2 + github: gov2/bedrock-runtime + excerpts: + - description: Create an image with the Amazon Titan Image Generator. + snippet_tags: + - gov2.bedrock-runtime.InvokeModelWrapper.struct + - gov2.bedrock-runtime.InvokeTitanImage + PHP: + versions: + - sdk_version: 3 + github: php/example_code/bedrock-runtime + excerpts: + - description: Create an image with the Amazon Titan Image Generator. + snippet_tags: + - php.example_code.bedrock-runtime.service.invokeTitanImage + services: + bedrock-runtime: {InvokeModel} + +bedrock-runtime_InvokeModel_StableDiffusion: + title: Invoke Stability.ai Stable Diffusion XL on &BR; to generate an image + title_abbrev: "InvokeModel" + synopsis: invoke Stability.ai Stable Diffusion XL on &BR; to generate an image. + category: Stable Diffusion + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Create an image with Stable Diffusion. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_StableDiffusion + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Create an image with Stable Diffusion. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_StableDiffusion + PHP: + versions: + - sdk_version: 3 + github: php/example_code/bedrock-runtime + excerpts: + - description: Create an image with Stable Diffusion. + snippet_tags: + - php.example_code.bedrock-runtime.service.invokeStableDiffusion + SAP ABAP: + versions: + - sdk_version: 1 + github: sap-abap/services/bdr + excerpts: + - description: Create an image with Stable Diffusion. + snippet_tags: + - bdr.abapv1.invokemodel_stable_diffusion + - description: Invoke the Stability.ai Stable Diffusion XL foundation model to generate images using L2 high level + client. + snippet_tags: + - bdr.abapv1.invokemodel_l2_stable_diffusion + services: + bedrock-runtime: {InvokeModel} + +# Video Generation Models +bedrock-runtime_Scenario_AmazonNova_TextToVideo: + title: Use Amazon Nova Reel to generate a video from a text prompt + title_abbrev: "Text-to-video" + synopsis: use Amazon Nova Reel to generate a video from a text prompt. + category: Amazon Nova Reel + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use Amazon Nova Reel to generate a video from a text prompt. + snippet_tags: + - python.example_code.bedrock-runtime.Scenario_AmazonNova_TextToVideo + Swift: + versions: + - sdk_version: 1 + github: swift/example_code/bedrock-runtime + excerpts: + - description: Use Amazon Nova Reel to generate a video from a text prompt. + snippet_tags: + - swift.example_code.bedrock-runtime.Scenario_AmazonNova_TextToVideo + services: + bedrock-runtime: {GetAsyncInvoke, StartAsyncInvoke} + +# Embedding Models +bedrock-runtime_InvokeModelWithResponseStream_TitanTextEmbeddings: + title: Invoke Amazon Titan Text Embeddings on &BR; + title_abbrev: "InvokeModel" + synopsis_list: + - Get started creating your first embedding. + - Create embeddings configuring the number of dimensions and normalization (V2 only). + category: Amazon Titan Text Embeddings + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Create your first embedding with Titan Text Embeddings V2. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_TitanTextEmbeddings + - description: Invoke Titan Text Embeddings V2 configuring the number of dimensions and normalization. + snippet_tags: + - bedrock-runtime.java2.InvokeModel_TitanTextEmbeddings_AdditionalFields + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Create your first embedding with Amazon Titan Text Embeddings. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_TitanTextEmbeddings + services: + bedrock-runtime: {InvokeModel} + +# Document understanding +bedrock-runtime_DocumentUnderstanding_AmazonNova: + title: Send and process a document with Amazon Nova on &BR; + title_abbrev: "Document understanding" + synopsis: send and process a document with Amazon Nova on &BR;. + category: Amazon Nova + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send and process a document with Amazon Nova on &BR;. + snippet_tags: + - python.example_code.bedrock-runtime.DocumentUnderstanding_AmazonNovaText + services: + bedrock-runtime: {Converse} + +bedrock-runtime_DocumentUnderstanding_AnthropicClaude: + title: Send and process a document with Anthropic Claude on &BR; + title_abbrev: "Document understanding" + synopsis: send and process a document with Anthropic Claude on &BR;. + category: Anthropic Claude + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send and process a document with Anthropic Claude on &BR;. + snippet_tags: + - python.example_code.bedrock-runtime.DocumentUnderstanding_AnthropicClaude + services: + bedrock-runtime: {Converse} + +bedrock-runtime_DocumentUnderstanding_CohereCommand: + title: Send and process a document with Cohere Command models on &BR; + title_abbrev: "Document understanding" + synopsis: send and process a document with Cohere Command models on &BR;. + category: Cohere Command + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send and process a document with Cohere Command models on &BR;. + snippet_tags: + - python.example_code.bedrock-runtime.DocumentUnderstanding_CohereCommand + services: + bedrock-runtime: {Converse} + +bedrock-runtime_DocumentUnderstanding_DeepSeek: + title: Send and process a document with DeepSeek on &BR; + title_abbrev: "Document understanding" + synopsis: send and process a document with DeepSeek on &BR;. + category: DeepSeek + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send and process a document with DeepSeek on &BR;. + snippet_tags: + - python.example_code.bedrock-runtime.DocumentUnderstanding_DeepSeek + services: + bedrock-runtime: {Converse} + +bedrock-runtime_DocumentUnderstanding_MetaLlama: + title: Send and process a document with Llama on &BR; + title_abbrev: "Document understanding" + synopsis: send and process a document with Llama on &BR;. + category: Meta Llama + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send and process a document with Llama on &BR;. + snippet_tags: + - python.example_code.bedrock-runtime.DocumentUnderstanding_MetaLlama + services: + bedrock-runtime: {Converse} + +bedrock-runtime_DocumentUnderstanding_Mistral: + title: Send and process a document with Mistral models on &BR; + title_abbrev: "Document understanding" + synopsis: send and process a document with Mistral models on &BR;. + category: Mistral AI + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Send and process a document with Mistral models on &BR;. + snippet_tags: + - python.example_code.bedrock-runtime.DocumentUnderstanding_Mistral + services: + bedrock-runtime: {Converse} + +# Tool use scenarios +bedrock-runtime_Scenario_ToolUseDemo_AmazonNova: + title: "A tool use demo illustrating how to connect AI models on &BR; with a custom tool or API" + title_abbrev: "Scenario: Tool use with the Converse API" + synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." + category: Amazon Nova + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + snippet_tags: + - bedrock.converseTool.javav2.scenario + - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + genai: some + snippet_tags: + - bedrock.converseTool.javav2.weathertool + - description: "The Converse API action with a tool configuration." + genai: some + snippet_tags: + - bedrockruntime.java2.converse.main + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock-runtime/Scenarios/ConverseToolScenario + excerpts: + - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + genai: some + snippet_tags: + - Bedrock.ConverseTool.dotnetv3.Scenario + - description: "The weather tool used by the demo. This file defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + genai: some + snippet_tags: + - Bedrock.ConverseTool.dotnetv3.WeatherTool + - description: "The Converse API action with a tool configuration." + genai: some + snippet_tags: + - Bedrock.ConverseTool.dotnetv3.SendConverseRequest + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime/scenarios/converse_tool_scenario + excerpts: + - description: "The primary execution of the scenario flow. This scenario orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + genai: some + snippet_tags: + - Bedrock.ConverseTool.javascriptv3.Scenario + services: + bedrock-runtime: {Converse} + +bedrock-runtime_Scenario_ToolUseDemo_AnthropicClaude: + title: "A tool use demo illustrating how to connect AI models on &BR; with a custom tool or API" + title_abbrev: "Scenario: Tool use with the Converse API" + synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." + category: Anthropic Claude + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: "The primary execution script of the demo. This script orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + snippet_files: + - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/tool_use_demo.py + - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + snippet_files: + - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/weather_tool.py + Rust: + versions: + - sdk_version: 1 + github: rustv1/examples/bedrock-runtime + excerpts: + - description: "The primary scenario and logic for the demo. This orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use + - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.weather-tool + - description: "Utilities to print the Message Content Blocks." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.user-interface + - description: "Use statements, Error utility, and constants." + snippet_tags: + - rust.bedrock-runtime.Converse_AnthropicClaude.tool-use.supporting + services: + bedrock-runtime: {Converse} + +bedrock-runtime_Scenario_ToolUseDemo_CohereCommand: + title: "A tool use demo illustrating how to connect AI models on &BR; with a custom tool or API" + title_abbrev: "Scenario: Tool use with the Converse API" + synopsis: "build a typical interaction between an application, a generative AI model, and connected tools or APIs to mediate interactions between the AI and the outside world. It uses the example of connecting an external weather API to the AI model so it can provide real-time weather information based on user input." + category: Cohere Command + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: "The primary execution script of the demo. This script orchestrates the conversation between the user, the &BR; Converse API, and a weather tool." + snippet_files: + - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/tool_use_demo.py + - description: "The weather tool used by the demo. This script defines the tool specification and implements the logic to retrieve weather data using from the Open-Meteo API." + snippet_files: + - python/example_code/bedrock-runtime/cross-model-scenarios/tool_use_demo/weather_tool.py + services: + bedrock-runtime: {Converse} + +# Other scenarios +bedrock-runtime_Scenario_InvokeModels: + title: Invoke multiple foundation models on &BR; + title_abbrev: "Invoke multiple foundation models on &BR;" + synopsis: prepare and send a prompt to a variety of large-language models (LLMs) on &BR; + category: Scenarios + languages: + Go: + versions: + - sdk_version: 2 + github: gov2/bedrock-runtime + excerpts: + - description: Invoke multiple foundation models on &BR;. + snippet_tags: + - gov2.bedrock-runtime.Scenario_InvokeModels + JavaScript: + versions: + - sdk_version: 3 + github: javascriptv3/example_code/bedrock-runtime + excerpts: + - description: + snippet_files: + - javascriptv3/example_code/bedrock-runtime/scenarios/cli_text_playground.js + PHP: + versions: + - sdk_version: 3 + github: php/example_code/bedrock-runtime/ + excerpts: + - description: Invoke multiple LLMs on &BR;. + snippet_tags: + - php.example_code.bedrock-runtime.basics.scenario + services: + bedrock-runtime: {InvokeModel, InvokeModelWithResponseStream} + +bedrock-runtime_Scenario_GenerateVideos_NovaReel: + title: Generate videos from text prompts using &BR; and Nova-Reel + title_abbrev: "Generate videos from text prompts using &BR;" + synopsis: a Spring Boot app that generates videos from text prompts using &BR; and the Nova-Reel model. + category: Scenarios + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/bedrock-runtime + excerpts: + - description: Generate videos from text prompts using &BR; and Nova-Reel. + snippet_tags: + - bedrock-runtime.java2.NovaReel.VideoGeneration + services: + bedrock-runtime: {StartAsyncInvoke, GetAsyncInvoke} + +bedrock-runtime_InvokeModel_TitanText: + title: Invoke Amazon Titan Text models on &BR; using the Invoke Model API + title_abbrev: "InvokeModel" + synopsis: send a text message to Amazon Titan Text, using the Invoke Model API. + category: Amazon Titan Text + languages: + Python: + versions: + - sdk_version: 3 + github: python/example_code/bedrock-runtime + excerpts: + - description: Use the Invoke Model API to send a text message. + snippet_tags: + - python.example_code.bedrock-runtime.InvokeModel_TitanText + services: + bedrock-runtime: {InvokeModel} From 34ddac4c97891be266c46895b395166d0aab73f8 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 10:54:19 -0500 Subject: [PATCH 13/28] Fixed a linter error --- .doc_gen/metadata/inspector_metadata.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.doc_gen/metadata/inspector_metadata.yaml b/.doc_gen/metadata/inspector_metadata.yaml index 07783c71918..d376516b981 100644 --- a/.doc_gen/metadata/inspector_metadata.yaml +++ b/.doc_gen/metadata/inspector_metadata.yaml @@ -156,6 +156,7 @@ inspector_Scenario: - List existing filters. - Check usage and costs. - Get coverage statistics. + - Delete a filter. category: Basics languages: Java: @@ -171,4 +172,4 @@ inspector_Scenario: snippet_tags: - inspector.java2_actions.main services: - inspector: {BatchGetAccountStatus, BatchGetFindingDetails, DeleteFilter, Enable, ListFindings, ListCoverage, CreateFilter, ListFilters, ListUsageTotals, ListCoverageStatistics} \ No newline at end of file + inspector: {BatchGetAccountStatus, BatchGetFindingDetails, DeleteFilter, Enable, ListFindings, ListCoverage, CreateFilter, ListFilters, ListUsageTotals, ListCoverageStatistics} From 03c07ba678cf0a9b050d6e29eeeb455947b24abc Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 11:01:19 -0500 Subject: [PATCH 14/28] Fixed a linter error --- javav2/example_code/inspector/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/javav2/example_code/inspector/README.md b/javav2/example_code/inspector/README.md index 754827256bc..6c722f8ec30 100644 --- a/javav2/example_code/inspector/README.md +++ b/javav2/example_code/inspector/README.md @@ -85,6 +85,7 @@ This example shows you how to do the following: - List existing filters. - Check usage and costs. - Get coverage statistics. +- Delete a filter. From 10f134462c6a9775c0825d45ba604903ac8f7dd7 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Sat, 13 Dec 2025 11:40:51 -0500 Subject: [PATCH 15/28] Fixed a linter error --- .doc_gen/metadata/inspector_metadata.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.doc_gen/metadata/inspector_metadata.yaml b/.doc_gen/metadata/inspector_metadata.yaml index d376516b981..119917bfdd0 100644 --- a/.doc_gen/metadata/inspector_metadata.yaml +++ b/.doc_gen/metadata/inspector_metadata.yaml @@ -42,7 +42,7 @@ inspector_DeleteFilter: - inspector.java2.delete.filter.main services: inspector: {DeleteFilter} -inspector_EnableInspector: +inspector_Enable: languages: Java: versions: From fcd608b5682a47f988edf90cdc8f3d1ffb16cbb3 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 09:46:14 -0500 Subject: [PATCH 16/28] updated Spec --- scenarios/basics/inspector/SPECIFICATION.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scenarios/basics/inspector/SPECIFICATION.md b/scenarios/basics/inspector/SPECIFICATION.md index c8fa8a1db0e..5776fccb55d 100644 --- a/scenarios/basics/inspector/SPECIFICATION.md +++ b/scenarios/basics/inspector/SPECIFICATION.md @@ -35,6 +35,8 @@ This Basics scenario does not require any additional AWS resources. * [DeleteFilter](https://docs.aws.amazon.com/inspector/v2/APIReference/API_DeleteFilter.html) +- [Disable](https://docs.aws.amazon.com/inspector/v2/APIReference/API_Disable.html) + ## Hello Amazon Inspector @@ -77,6 +79,13 @@ This scenario demonstrates the basic usage of **Amazon Inspector** using a Java --- +### Cleanup + +* Delete the filter +* Diable inspector + +--- + ### Outcome By following this scenario, users learn how to: @@ -87,6 +96,7 @@ By following this scenario, users learn how to: * Monitor scan coverage * Create and manage filters * Track usage and coverage statistics +* Cleanup the resources ## Errors @@ -95,6 +105,7 @@ The table below describes the exceptions handled in the program for each action. | Action | Exception | Handling | |-------------------------------|---------------------------|--------------------------------------------------------------------------| | `Enable` | `ValidationException` | Prints a message indicating Inspector may already be enabled. | +| `Disable` | `ValidationException` | Prints a message indicating Inspector may already be disabled. | | `listUsageTotals` | `ValidationException` | Validation error listing usage totals. | `BatchGetAccountStatus` | `AccessDeniedException` | Prints AWS service error details and rethrows the exception. | | `ListFindings` | `ValidationException` | Prints validation error details. | @@ -111,6 +122,7 @@ The table below describes the exceptions handled in the program for each action. | Action / Scenario | Metadata File | Metadata Key | |-----------------------------------------|------------------------|-------------------------------| | `Enable` | inspector_metadata.yaml | inspector_EnableInspector | +| `Disable` | inspector_metadata.yaml | inspector_DisableInspector | | `BatchGetAccountStatus` | inspector_metadata.yaml | inspector_GetAccountStatus | | `ListFindings` | inspector_metadata.yaml | inspector_ListFindings | | `ListCoverage` | inspector_metadata.yaml | inspector_ListCoverage | From 06b88d9792197d4f5c9ce018dcf0dae505dd5f05 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 09:52:30 -0500 Subject: [PATCH 17/28] updated Spec --- scenarios/basics/inspector/SPECIFICATION.md | 1 - 1 file changed, 1 deletion(-) diff --git a/scenarios/basics/inspector/SPECIFICATION.md b/scenarios/basics/inspector/SPECIFICATION.md index 5776fccb55d..4aca464cfff 100644 --- a/scenarios/basics/inspector/SPECIFICATION.md +++ b/scenarios/basics/inspector/SPECIFICATION.md @@ -20,7 +20,6 @@ This Basics scenario does not require any additional AWS resources. * [ListCoverageStatistics](https://docs.aws.amazon.com/inspector/v2/APIReference/API_ListCoverageStatistics.html) - * [ListUsageTotals](https://docs.aws.amazon.com/inspector/v2/APIReference/API_ListUsageTotals.html) * [BatchGetAccountStatus](https://docs.aws.amazon.com/inspector/v2/APIReference/API_BatchGetAccountStatus.html) From e6d38c340ef8bf836e12cf3f32b69b32c5d26219 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 10:15:42 -0500 Subject: [PATCH 18/28] updated the Scenario --- .../src/main/java/com/java/inspector/InspectorScenario.java | 1 + 1 file changed, 1 insertion(+) diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java index 52e7ae8da1c..3bf9964b528 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java @@ -166,6 +166,7 @@ public static void runScenario(InspectorActions actions) { if (scanner.nextLine().trim().equalsIgnoreCase("y")) { actions.deleteFilterAsync(filterArn).join(); logger.info("Filter deleted."); + logger.info("Disable Inspector ."); } waitForInputToContinue(); From ce1bb75699d7023b8d4662c966ab2d4d6420c88d Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 11:15:45 -0500 Subject: [PATCH 19/28] updated the YAML --- .doc_gen/metadata/inspector_metadata.yaml | 13 +++ .../com/java/inspector/InspectorActions.java | 79 +++++++++++++++++++ .../com/java/inspector/InspectorScenario.java | 3 + .../src/test/java/InspectorTests.java | 2 + scenarios/basics/inspector/SPECIFICATION.md | 8 +- 5 files changed, 101 insertions(+), 4 deletions(-) diff --git a/.doc_gen/metadata/inspector_metadata.yaml b/.doc_gen/metadata/inspector_metadata.yaml index 119917bfdd0..f9334f20d49 100644 --- a/.doc_gen/metadata/inspector_metadata.yaml +++ b/.doc_gen/metadata/inspector_metadata.yaml @@ -42,6 +42,19 @@ inspector_DeleteFilter: - inspector.java2.delete.filter.main services: inspector: {DeleteFilter} +inspector_Disable: + languages: + Java: + versions: + - sdk_version: 2 + github: javav2/example_code/inspector + sdkguide: + excerpts: + - description: + snippet_tags: + - inspector.java2.disable.main + services: + inspector: {Disable} inspector_Enable: languages: Java: diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java index c51a7788cc0..424b8c7ddbc 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java @@ -706,5 +706,84 @@ public CompletableFuture getFindingDetailsAsync(String findingArn) { }); } // snippet-end:[inspector.java2.finding.details.main] + + + // snippet-start:[inspector.java2.disable.main] + /** + * Asynchronously disables AWS Inspector for the specified accounts and resource types. + * + * @param accountIds a {@link List} of AWS account IDs for which to disable Inspector; + * may be {@code null} or empty to target the current account + * @return a {@link CompletableFuture} that, when completed, returns a {@link String} + * summarizing the disable results for each account + * @throws CompletionException if the disable operation fails due to validation errors, + * service errors, or other exceptions + * @see + * AWS Inspector2 Disable API + */ + public CompletableFuture disableInspectorAsync(List accountIds) { + + // The resource types to disable. + List resourceTypes = List.of( + ResourceScanType.EC2, + ResourceScanType.ECR, + ResourceScanType.LAMBDA, + ResourceScanType.LAMBDA_CODE + ); + + // Build the request. + DisableRequest.Builder requestBuilder = DisableRequest.builder() + .resourceTypes(resourceTypes); + + if (accountIds != null && !accountIds.isEmpty()) { + requestBuilder.accountIds(accountIds); + } + + DisableRequest request = requestBuilder.build(); + + return getAsyncClient().disable(request) + .whenComplete((response, exception) -> { + if (exception != null) { + Throwable cause = exception.getCause(); + if (cause instanceof ValidationException) { + throw new CompletionException( + "Inspector may already be disabled for this account: %s".formatted(cause.getMessage()), + cause + ); + } + + if (cause instanceof Inspector2Exception) { + Inspector2Exception e = (Inspector2Exception) cause; + throw new CompletionException( + "AWS Inspector2 service error: %s".formatted(e.awsErrorDetails().errorMessage()), + cause + ); + } + + throw new CompletionException( + "Failed to disable Inspector: %s".formatted(exception.getMessage()), + exception + ); + } + }) + .thenApply(response -> { + StringBuilder summary = new StringBuilder("Disable results:\n"); + + if (response.accounts() == null || response.accounts().isEmpty()) { + summary.append("Inspector may already be disabled for all target accounts."); + return summary.toString(); + } + + for (Account account : response.accounts()) { + String accountId = account.accountId() != null ? account.accountId() : "Unknown"; + String status = account.status() != null ? account.statusAsString() : "Unknown"; + summary.append(" • Account: ").append(accountId) + .append(" → Status: ").append(status).append("\n"); + } + + return summary.toString(); + }); + } + // snippet-end:[inspector.java2.disable.main] } // snippet-end:[inspector.java2_actions.main] \ No newline at end of file diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java index 3bf9964b528..7167de7ee83 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java @@ -55,6 +55,7 @@ Amazon Inspector is a security assessment service provided by Amazon Web Service logger.info(" - How to check coverage information"); logger.info(" - How to create and manage filters"); logger.info(" - How to track usage and costs"); + logger.info(" - How to clean up resources"); logger.info(""); } catch (Exception ex) { @@ -167,6 +168,8 @@ public static void runScenario(InspectorActions actions) { actions.deleteFilterAsync(filterArn).join(); logger.info("Filter deleted."); logger.info("Disable Inspector ."); + String disableMsg = actions.disableInspectorAsync(null).join(); + logger.info(disableMsg); } waitForInputToContinue(); diff --git a/javav2/example_code/inspector/src/test/java/InspectorTests.java b/javav2/example_code/inspector/src/test/java/InspectorTests.java index 8ff9b1b2a4b..770422b7d33 100644 --- a/javav2/example_code/inspector/src/test/java/InspectorTests.java +++ b/javav2/example_code/inspector/src/test/java/InspectorTests.java @@ -104,6 +104,8 @@ public void testInspectorActionsIntegration() { inspectorActions.listCoverageStatisticsAsync().join(); inspectorActions.deleteFilterAsync(filterARN).join(); + + inspectorActions.disableInspectorAsync(null).join(); }); logger.info("Test 2 passed"); diff --git a/scenarios/basics/inspector/SPECIFICATION.md b/scenarios/basics/inspector/SPECIFICATION.md index 4aca464cfff..8772710ff56 100644 --- a/scenarios/basics/inspector/SPECIFICATION.md +++ b/scenarios/basics/inspector/SPECIFICATION.md @@ -120,8 +120,8 @@ The table below describes the exceptions handled in the program for each action. | Action / Scenario | Metadata File | Metadata Key | |-----------------------------------------|------------------------|-------------------------------| -| `Enable` | inspector_metadata.yaml | inspector_EnableInspector | -| `Disable` | inspector_metadata.yaml | inspector_DisableInspector | +| `Enable` | inspector_metadata.yaml | inspector_Enable | +| `Disable` | inspector_metadata.yaml | inspector_Disable | | `BatchGetAccountStatus` | inspector_metadata.yaml | inspector_GetAccountStatus | | `ListFindings` | inspector_metadata.yaml | inspector_ListFindings | | `ListCoverage` | inspector_metadata.yaml | inspector_ListCoverage | @@ -129,7 +129,7 @@ The table below describes the exceptions handled in the program for each action. | `ListUsageTotals` | inspector_metadata.yaml | inspector_ListUsageTotals | | `CreateFilter` | inspector_metadata.yaml | inspector_CreateFilter | | `ListFilters` | inspector_metadata.yaml | inspector_ListFilters | -| `DeleteFilter` | inspector_metadata.yaml | inspector_DeleteFilter` | -| `batchGetFindingDetails` | inspector_metadata.yaml | inspector_BatchGetFindingDetails | +| `DeleteFilter` | inspector_metadata.yaml | inspector_DeleteFilter | +| `BatchGetFindingDetails` | inspector_metadata.yaml | inspector_BatchGetFindingDetails | | `Amazon Inspector Hello` | inspector_metadata.yaml | inspector_Hello | | `Amazon Inspector Basics Scenario` | inspector_metadata.yaml | inspector_Scenario \ No newline at end of file From 2a6ce6b5324bcea5b7309adbbea3db7539dd710b Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 11:29:29 -0500 Subject: [PATCH 20/28] modified hello --- .../com/java/inspector/HelloInspector.java | 131 ------------------ 1 file changed, 131 deletions(-) diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java index 1f241895f09..bbfbcf0d465 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java @@ -43,14 +43,6 @@ public static void main(String[] args) { checkAccountStatus(inspectorClient); logger.info(""); - logger.info("Checking for recent findings..."); - listRecentFindings(inspectorClient); - logger.info(""); - - logger.info("Checking usage totals..."); - showUsageTotals(inspectorClient); - logger.info(""); - logger.info("The Hello Inspector example completed successfully."); } catch (Inspector2Exception e) { @@ -109,128 +101,5 @@ public static void printState(String name, State state) { String err = state.errorMessage() != null ? " (Error: " + state.errorMessage() + ")" : ""; logger.info(" - {}: {}{}", name, state.status(), err); } - - /** - * Lists recent findings from AWS Inspector2 using the synchronous client with a paginator. - * - * @param inspectorClient an instance of {@link Inspector2Client} used to call AWS Inspector2 - * @throws Inspector2Exception if there is an error communicating with the Inspector2 service - */ - /** - * Lists up to 10 recent findings from AWS Inspector2 using the synchronous client. - * - *

This method retrieves findings in pages and logs details for each finding, - * including title, severity, status, and last observed time. Only the first - * 10 findings are logged, even if more exist. - * - * @param inspectorClient an instance of {@link Inspector2Client} used to call AWS Inspector2 - * @throws Inspector2Exception if there is an error communicating with the Inspector2 service - */ - public static void listRecentFindings(Inspector2Client inspectorClient) { - final int MAX_FINDINGS = 10; - int totalLogged = 0; - - try { - // Build initial request with page size - ListFindingsRequest request = ListFindingsRequest.builder() - .maxResults(MAX_FINDINGS) - .build(); - - // Paginator returns an iterable over responses - ListFindingsIterable responses = inspectorClient.listFindingsPaginator(request); - - for (ListFindingsResponse response : responses) { - List findings = response.findings(); - if (findings == null || findings.isEmpty()) { - continue; - } - - for (Finding finding : findings) { - if (totalLogged >= MAX_FINDINGS) { - break; - } - - logger.info(" Title: {}", finding.title()); - logger.info(" Severity: {}", finding.severity()); - logger.info(" Status: {}", finding.status()); - logger.info(" Last Observed: {}", finding.lastObservedAt()); - logger.info(""); - - totalLogged++; - } - - if (totalLogged >= MAX_FINDINGS) { - break; - } - } - - if (totalLogged == 0) { - logger.info(" No findings found."); - } else { - logger.info(" Displayed {} recent finding(s).", totalLogged); - } - - } catch (Inspector2Exception e) { - logger.info(" Error listing findings: {}", e.awsErrorDetails().errorMessage()); - } - } - - - /** - * Displays the usage totals for the Inspector2 service. - * - * @param inspectorClient the {@code Inspector2Client} used to make the API call to - * retrieve the usage totals. - * - * @throws Inspector2Exception if there is an error while retrieving the usage totals. - * The error message is printed to the standard error output. - */ - public static void showUsageTotals(Inspector2Client inspectorClient) { - try { - logger.info("Listing usage totals using paginator..."); - ListUsageTotalsRequest request = ListUsageTotalsRequest.builder() - .maxResults(10) - .build(); - - // Create paginator. - ListUsageTotalsIterable paginator = inspectorClient.listUsageTotalsPaginator(request); - List allTotals = new ArrayList<>(); - - // Iterate through all pages. - for (ListUsageTotalsResponse response : paginator) { - List totals = response.totals(); - if (totals != null && !totals.isEmpty()) { - allTotals.addAll(totals); - } - } - - // Display results. - if (allTotals.isEmpty()) { - logger.info(" No usage data available yet."); - logger.info(" Usage data appears after Inspector has been active for some time."); - } else { - logger.info(" Usage Totals (Last 30 days):"); - for (UsageTotal total : allTotals) { - logger.info(" Account: {}" , total.accountId()); - if (total.usage() != null && !total.usage().isEmpty()) { - total.usage().forEach(u -> { - logger.info(" - {}: {}", u.type(), u.total()); - - if (u.estimatedMonthlyCost() != null) { - logger.info(" Estimated Monthly Cost: {} {}", u.estimatedMonthlyCost(), u.currency()); - } - }); - } - logger.info(""); - } - } - - } catch (Inspector2Exception e) { - logger.info(" Error getting usage totals: {}" , e.awsErrorDetails().errorMessage()); - throw e; - } catch (Exception e) { - throw new RuntimeException("Unexpected error while listing usage totals: " + e.getMessage(), e); - } - } } // snippet-end:[inspector.java2.hello.main] \ No newline at end of file From 23afe4a35d27cd1634b5a8c432712c5e0de1306c Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 11:56:57 -0500 Subject: [PATCH 21/28] rolled im review comments --- .doc_gen/metadata/inspector_metadata.yaml | 2 +- .../com/java/inspector/HelloInspector.java | 69 ++++----- .../com/java/inspector/InspectorActions.java | 139 +++++++----------- .../src/test/java/InspectorTests.java | 4 +- scenarios/basics/inspector/SPECIFICATION.md | 2 +- 5 files changed, 82 insertions(+), 134 deletions(-) diff --git a/.doc_gen/metadata/inspector_metadata.yaml b/.doc_gen/metadata/inspector_metadata.yaml index f9334f20d49..b06fd987e2f 100644 --- a/.doc_gen/metadata/inspector_metadata.yaml +++ b/.doc_gen/metadata/inspector_metadata.yaml @@ -15,7 +15,7 @@ inspector_Hello: snippet_tags: - inspector.java2.hello.main services: - inspector: {BatchGetAccountStatus, ListFindings, ListUsageTotals} + inspector: {ListMembers} inspector_BatchGetFindingDetails: languages: Java: diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java index bbfbcf0d465..a457a90145f 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/HelloInspector.java @@ -9,6 +9,9 @@ import software.amazon.awssdk.services.inspector2.model.BatchGetAccountStatusRequest; import software.amazon.awssdk.services.inspector2.model.BatchGetAccountStatusResponse; import software.amazon.awssdk.services.inspector2.model.AccountState; +import software.amazon.awssdk.services.inspector2.model.ListMembersRequest; +import software.amazon.awssdk.services.inspector2.model.ListMembersResponse; +import software.amazon.awssdk.services.inspector2.model.Member; import software.amazon.awssdk.services.inspector2.model.ResourceState; import software.amazon.awssdk.services.inspector2.model.State; import software.amazon.awssdk.services.inspector2.model.ListFindingsRequest; @@ -34,20 +37,20 @@ */ public class HelloInspector { private static final Logger logger = LoggerFactory.getLogger(HelloInspector.class); + public static void main(String[] args) { - logger.info(" Hello Amazon Inspector!"); - try (Inspector2Client inspectorClient = Inspector2Client.builder() - .build()) { + logger.info("Hello Amazon Inspector!"); + + try (Inspector2Client inspectorClient = Inspector2Client.builder().build()) { - logger.info("Checking Inspector account status..."); - checkAccountStatus(inspectorClient); - logger.info(""); + logger.info("Listing member accounts for this Inspector administrator account..."); + listMembers(inspectorClient); logger.info("The Hello Inspector example completed successfully."); } catch (Inspector2Exception e) { - logger.info(" Error: {}" , e.getMessage()); - logger.info(" Troubleshooting:"); + logger.error("Error: {}", e.getMessage()); + logger.info("Troubleshooting:"); logger.info("1. Verify AWS credentials are configured"); logger.info("2. Check IAM permissions for Inspector2"); logger.info("3. Ensure Inspector2 is enabled in your account"); @@ -56,50 +59,34 @@ public static void main(String[] args) { } /** - * Checks the account status using the provided Inspector2Client. - * This method sends a request to retrieve the account status and prints the details of each account's resource states. + * Lists all member accounts associated with the current Inspector administrator account. * - * @param inspectorClient The Inspector2Client used to interact with the AWS Inspector service. + * @param inspectorClient The Inspector2Client used to interact with AWS Inspector. */ - public static void checkAccountStatus(Inspector2Client inspectorClient) { + public static void listMembers(Inspector2Client inspectorClient) { try { - BatchGetAccountStatusRequest request = BatchGetAccountStatusRequest.builder().build(); - BatchGetAccountStatusResponse response = inspectorClient.batchGetAccountStatus(request); + ListMembersRequest request = ListMembersRequest.builder() + .maxResults(50) // optional: limit results + .build(); - List accounts = response.accounts(); - if (accounts == null || accounts.isEmpty()) { - logger.info(" No account information returned."); + ListMembersResponse response = inspectorClient.listMembers(request); + List members = response.members(); + + if (members == null || members.isEmpty()) { + logger.info("No member accounts found for this Inspector administrator account."); return; } - for (AccountState account : accounts) { - logger.info(" Account: " + account.accountId()); - ResourceState resources = account.resourceState(); - if (resources == null) { - System.out.println(" No resource state data available."); - continue; - } - - logger.info(" Resource States:"); - printState("EC2", resources.ec2()); - printState("ECR", resources.ecr()); - printState("Lambda", resources.lambda()); - printState("Lambda Code", resources.lambdaCode()); - System.out.println(); + logger.info("Found {} member account(s):", members.size()); + for (Member member : members) { + logger.info(" - Account ID: {}, Status: {}", + member.accountId(), + member.relationshipStatusAsString()); } } catch (Inspector2Exception e) { - System.err.println(" Failed to retrieve account status: " + e.awsErrorDetails().errorMessage()); - } - } - - public static void printState(String name, State state) { - if (state == null) { - logger.info(" - {} : (no data)", name); - return; + logger.error("Failed to list members: {}", e.awsErrorDetails().errorMessage()); } - String err = state.errorMessage() != null ? " (Error: " + state.errorMessage() + ")" : ""; - logger.info(" - {}: {}{}", name, state.status(), err); } } // snippet-end:[inspector.java2.hello.main] \ No newline at end of file diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java index 424b8c7ddbc..5d18a671dbd 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java @@ -11,6 +11,7 @@ import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; import software.amazon.awssdk.services.inspector2.Inspector2AsyncClient; import software.amazon.awssdk.services.inspector2.model.*; +import software.amazon.awssdk.services.inspector2.paginators.ListCoveragePublisher; import software.amazon.awssdk.services.inspector2.paginators.ListFiltersPublisher; import software.amazon.awssdk.services.inspector2.paginators.ListFindingsPublisher; import software.amazon.awssdk.services.inspector2.paginators.ListUsageTotalsPublisher; @@ -497,101 +498,63 @@ public CompletableFuture listLowSeverityFindingsAsync() { * * @param maxResults Maximum number of resources to return. */ - public CompletableFuture listCoverageAsync( - int maxResults) { - - ListCoverageRequest request = ListCoverageRequest.builder() + public CompletableFuture listCoverageAsync(int maxResults) { + ListCoverageRequest initialRequest = ListCoverageRequest.builder() .maxResults(maxResults) .build(); - return getAsyncClient().listCoverage(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause(); - - if (cause instanceof ValidationException) { - throw new CompletionException( - "Validation error listing coverage: " + cause.getMessage(), - cause - ); - } - - if (cause instanceof Inspector2Exception) { - Inspector2Exception e = (Inspector2Exception) cause; - throw new CompletionException( - "Inspector2 service error: " + e.awsErrorDetails().errorMessage(), - e - ); - } - - throw new CompletionException( - "Unexpected error listing coverage: " + exception.getMessage(), - exception - ); - } - }) - .thenApply(response -> { + ListCoveragePublisher paginator = getAsyncClient().listCoveragePaginator(initialRequest); + StringBuilder summary = new StringBuilder(); - List coveredResources = response.coveredResources(); - - // Build output summary - StringBuilder sb = new StringBuilder(); - - if (coveredResources == null || coveredResources.isEmpty()) { - sb.append("No coverage information available.\n") - .append("This likely means Inspector hasn't scanned your resources yet ") - .append("or no supported resource types are present.\n"); - - return sb.toString(); - } + return paginator.subscribe(response -> { + List coveredResources = response.coveredResources(); - // Summary counts - sb.append("Coverage Information:\n") - .append(" Total resources covered: ") - .append(coveredResources.size()) - .append("\n"); - - // Group by resource type - Map> byType = - coveredResources.stream() - .collect(Collectors.groupingBy(CoveredResource::resourceTypeAsString)); - - byType.forEach((type, list) -> - sb.append(" ").append(type) - .append(": ").append(list.size()) - .append(" resource(s)\n") - ); - - sb.append("\nSample covered resources:\n"); - for (int i = 0; i < Math.min(coveredResources.size(), 3); i++) { - CoveredResource r = coveredResources.get(i); - - sb.append(" - ") - .append(r.resourceTypeAsString()) - .append(": ") - .append(r.resourceId()) - .append("\n"); - - sb.append(" Scan Type: ") - .append(r.scanTypeAsString()) - .append("\n"); - - if (r.scanStatus() != null) { - sb.append(" Status: ") - .append(r.scanStatus().statusCodeAsString()) - .append("\n"); - } + if (coveredResources == null || coveredResources.isEmpty()) { + summary.append("No coverage information available for this page.\n"); + return; + } - if (r.accountId() != null) { - sb.append(" Account ID: ") - .append(r.accountId()) - .append("\n"); - } + Map> byType = coveredResources.stream() + .collect(Collectors.groupingBy(CoveredResource::resourceTypeAsString)); + + byType.forEach((type, list) -> + summary.append(" ").append(type) + .append(": ").append(list.size()) + .append(" resource(s)\n") + ); + + // Include up to 3 sample resources per page + for (int i = 0; i < Math.min(coveredResources.size(), 3); i++) { + CoveredResource r = coveredResources.get(i); + summary.append(" - ").append(r.resourceTypeAsString()) + .append(": ").append(r.resourceId()).append("\n"); + summary.append(" Scan Type: ").append(r.scanTypeAsString()).append("\n"); + if (r.scanStatus() != null) { + summary.append(" Status: ").append(r.scanStatus().statusCodeAsString()).append("\n"); + } + if (r.accountId() != null) { + summary.append(" Account ID: ").append(r.accountId()).append("\n"); + } + summary.append("\n"); + } - sb.append("\n"); - } - return sb.toString(); - }); + }).thenApply(v -> { + if (summary.length() == 0) { + return "No coverage information found across all pages."; + } else { + return "Coverage Information:\n" + summary.toString(); + } + }).exceptionally(ex -> { + Throwable cause = ex.getCause(); + if (cause instanceof ValidationException) { + throw new CompletionException( + "Validation error listing coverage: " + cause.getMessage(), cause); + } else if (cause instanceof Inspector2Exception e) { + throw new CompletionException( + "Inspector2 service error: " + e.awsErrorDetails().errorMessage(), e); + } + throw new CompletionException("Unexpected error listing coverage: " + ex.getMessage(), ex); + }); } // snippet-end:[inspector.java2.list_coverage.main] diff --git a/javav2/example_code/inspector/src/test/java/InspectorTests.java b/javav2/example_code/inspector/src/test/java/InspectorTests.java index 770422b7d33..7fdee72a73c 100644 --- a/javav2/example_code/inspector/src/test/java/InspectorTests.java +++ b/javav2/example_code/inspector/src/test/java/InspectorTests.java @@ -44,9 +44,7 @@ public static void setUp() { @Order(1) public void testHelloService() { assertDoesNotThrow(() -> { - HelloInspector.checkAccountStatus(inspector); - HelloInspector.listRecentFindings(inspector); - HelloInspector.showUsageTotals(inspector); + HelloInspector.listMembers(inspector); }); logger.info("Test 1 passed"); } diff --git a/scenarios/basics/inspector/SPECIFICATION.md b/scenarios/basics/inspector/SPECIFICATION.md index 8772710ff56..784cf2ba868 100644 --- a/scenarios/basics/inspector/SPECIFICATION.md +++ b/scenarios/basics/inspector/SPECIFICATION.md @@ -39,7 +39,7 @@ This Basics scenario does not require any additional AWS resources. ## Hello Amazon Inspector -The Hello example is intended for users not familiar with this service to easily get up and running. It sets up the Inspector service client, checks the current account status for Inspector and displays available scan types. +The Hello example is designed for users who are new to Amazon Inspector. It demonstrates how to set up the Inspector service client and retrieve a list of all member accounts associated with the current Inspector administrator account. ## Scenario From a34922cd309f62aa54e5b9a07fee2fd9caaf4619 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 12:06:44 -0500 Subject: [PATCH 22/28] rolled im review comments --- .../src/main/java/com/java/inspector/InspectorScenario.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java index 7167de7ee83..c1bf096a2bc 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java @@ -162,7 +162,7 @@ public static void runScenario(InspectorActions actions) { logger.info(DASHES); logger.info("Step 9: Delete filter?"); logger.info("Filter ARN: {}", filterArn); - logger.info("Delete filter? (y/n)"); + logger.info("Delete the filter and disable Inspector? (y/n)"); if (scanner.nextLine().trim().equalsIgnoreCase("y")) { actions.deleteFilterAsync(filterArn).join(); From aad6ab2dcd33ce0d4bb8e60c00c4dca569891cc9 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 12:11:35 -0500 Subject: [PATCH 23/28] updated the readme --- javav2/example_code/inspector/README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/javav2/example_code/inspector/README.md b/javav2/example_code/inspector/README.md index 6c722f8ec30..a6a77524f29 100644 --- a/javav2/example_code/inspector/README.md +++ b/javav2/example_code/inspector/README.md @@ -31,7 +31,7 @@ For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav ### Get started -- [Hello Amazon Inspector](src/main/java/com/java/inspector/HelloInspector.java#L26) (`BatchGetAccountStatus`) +- [Hello Amazon Inspector](src/main/java/com/java/inspector/HelloInspector.java#L29) (`ListMembers`) ### Basics @@ -45,16 +45,17 @@ Code examples that show you how to perform the essential operations within a ser Code excerpts that show you how to call individual service functions. -- [BatchGetAccountStatus](src/main/java/com/java/inspector/InspectorActions.java#L245) -- [BatchGetFindingDetails](src/main/java/com/java/inspector/InspectorActions.java#L628) -- [CreateFilter](src/main/java/com/java/inspector/InspectorActions.java#L370) -- [DeleteFilter](src/main/java/com/java/inspector/InspectorActions.java#L598) -- [Enable](src/main/java/com/java/inspector/InspectorActions.java#L54) -- [ListCoverage](src/main/java/com/java/inspector/InspectorActions.java#L493) -- [ListCoverageStatistics](src/main/java/com/java/inspector/InspectorActions.java#L126) -- [ListFilters](src/main/java/com/java/inspector/InspectorActions.java#L324) -- [ListFindings](src/main/java/com/java/inspector/InspectorActions.java#L434) -- [ListUsageTotals](src/main/java/com/java/inspector/InspectorActions.java#L183) +- [BatchGetAccountStatus](src/main/java/com/java/inspector/InspectorActions.java#L246) +- [BatchGetFindingDetails](src/main/java/com/java/inspector/InspectorActions.java#L591) +- [CreateFilter](src/main/java/com/java/inspector/InspectorActions.java#L371) +- [DeleteFilter](src/main/java/com/java/inspector/InspectorActions.java#L561) +- [Disable](src/main/java/com/java/inspector/InspectorActions.java#L674) +- [Enable](src/main/java/com/java/inspector/InspectorActions.java#L55) +- [ListCoverage](src/main/java/com/java/inspector/InspectorActions.java#L494) +- [ListCoverageStatistics](src/main/java/com/java/inspector/InspectorActions.java#L127) +- [ListFilters](src/main/java/com/java/inspector/InspectorActions.java#L325) +- [ListFindings](src/main/java/com/java/inspector/InspectorActions.java#L435) +- [ListUsageTotals](src/main/java/com/java/inspector/InspectorActions.java#L184) From 989c83ae3cb666018ba8e5337a205053bfa60e2f Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 12:20:46 -0500 Subject: [PATCH 24/28] updated Scenario --- .../java/com/java/inspector/InspectorScenario.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java index c1bf096a2bc..43265b6f1ad 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java @@ -5,7 +5,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import java.util.Scanner; // snippet-start:[inspector.java2_scenario.main] @@ -71,17 +70,8 @@ Amazon Inspector is a security assessment service provided by Amazon Web Service * Runs the Inspector scenario in a step-by-step sequence. * * All InspectorActions methods are asynchronous and return CompletableFutures. - * Each step ends with .join(). - * - * - * Error handling: - * • runScenario() intentionally does not catch any exceptions - * • Any async exception thrown during .join() will bubble up - * • The main() method contains a single top-level try/catch, - * which logs failures and ends the scenario gracefully + * Each step ends with .join(). Any async exception thrown during .join() will bubble up * - * This design keeps the scenario readable while still demonstrating proper - * asynchronous Inspector2 usage, pagination, and exception propagation. */ public static void runScenario(InspectorActions actions) { From 1c6666069e5cc483de66fe2261c3a2865e907413 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 13:28:28 -0500 Subject: [PATCH 25/28] updated Scenario --- .../com/java/inspector/InspectorScenario.java | 176 ++++++++++-------- 1 file changed, 101 insertions(+), 75 deletions(-) diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java index 43265b6f1ad..03cf13ba31a 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java @@ -74,95 +74,121 @@ Amazon Inspector is a security assessment service provided by Amazon Web Service * */ public static void runScenario(InspectorActions actions) { + String filterArn = null; + boolean inspectorEnabled = false; - // Step 1 - logger.info(DASHES); - logger.info("Step 1: Checking Inspector account status..."); - String status = actions.getAccountStatusAsync().join(); - logger.info(status); - waitForInputToContinue(); + try { + // Step 1 + logger.info(DASHES); + logger.info("Step 1: Checking Inspector account status..."); + String status = actions.getAccountStatusAsync().join(); + logger.info(status); + waitForInputToContinue(); - // Step 2 - logger.info(DASHES); - logger.info("Step 2: Enabling Inspector..."); - String message = actions.enableInspectorAsync(null).join(); - logger.info(message); - waitForInputToContinue(); + // Step 2 + logger.info(DASHES); + logger.info("Step 2: Enabling Inspector..."); + String message = actions.enableInspectorAsync(null).join(); + logger.info(message); + inspectorEnabled = true; // track that Inspector was enabled + waitForInputToContinue(); + + // Step 3 + logger.info(DASHES); + logger.info("Step 3: Listing findings..."); + String allFindings = actions.listLowSeverityFindingsAsync().join(); - // Step 3 - logger.info(DASHES); - logger.info("Step 3: Listing findings..."); - String allFindings = actions.listLowSeverityFindingsAsync().join(); + if (!allFindings.equals("No findings found.")) { + String[] arns = allFindings.split("\\r?\\n"); + String lastArn = arns[arns.length - 1]; - if (!allFindings.equals("No findings found.")) { - // Split by newline and get the last ARN - String[] arns = allFindings.split("\\r?\\n"); - String lastArn = arns[arns.length - 1]; + logger.info("Look up details on: {}", lastArn); + waitForInputToContinue(); + String details = actions.getFindingDetailsAsync(lastArn).join(); + logger.info(details); + } else { + logger.info("No findings found."); + } - // Looks up details - logger.info("Look up details on: {}" , lastArn); waitForInputToContinue(); - String details = actions.getFindingDetailsAsync(lastArn).join() ; - logger.info(details); - } else { - System.out.println("No findings found."); - } - waitForInputToContinue(); + // Step 4 + logger.info(DASHES); + logger.info("Step 4: Listing coverage..."); + String coverage = actions.listCoverageAsync(5).join(); + logger.info(coverage); + waitForInputToContinue(); - // Step 4 - logger.info(DASHES); - logger.info("Step 4: Listing coverage..."); - String coverage = actions.listCoverageAsync(5).join(); - logger.info(coverage); - waitForInputToContinue(); + // Step 5 + logger.info(DASHES); + logger.info("Step 5: Creating filter..."); + String filterName = "suppress-low-" + System.currentTimeMillis(); + filterArn = actions.createLowSeverityFilterAsync(filterName, "Suppress low severity findings").join(); + logger.info("Created filter: {}", filterArn); + waitForInputToContinue(); - // Step 5 - logger.info(DASHES); - logger.info("Step 5: Creating filter..."); - String filterName = "suppress-low-" + System.currentTimeMillis(); - String filterArn = actions - .createLowSeverityFilterAsync(filterName, "Suppress low severity findings") - .join(); - logger.info("Created filter: {}", filterArn); - waitForInputToContinue(); + // Step 6 + logger.info(DASHES); + logger.info("Step 6: Listing filters..."); + String filters = actions.listFiltersAsync(10).join(); + logger.info(filters); + waitForInputToContinue(); - // Step 6 - logger.info(DASHES); - logger.info("Step 6: Listing filters..."); - String filters = actions.listFiltersAsync(10).join(); - logger.info(filters); - waitForInputToContinue(); + // Step 7 + logger.info(DASHES); + logger.info("Step 7: Usage totals..."); + String usage = actions.listUsageTotalsAsync(null, 10).join(); + logger.info(usage); + waitForInputToContinue(); - // Step 7 - logger.info(DASHES); - logger.info("Step 7: Usage totals..."); - String usage = actions.listUsageTotalsAsync(null, 10).join(); - logger.info(usage); - waitForInputToContinue(); + // Step 8 + logger.info(DASHES); + logger.info("Step 8: Coverage statistics..."); + String stats = actions.listCoverageStatisticsAsync().join(); + logger.info(stats); + waitForInputToContinue(); - // Step 8 - logger.info(DASHES); - logger.info("Step 8: Coverage statistics..."); - String stats = actions.listCoverageStatisticsAsync().join(); - logger.info(stats); - waitForInputToContinue(); + // Step 9 + logger.info(DASHES); + logger.info("Step 9: Delete filter?"); + logger.info("Filter ARN: {}", filterArn); + logger.info("Delete the filter and disable Inspector? (y/n)"); - // Step 9 - logger.info(DASHES); - logger.info("Step 9: Delete filter?"); - logger.info("Filter ARN: {}", filterArn); - logger.info("Delete the filter and disable Inspector? (y/n)"); - - if (scanner.nextLine().trim().equalsIgnoreCase("y")) { - actions.deleteFilterAsync(filterArn).join(); - logger.info("Filter deleted."); - logger.info("Disable Inspector ."); - String disableMsg = actions.disableInspectorAsync(null).join(); - logger.info(disableMsg); - } + if (scanner.nextLine().trim().equalsIgnoreCase("y")) { + actions.deleteFilterAsync(filterArn).join(); + logger.info("Filter deleted."); + String disableMsg = actions.disableInspectorAsync(null).join(); + logger.info(disableMsg); + inspectorEnabled = false; // track that Inspector was disabled + } - waitForInputToContinue(); + waitForInputToContinue(); + + } catch (Exception ex) { + logger.error("Scenario encountered an error: {}", ex.getMessage(), ex); + // Rethrow the exception + throw ex; + + } finally { + // Cleanup in case of an exception + if (filterArn != null) { + try { + actions.deleteFilterAsync(filterArn).join(); + logger.info("Cleanup: Filter deleted."); + } catch (Exception e) { + logger.warn("Failed to delete filter during cleanup: {}", e.getMessage(), e); + } + } + + if (inspectorEnabled) { + try { + actions.disableInspectorAsync(null).join(); + logger.info("Cleanup: Inspector disabled."); + } catch (Exception e) { + logger.warn("Failed to disable Inspector during cleanup: {}", e.getMessage(), e); + } + } + } } // Utility Method From 3b9fff800316cfc743c8de0ac98e79e841af7e6c Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 14:08:33 -0500 Subject: [PATCH 26/28] updated Scenario --- .../com/java/inspector/InspectorActions.java | 14 ++++------- .../com/java/inspector/InspectorScenario.java | 15 ++++++----- .../src/test/java/InspectorTests.java | 25 +++++++++++-------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java index 5d18a671dbd..d8e91de990e 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorActions.java @@ -437,9 +437,10 @@ public CompletableFuture createLowSeverityFilterAsync( /** * Lists all AWS Inspector findings of LOW severity asynchronously. * - * @return CompletableFuture containing either "No findings found." or the ARNs of all LOW findings. + * @return CompletableFuture containing a List of finding ARNs. + * Returns an empty list if no LOW severity findings are found. */ - public CompletableFuture listLowSeverityFindingsAsync() { + public CompletableFuture> listLowSeverityFindingsAsync() { logger.info("Starting async LOW severity findings paginator…"); // Build a filter criteria for LOW severity. @@ -471,13 +472,7 @@ public CompletableFuture listLowSeverityFindingsAsync() { } }) .thenRun(() -> logger.info("Successfully listed all LOW severity findings.")) - .thenApply(v -> { - if (allArns.isEmpty()) { - return "No LOW severity findings found."; - } else { - return String.join("\n", allArns); - } - }) + .thenApply(v -> new ArrayList<>(allArns)) // Return list instead of a formatted string .exceptionally(ex -> { Throwable cause = ex.getCause() != null ? ex.getCause() : ex; if (cause instanceof ValidationException ve) { @@ -489,6 +484,7 @@ public CompletableFuture listLowSeverityFindingsAsync() { throw new RuntimeException("Failed to list LOW severity findings", ex); }); } + // snippet-end:[inspector.java2.list_findings.main] // snippet-start:[inspector.java2.list_coverage.main] diff --git a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java index 03cf13ba31a..dcbbad9c4a1 100644 --- a/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java +++ b/javav2/example_code/inspector/src/main/java/com/java/inspector/InspectorScenario.java @@ -5,6 +5,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.util.List; import java.util.Scanner; // snippet-start:[inspector.java2_scenario.main] @@ -95,19 +97,20 @@ public static void runScenario(InspectorActions actions) { // Step 3 logger.info(DASHES); - logger.info("Step 3: Listing findings..."); - String allFindings = actions.listLowSeverityFindingsAsync().join(); + logger.info("Step 3: Listing LOW severity findings..."); - if (!allFindings.equals("No findings found.")) { - String[] arns = allFindings.split("\\r?\\n"); - String lastArn = arns[arns.length - 1]; + // Call the service method + List allFindings = actions.listLowSeverityFindingsAsync().join(); + if (!allFindings.isEmpty()) { + // Only proceed if there are findings + String lastArn = allFindings.get(allFindings.size() - 1); logger.info("Look up details on: {}", lastArn); waitForInputToContinue(); String details = actions.getFindingDetailsAsync(lastArn).join(); logger.info(details); } else { - logger.info("No findings found."); + logger.info("No LOW severity findings found."); } waitForInputToContinue(); diff --git a/javav2/example_code/inspector/src/test/java/InspectorTests.java b/javav2/example_code/inspector/src/test/java/InspectorTests.java index 7fdee72a73c..b48edc08d17 100644 --- a/javav2/example_code/inspector/src/test/java/InspectorTests.java +++ b/javav2/example_code/inspector/src/test/java/InspectorTests.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.PrintStream; import java.util.Collections; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -72,19 +73,23 @@ public void testInspectorActionsIntegration() { inspectorActions.enableInspectorAsync(null).join(); - String allFindings = inspectorActions.listLowSeverityFindingsAsync().join(); - // Check if any findings were returned - if (allFindings == null || allFindings.startsWith("No LOW severity findings")) { - logger.info("No LOW severity findings available. Skipping details lookup."); + List allFindings = inspectorActions.listLowSeverityFindingsAsync().join(); + + if (allFindings.isEmpty()) { + logger.info("No LOW severity findings found."); } else { - String[] arns = allFindings.split("\\r?\\n"); - String lastArn = arns[arns.length - 1]; + logger.info("Found {} LOW severity findings.", allFindings.size()); - // Fetch details safely - String details = inspectorActions.getFindingDetailsAsync(lastArn).join(); - logger.info("Details for last LOW severity finding:\n{}", details); - } + // Optionally, iterate over all findings to test getFindingDetailsAsync + for (String arn : allFindings) { + logger.info("Fetching details for finding ARN: {}", arn); + String details = inspectorActions.getFindingDetailsAsync(arn).join(); + // Check details are not empty/null + assertNotNull(details, "Finding details should not be null"); + assertFalse(details.isEmpty(), "Finding details should not be empty"); + } + } maxResults = 5; inspectorActions.listCoverageAsync(maxResults).join(); From 5378cf961970823ea2576c88b844304431a39576 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 14:17:04 -0500 Subject: [PATCH 27/28] updated Tests --- .../src/test/java/InspectorTests.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/javav2/example_code/inspector/src/test/java/InspectorTests.java b/javav2/example_code/inspector/src/test/java/InspectorTests.java index b48edc08d17..e5ff85ca7cb 100644 --- a/javav2/example_code/inspector/src/test/java/InspectorTests.java +++ b/javav2/example_code/inspector/src/test/java/InspectorTests.java @@ -74,21 +74,18 @@ public void testInspectorActionsIntegration() { inspectorActions.enableInspectorAsync(null).join(); List allFindings = inspectorActions.listLowSeverityFindingsAsync().join(); + if (!allFindings.isEmpty()) { + // Only proceed if there are findings + String lastArn = allFindings.get(allFindings.size() - 1); + logger.info("Fetching details for last finding ARN: {}", lastArn); - if (allFindings.isEmpty()) { - logger.info("No LOW severity findings found."); - } else { - logger.info("Found {} LOW severity findings.", allFindings.size()); - - // Optionally, iterate over all findings to test getFindingDetailsAsync - for (String arn : allFindings) { - logger.info("Fetching details for finding ARN: {}", arn); - String details = inspectorActions.getFindingDetailsAsync(arn).join(); + String details = inspectorActions.getFindingDetailsAsync(lastArn).join(); - // Check details are not empty/null - assertNotNull(details, "Finding details should not be null"); - assertFalse(details.isEmpty(), "Finding details should not be empty"); - } + // Check details are not empty/null + assertNotNull(details, "Finding details should not be null"); + assertFalse(details.isEmpty(), "Finding details should not be empty"); + } else { + logger.info("No LOW severity findings found."); } maxResults = 5; From 3538f39e7045e6962a048724bc84ddf049022d79 Mon Sep 17 00:00:00 2001 From: Scott Macdonald Date: Tue, 16 Dec 2025 14:22:03 -0500 Subject: [PATCH 28/28] updated readme --- javav2/example_code/inspector/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/javav2/example_code/inspector/README.md b/javav2/example_code/inspector/README.md index a6a77524f29..39146582ba5 100644 --- a/javav2/example_code/inspector/README.md +++ b/javav2/example_code/inspector/README.md @@ -46,12 +46,12 @@ Code examples that show you how to perform the essential operations within a ser Code excerpts that show you how to call individual service functions. - [BatchGetAccountStatus](src/main/java/com/java/inspector/InspectorActions.java#L246) -- [BatchGetFindingDetails](src/main/java/com/java/inspector/InspectorActions.java#L591) +- [BatchGetFindingDetails](src/main/java/com/java/inspector/InspectorActions.java#L587) - [CreateFilter](src/main/java/com/java/inspector/InspectorActions.java#L371) -- [DeleteFilter](src/main/java/com/java/inspector/InspectorActions.java#L561) -- [Disable](src/main/java/com/java/inspector/InspectorActions.java#L674) +- [DeleteFilter](src/main/java/com/java/inspector/InspectorActions.java#L557) +- [Disable](src/main/java/com/java/inspector/InspectorActions.java#L670) - [Enable](src/main/java/com/java/inspector/InspectorActions.java#L55) -- [ListCoverage](src/main/java/com/java/inspector/InspectorActions.java#L494) +- [ListCoverage](src/main/java/com/java/inspector/InspectorActions.java#L490) - [ListCoverageStatistics](src/main/java/com/java/inspector/InspectorActions.java#L127) - [ListFilters](src/main/java/com/java/inspector/InspectorActions.java#L325) - [ListFindings](src/main/java/com/java/inspector/InspectorActions.java#L435)