我有问题初始化API网关客户端在Java使用AWS-Java-SDK(尝试旧版本和最新版本)。我已经检查了10次,如果我的访问和密钥是正确的,他们是。我不知道我的错误编码,所以它停止工作后,“良好2”输出。需要帮助,请
下面是我的代码:
public void startAPIGateway() {
callbacks.printOutput("Starting API Gateway");
String API_NAME = "Testing";
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKeyField.getText(), secretKeyField.getText());
callbacks.printOutput("Good 1");
// Create an AWSStaticCredentialsProvider object with the credentials
AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
callbacks.printOutput("Good 2");
// Create an AwsClientBuilder object with the region and endpoint;
AmazonApiGatewayClientBuilder clientBuilder = AmazonApiGatewayClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://apigateway.eu-east-2.amazonaws.com", "eu-east-2"));
callbacks.printOutput("Good 3");
// Set the credentials provider on the client builder
clientBuilder.setCredentials(credentialsProvider);
clientBuilder.setRegion("eu-east-2");
AmazonApiGateway client = clientBuilder.build();
callbacks.printOutput("Goodzzzz");
CreateRestApiRequest restApiRequest = new CreateRestApiRequest().withName(API_NAME);
CreateRestApiResult createRestApiResult = client.createRestApi(restApiRequest);
callbacks.printOutput(createRestApiResult.getId());
// Add a new resource with a path variable
GetResourcesRequest getResourcesRequest = new GetResourcesRequest()
.withRestApiId(createRestApiResult.getId());
GetResourcesResult getResourcesResult = client.getResources(getResourcesRequest);
CreateResourceRequest createResourceRequest = new CreateResourceRequest()
.withRestApiId(createRestApiResult.getId())
.withParentId(getResourcesResult.getItems().get(0).getId())
.withPathPart("{proxy+}");
CreateResourceResult createResourceResult = client.createResource(createResourceRequest);
}
2条答案
按热度按时间nbnkbykc1#
您正在使用旧的Java V1 API。AWS SDK Java团队不再建议您使用此API。您应考虑迁移到AWS SDK for Java V2。您可以在此处阅读有关此SDK版本的信息:
Developer guide - AWS SDK for Java 2.x
要使此服务与V2一起工作,请在.aws文件夹中设置您的凭据,如下面的DEV指南中所述:
请参阅此主题:
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials.html
无需在代码中指定凭据。根据文档设置凭据后,即可成功使用ApiGatewayClient。
此代码示例演示如何获取有关当前ApiKeys的信息。
下面的屏幕截图显示了这段代码的工作情况和输出。
sbtkgmzw2#
安装了AWS SDK for Java 2 by Maven并添加了以下代码,但我的Burp扩展仍然无法正常工作:
结果是: