AWS describeLogGroups()不返回日志组。谁有人面对这个?如果是的话,你是如何克服的?这是代码......
import java.util.List;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.logs.AWSLogsClient;
import com.amazonaws.services.logs.model.DescribeLogGroupsResult;
import com.amazonaws.services.logs.model.LogGroup;
public class MyAWSLogGroups {
public static void main(String[] args) {
AWSCredentials credentials = new ProfileCredentialsProvider().getCredentials();
AWSLogsClient client = new AWSLogsClient(credentials);
DescribeLogGroupsResult logGroupsResult = client.describeLogGroups();
List<LogGroup> logGroups = logGroupsResult.getLogGroups();
// why does logGroups.size() return 0 ?
System.out.println("=> Number of Log Groups: " + logGroups.size());
for (LogGroup lg : logGroups) {
String logGroupName = lg.getLogGroupName();
System.out.println(logGroupName);
}
}
}
此AWS CLI显示日志组...
$ aws logs describe-log-groups
答案 0 :(得分:0)
我知道这有点晚了,但我自己也遇到了这个问题。您的Cloudfront日志是否在美国东部以外的地区?
我们在美国西部。 Java SKD defaults to us-east-1但您可能刚刚设置了客户端默认区域。
使用客户端上的configureRegion继承方法设置您的位置区域。从区域class documentation获取您的区域枚举。
对我来说,解决方案是这样的(使用上面的示例代码):
import java.util.List;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.logs.AWSLogsClient;
import com.amazonaws.services.logs.model.DescribeLogGroupsResult;
import com.amazonaws.services.logs.model.LogGroup;
import com.amazonaws.regions.Regions;
public class MyAWSLogGroups {
public static void main(String[] args) {
AWSCredentials credentials = new ProfileCredentialsProvider().getCredentials();
AWSLogsClient client = new AWSLogsClient(credentials);
client.configureRegion(Regions.US_WEST_2);
DescribeLogGroupsResult logGroupsResult = client.describeLogGroups();
List<LogGroup> logGroups = logGroupsResult.getLogGroups();
// why does logGroups.size() return 0 ?
System.out.println("=> Number of Log Groups: " + logGroups.size());
for (LogGroup lg : logGroups) {
String logGroupName = lg.getLogGroupName();
System.out.println(logGroupName);
}
}
}