• Das AWS Systems Manager CloudWatch Dashboard wird nach dem 30. April 2026 nicht mehr verfügbar sein. Kunden können weiterhin die CloudWatch Amazon-Konsole verwenden, um ihre CloudWatch Amazon-Dashboards anzusehen, zu erstellen und zu verwalten, so wie sie es heute tun. Weitere Informationen finden Sie in der Amazon CloudWatch Dashboard-Dokumentation.
Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
Hallo Systems Manager
Die folgenden Codebeispiele zeigen, wie Sie mit der Verwendung von Systems Manager beginnen.
- Java
-
- SDK für Java 2.x
-
Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel- einrichten und ausführen.
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);
}
}
- JavaScript
-
- SDK für JavaScript (v3)
-
Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel- einrichten und ausführen.
import { paginateListDocuments, SSMClient } from "@aws-sdk/client-ssm";
// Call ListDocuments and display the result.
export const main = async () => {
const client = new SSMClient();
const listDocumentsPaginated = [];
console.log(
"Hello, AWS Systems Manager! Let's list some of your documents:\n",
);
try {
// The paginate function is a wrapper around the base command.
const paginator = paginateListDocuments({ client }, { MaxResults: 5 });
for await (const page of paginator) {
listDocumentsPaginated.push(...page.DocumentIdentifiers);
}
} catch (caught) {
console.error(`There was a problem saying hello: ${caught.message}`);
throw caught;
}
for (const { Name, DocumentFormat, CreatedDate } of listDocumentsPaginated) {
console.log(`${Name} - ${DocumentFormat} - ${CreatedDate}`);
}
};
// Call function if run directly.
import { fileURLToPath } from "node:url";
if (process.argv[1] === fileURLToPath(import.meta.url)) {
main();
}
- Python
-
- SDK für Python (Boto3)
-
Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel- einrichten und ausführen.
import boto3
from botocore.exceptions import ClientError
def hello_systems_manager(ssm_client):
"""
Use the AWS SDK for Python (Boto3) to create an AWS Systems Manager
client and list the first 5 documents in your account.
This example uses the default settings specified in your shared credentials
and config files.
:param ssm_client: A Boto3 AWS Systems Manager Client object. This object wraps
the low-level AWS Systems Manager service API.
"""
print("Hello, AWS Systems Manager! Let's list some of your documents:\n")
paginator = ssm_client.get_paginator("list_documents")
page_iterator = paginator.paginate(PaginationConfig={"MaxItems": 5})
for page in page_iterator:
for document in page["DocumentIdentifiers"]:
print(f" {document['Name']}")
if __name__ == "__main__":
try:
hello_systems_manager(boto3.client("ssm"))
except ClientError as err:
print("Hello systems manager had an error.")
print(err.response["Error"]["Code"])
print(err.response["Error"]["Message"])
Eine vollständige Liste der AWS SDK-Entwicklerhandbücher und Codebeispiele finden Sie unter. Verwenden dieses Dienstes mit einem AWS SDK Dieses Thema enthält auch Informationen zu den ersten Schritten und Details zu früheren SDK-Versionen.