- AWS Code Sample demonstrates how to list detector ID values for existing Amazon GuardDuty detector resources.

/** * Copyright, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * */ package com.example.guardduty; import; import; import; import; import; import; import java.util.ArrayList; import java.util.List; public class GetFindings { public static void main(String[] args) { final String USAGE = "\n" + "To run this example, supply the finding ID value and the detector ID value. \n" + "\n" + "Example: GetFindings <findingId><detectorId>\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String findingId = args[0]; String detectorId = args[1]; Region region = Region.US_EAST_1; GuardDutyClient guardDutyClient = GuardDutyClient.builder() .region(region) .build(); getSpecificFinding(guardDutyClient, findingId, detectorId); } public static void getSpecificFinding(GuardDutyClient guardDutyClient, String findingId, String detectorId) { try { List<String> myIds = new ArrayList<>(); myIds.add(findingId); GetFindingsRequest findingsRequest = GetFindingsRequest.builder() .findingIds(myIds) .detectorId(detectorId) .build(); GetFindingsResponse findingsResponse = guardDutyClient.getFindings(findingsRequest); List<Finding> findings = findingsResponse.findings(); for (Finding finding : findings) { System.out.println("The finding ARN is " + finding.arn()); System.out.println("The resource type is " + finding.resource().resourceType()); } } catch (GuardDutyException e) { System.err.println(e.getMessage()); System.exit(1); } } }

Sample Details

Service: Amazon GuardDuty

Last tested: 2020-09-17

Author: AWS - scmacdon

Type: full-example