本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DescribeParameters
搭配 AWS SDK或 使用 CLI
下列程式碼範例示範如何使用 DescribeParameters
。
- CLI
-
- AWS CLI
-
範例 1:列出所有參數
下列
describe-parameters
範例會列出目前 AWS 帳戶和區域中的所有參數。aws ssm describe-parameters
輸出:
{ "Parameters": [ { "Name": "MySecureStringParameter", "Type": "SecureString", "KeyId": "alias/aws/ssm", "LastModifiedDate": 1582155479.205, "LastModifiedUser": "arn:aws:sts::111222333444:assumed-role/Admin/Richard-Roe-Managed", "Description": "This is a SecureString parameter", "Version": 2, "Tier": "Advanced", "Policies": [ { "PolicyText": "{\"Type\":\"Expiration\",\"Version\":\"1.0\",\"Attributes\":{\"Timestamp\":\"2020-07-07T22:30:00Z\"}}", "PolicyType": "Expiration", "PolicyStatus": "Pending" }, { "PolicyText": "{\"Type\":\"ExpirationNotification\",\"Version\":\"1.0\",\"Attributes\":{\"Before\":\"12\",\"Unit\":\"Hours\"}}", "PolicyType": "ExpirationNotification", "PolicyStatus": "Pending" } ] }, { "Name": "MyStringListParameter", "Type": "StringList", "LastModifiedDate": 1582154764.222, "LastModifiedUser": "arn:aws:iam::111222333444:user/Mary-Major", "Description": "This is a StringList parameter", "Version": 1, "Tier": "Standard", "Policies": [] }, { "Name": "MyStringParameter", "Type": "String", "LastModifiedDate": 1582154711.976, "LastModifiedUser": "arn:aws:iam::111222333444:user/Alejandro-Rosalez", "Description": "This is a String parameter", "Version": 1, "Tier": "Standard", "Policies": [] }, { "Name": "latestAmi", "Type": "String", "LastModifiedDate": 1580862415.521, "LastModifiedUser": "arn:aws:sts::111222333444:assumed-role/lambda-ssm-role/Automation-UpdateSSM-Param", "Version": 3, "Tier": "Standard", "Policies": [] } ] }
範例 2:列出符合特定中繼資料的所有參數
此
describe-parameters
範例會列出符合篩選條件的所有參數。aws ssm describe-parameters --filters "Key=Type,Values=StringList"
輸出:
{ "Parameters": [ { "Name": "MyStringListParameter", "Type": "StringList", "LastModifiedDate": 1582154764.222, "LastModifiedUser": "arn:aws:iam::111222333444:user/Mary-Major", "Description": "This is a StringList parameter", "Version": 1, "Tier": "Standard", "Policies": [] } ] }
如需詳細資訊,請參閱 Systems Manager 使用者指南中的搜尋 Systems Manager 參數AWS 。
-
如需API詳細資訊,請參閱 命令參考 DescribeParameters
中的 。 AWS CLI
-
- Java
-
- SDK 適用於 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.GetParameterRequest; import software.amazon.awssdk.services.ssm.model.GetParameterResponse; import software.amazon.awssdk.services.ssm.model.SsmException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class GetParameter { public static void main(String[] args) { final String usage = """ Usage: <paraName> Where: paraName - The name of the parameter. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String paraName = args[0]; Region region = Region.US_EAST_1; SsmClient ssmClient = SsmClient.builder() .region(region) .build(); getParaValue(ssmClient, paraName); ssmClient.close(); } public static void getParaValue(SsmClient ssmClient, String paraName) { try { GetParameterRequest parameterRequest = GetParameterRequest.builder() .name(paraName) .build(); GetParameterResponse parameterResponse = ssmClient.getParameter(parameterRequest); System.out.println("The parameter value is " + parameterResponse.parameter().value()); } catch (SsmException e) { System.err.println(e.getMessage()); System.exit(1); } } }
-
如需API詳細資訊,請參閱 參考 DescribeParameters中的 。 AWS SDK for Java 2.x API
-
- PowerShell
-
- 適用於 的工具 PowerShell
-
範例 1:此範例會列出所有參數。
Get-SSMParameterList
輸出:
Description : KeyId : LastModifiedDate : 3/3/2017 6:58:23 PM LastModifiedUser : arn:aws:iam::123456789012:user/admin Name : Welcome Type : String
-
如需API詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考 DescribeParameters中的 。
-
- Rust
-
- SDK for Rust
-
注意
還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 async fn show_parameters(client: &Client) -> Result<(), Error> { let resp = client.describe_parameters().send().await?; for param in resp.parameters() { println!(" {}", param.name().unwrap_or_default()); } Ok(()) }
-
如需API詳細資訊,請參閱 DescribeParameters
中的 AWS SDK for Rust API參考 。
-
如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 搭配 使用 Systems Manager AWS SDK。本主題也包含有關入門的資訊,以及先前SDK版本的詳細資訊。