与 AWS SDK或DescribeParameters一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或DescribeParameters一起使用 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 描述参数——过滤器 “键=类型,值=” 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": [] } ] }

有关更多信息,请参阅《AWS Systems Manager 用户指南》中的搜索 Systems Manager 参数

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详细信息,请参阅 “AWS SDK for Java 2.x API参考 DescribeParameters” 中的。

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对于 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(()) }