请参阅以下用于列出RDS(Mysql)中可用日志文件的代码
AWSCredentials credentials = new BasicAWSCredentials("XXX", "XXX");
AWSCredentialsProvider provider = new StaticCredentialsProvider(credentials);
AmazonRDS rdsClient = AmazonRDSClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("XXXX.us-west-2.rds.amazonaws.com:3306", "us-west-2"))
.withCredentials(provider)
.build();
DescribeDBLogFilesRequest request = new DescribeDBLogFilesRequest();
DescribeDBLogFilesResult response = rdsClient.describeDBLogFiles(request);
List<DescribeDBLogFilesDetails> listOfFiles = response.getDescribeDBLogFiles();
System.out.println(listOfFiles.toString());
System.out.println("Program done");
这是我的pom.xml依赖项:
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-rds -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-rds</artifactId>
<version>1.11.101</version>
</dependency>
使用上述代码时我遇到异常。
答案 0 :(得分:1)
错误在于:
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("XXXX.us-west-2.rds.amazonaws.com:3306", "us-west-2"))
您尝试使用SDK连接到实际的RDS 实例,这不是正确的方法。您需要连接到RDS Query API Endpoint。这些请求通过服务发送。
您应该能够简单地使用.withRegion()
,而不必实际提供端点URL,因为端点对于区域内的所有RDS实例都是相同的,并且默认的区域URL被编码到SDK中