如何通过AWS Java SDK请求“快照日志”?

时间:2012-10-10 16:50:47

标签: amazon-web-services elastic-beanstalk

是否可以通过AWS SDK以某种方式请求“快照日志”?

可以通过AWS控制台执行此操作:

enter image description here

交叉发布到Amazon forum

1 个答案:

答案 0 :(得分:2)

请求日志快照是一个3步骤的过程。首先,您必须执行环境信息请求:

elasticBeanstalk.requestEnvironmentInfo(
    new RequestEnvironmentInfoRequest()
        .withEnvironmentName(envionmentName)
        .withInfoType("tail"));

然后你必须检索环境信息:

final List<EnvironmentInfoDescription> envInfos =
     elasticBeanstalk.retrieveEnvironmentInfo(
         new RetrieveEnvironmentInfoRequest()
             .withEnvironmentName(environmentName)
             .withInfoType("tail")).getEnvironmentInfo();

返回环境信息描述列表,其中包含EC2实例ID和包含日志快照的S3对象的URL。然后,您可以使用以下命令检索日志:

    DefaultHttpClient client = new DefaultHttpClient();
    DefaultHttpRequestRetryHandler retryhandler = 
        new DefaultHttpRequestRetryHandler(3, true);
    client.setHttpRequestRetryHandler(retryhandler);

    for (EnvironmentInfoDescription environmentInfoDescription : envInfos) {
        System.out.println(environmentInfoDescription.getEc2InstanceId());
         HttpGet rq = new HttpGet(environmentInfoDescription.getMessage());
         try {                    
             HttpResponse response = client.execute(rq);
             InputStream content = response.getEntity().getContent();                    
             System.out.println(IOUtils.toString(content));
         } catch ( Exception e ) {
             System.out.println("Exception fetching " + 
                 environmentInfoDescription.getMessage());
         }
    }

我希望这有帮助!