gpt4 book ai didi

java - 寻找示例代码从 aws 参数存储中读取参数值

转载 作者:行者123 更新时间:2023-12-01 16:20:36 26 4
gpt4 key购买 nike

寻找示例java代码来从aws参数存储中读取参数存储值,例如RDS连接字符串。欣赏代码或任何引用链接。谢谢。

最佳答案

以下是从 AWS 参数存储中读取特定参数值的 V2(而非 V1)示例:

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;

public class GetParameter {

public static void main(String[] args) {

final String USAGE = "\n" +
"Usage:\n" +
" GetParameter <paraName>\n\n" +
"Where:\n" +
" paraName - the name of the parameter\n";

if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}

// Get args
String paraName = args[0];

Region region = Region.US_EAST_1;
SsmClient ssmClient = SsmClient.builder()
.region(region)
.build();

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);
}
}
}

关于java - 寻找示例代码从 aws 参数存储中读取参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62294751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com