提供Properties文件MultiLangDaemon以使用AWS S3 KMS Java。以下是示例代码:
aws.endpoint=http://s3.amazonaws.com s3.region=us-west-2 aws.accessKeyId=YOUR_ACCESS_KEY aws.secretKey=YOUR_SECRET_KEY
public class MyMultiLangDaemon {
public static void main(String[] args) throws IOException {
Properties props = loadPropertiesFile();
// Use the properties to configure AWS S3 client
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withRegion(props.getProperty("s3.region"))
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(
props.getProperty("aws.accessKeyId"),
props.getProperty("aws.secretKey")
)
))
.build();
// Your logic here
}
private static Properties loadPropertiesFile() throws IOException {
String fileName = "MultiLangDaemon.properties";
Properties props = new Properties();
try (InputStream inputStream = Main.class.getClassLoader().getResourceAsStream(fileName)) {
if (inputStream == null) {
throw new FileNotFoundException(String.format("File %s not found on classpath", fileName));
}
props.load(inputStream);
return props;
}
}
}
下一篇:AWSS3空桶策略