使用 AWS 重新启动应用程序服务器 API

Restarting app server using AWS API

我需要重新启动我的 AWS 应用程序服务器,为此我尝试使用 AWS API 并完成了以下操作:

1) 使用 aws java sdk maven 存储库

   <dependency>
      <groupId>com.amazonaws</groupId>
         <artifactId>aws-java-sdk-elasticbeanstalk</artifactId>
             <version>1.11.86</version>
   </dependency>

2) 使用了以下代码段:

   AWSElasticBeanstalk client = new AWSElasticBeanstalkClient();
   RestartAppServerRequest request = new RestartAppServerRequest()
                                .withEnvironmentId("<myEnvId>")
                            .withEnvironmentName("<myEnvName>");
   RestartAppServerResult response = client.restartAppServer(request);

我收到以下错误:

com.amazonaws.services.elasticbeanstalk.model.AWSElasticBeanstalkException: No Environment found for EnvironmentId = ''. (Service: AWSElasticBeanstalk; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 4d025449-ed00-11e6-8405-4d5eb8e5ecd9)

<myEnvId><myEnvName> 是正确的,因为它们取自 AWS 仪表板。

我还尝试将 aws.accessKeyIdaws.secretKey 包括到 java 系统属性。我仍然得到同样的错误。

有没有我遗漏或做错了什么?请指教

谢谢,

克莱德

听起来你需要配置区域。例如,要将区域配置为 us-west-2,您可以使用以下代码:

AWSElasticBeanstalk client = new AWSElasticBeanstalkClient();
client.configureRegion(Regions.US_WEST_2);

感谢所有发布者。我设法解决了这个问题。使用的代码段如下:

    AWSElasticBeanstalk client = new AWSElasticBeanstalkClient(); 
    client.setEndpoint(<set your endpoint>);
    RestartAppServerRequest request = new RestartAppServerRequest()
            .withEnvironmentId(<set your env id>)
            .withEnvironmentName(<set your env name>);
    RestartAppServerResult response = client.restartAppServer(request);

这个找到了。