Code examples for Systems Manager using AWS SDKs - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Code examples for Systems Manager using AWS SDKs

The following code examples show you how to use AWS Systems Manager with an AWS software development kit (SDK).

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

More resources

Get started

The following code example shows how to get started using Systems Manager.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.ssm.SsmClient; import software.amazon.awssdk.services.ssm.model.DocumentFilter; import software.amazon.awssdk.services.ssm.model.ListDocumentsRequest; import software.amazon.awssdk.services.ssm.model.ListDocumentsResponse; public class HelloSSM { public static void main(String[] args) { final String usage = """ Usage: <awsAccount> Where: awsAccount - Your AWS Account number. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String awsAccount = args[0] ; Region region = Region.US_EAST_1; SsmClient ssmClient = SsmClient.builder() .region(region) .build(); listDocuments(ssmClient, awsAccount); } /* This code automatically fetches the next set of results using the `nextToken` and stops once the desired maxResults (20 in this case) have been reached. */ public static void listDocuments(SsmClient ssmClient, String awsAccount) { String nextToken = null; int totalDocumentsReturned = 0; int maxResults = 20; do { ListDocumentsRequest request = ListDocumentsRequest.builder() .documentFilterList( DocumentFilter.builder() .key("Owner") .value(awsAccount) .build() ) .maxResults(maxResults) .nextToken(nextToken) .build(); ListDocumentsResponse response = ssmClient.listDocuments(request); response.documentIdentifiers().forEach(identifier -> System.out.println("Document Name: " + identifier.name())); nextToken = response.nextToken(); totalDocumentsReturned += response.documentIdentifiers().size(); } while (nextToken != null && totalDocumentsReturned < maxResults); } }
  • For API details, see listThings in AWS SDK for Java 2.x API Reference.

Code examples