GetOpsItem.java - AWS Code Sample

GetOpsItem.java

GetOpsItem.java demonstrates how to get information about an OpsItem by using the ID value.

/** * Copyright Amazon.com, 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 * * http://aws.amazon.com/apache2.0/ * * 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.ssm; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.ssm.SsmClient; import software.amazon.awssdk.services.ssm.model.GetOpsItemResponse; import software.amazon.awssdk.services.ssm.model.GetOpsItemRequest; import software.amazon.awssdk.services.ssm.model.OpsItem; import software.amazon.awssdk.services.ssm.model.SsmException; public class GetOpsItem { public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " GetOpsItem <opsID>\n\n" + "Where:\n" + " opsID - The OpsItem ID value.\n"; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } /* Read the name from command args */ String opsID = args[0]; Region region = Region.US_EAST_1; SsmClient ssmClient = SsmClient.builder() .region(region) .build(); getOpsItem(ssmClient, opsID ); } public static void getOpsItem(SsmClient ssmClient, String opsID ) { try { // Create a DescribeParametersRequest object GetOpsItemRequest opsRequest = GetOpsItemRequest.builder() .opsItemId(opsID) .build(); // Get SSM parameters (you can define them in the AWS Management Console) GetOpsItemResponse opsItem = ssmClient.getOpsItem(opsRequest); OpsItem item = opsItem.opsItem(); System.out.println(item.title()); System.out.println(item.description()); System.out.println(item.source()); } catch (SsmException e) { System.err.println(e.getMessage()); System.exit(1); } } }

Sample Details

Service: ssm

Last tested: 2020-09-10

Author: AWS - scmacdon

Type: full-example