を使用した Systems Manager のコード例 AWS SDKs - AWS SDK コード例

AWS Doc SDK Examples GitHub リポジトリには他にも AWS SDK例があります。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

を使用した Systems Manager のコード例 AWS SDKs

次のコード例は、 ソフトウェア AWS 開発キット () AWS Systems Manager で を使用する方法を示していますSDK。

「基本」は、重要なオペレーションをサービス内で実行する方法を示すコード例です。

アクションはより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

その他のリソース

開始方法

次のコード例は、Systems Manager の使用を開始する方法を示しています。

Java
SDK for Java 2.x
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

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); } }
  • API 詳細については、「 リファレンスlistThings」の「」を参照してください。 AWS SDK for Java 2.x API

Python
SDK for Python (Boto3)
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

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"])
  • API 詳細については、listThings「 for AWS SDK Python (Boto3) APIリファレンス」の「」を参照してください。

コードの例