gpt4 book ai didi

amazon-web-services - ElasticBeanstalk 客户端

转载 作者:行者123 更新时间:2023-12-02 07:33:23 28 4
gpt4 key购买 nike

我尝试开发一个Elastic beanstalk客户端接口(interface),通过它连接到我的亚马逊帐户elasticbeanstalk。我使用了脚本文件 credentials.Csl 中的帐户凭据。我从 Google Chrome 注册了我的帐户,但遇到错误。这是我的代码。

package PFE;


import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalk;
import com.amazonaws.services.elasticbeanstalk.AWSElasticBeanstalkClient;
import com.amazonaws.services.elasticbeanstalk.model.CheckDNSAvailabilityResult;

public class Sample {

static AWSElasticBeanstalk eb;

private static void init()throws Exception{


/*
* The ProfileCredentialsProvider will return your [default]
* credential profile by reading from the credentials file located at
* (~/.aws/credentials).
*/
AWSCredentials credentials = null;

try {

credentials = new ProfileCredentialsProvider().getCredentials();

} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}

eb = new AWSElasticBeanstalkClient(credentials);
Region usWest2 = Region.getRegion(Regions.US_WEST_2);
eb.setRegion(usWest2);
}

public static void main(String[] args) throws Exception {

init();
try {
CheckDNSAvailabilityResult c= eb.checkDNSAvailability(null);

System.out.println("You have access to " + c.getAvailable() +
" Availability Zones.")

eb.createStorageLocation();

} catch (AmazonServiceException ase) {
System.out.println("Caught Exception: " + ase.getMessage());
System.out.println("Reponse Status Code: " + ase.getStatusCode());
System.out.println("Error Code: " + ase.getErrorCode());
System.out.println("Request ID: " + ase.getRequestId());
}
}

}

这是我在运行项目时遇到的错误

 Exception in thread "main" java.lang.NoClassDefFoundError:org/apache/commons/logging/LogFactory at com.amazonaws.auth.profile.ProfilesConfigFile.<clinit>(ProfilesConfigFile.java:62) at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:106)
at PFE.Sample.init(Sample.java:29)
at PFE.Sample.main(Sample.java:47)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

我认为问题出在 org.apache.commons.logging.LogFactory 库上,因此我下载了它并将其添加到我引用的库中,但我仍然遇到相同的错误。

最佳答案

我在尝试制作 SQS 示例时遇到了同样的错误...我的解决方案是:不要将 AWS SDK for Java 添加为外部 jar

Don't

但作为一个图书馆。

enter image description here

关于amazon-web-services - ElasticBeanstalk 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24678297/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com