@SuppressWarnings("deprecation") public ApiImporter(String profile, String accessKey, String secret) { if (accessKey != null && secret != null) { credentialsProvider=new AWSCredentialsProvider() { @Override public void refresh() { } @Override public AWSCredentials getCredentials() { return new AWSCredentials() { @Override public String getAWSSecretKey() { return secret; } @Override public String getAWSAccessKeyId() { return accessKey; } }; } }; } else { credentialsProvider = new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(profile), new InstanceProfileCredentialsProvider()); } amazonApiGatewayClient = new AmazonApiGatewayClient(credentialsProvider); }
public void run() { String AWSAccessKey="AKIAJM7YMMLXKUH5EWRQ"; String AWSSecretKey="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"; BasicAWSCredentials awsCredentials = new BasicAWSCredentials(AWSAccessKey, AWSSecretKey); AmazonApiGatewayClient apiClient = new AmazonApiGatewayClient(awsCredentials); apiClient.setRegion(Region.getRegion(Regions.US_WEST_2)); GetRestApisRequest graReq = new GetRestApisRequest(); GetRestApisResult graRes = apiClient.getRestApis(graReq); RestApi theApi = null; for ( RestApi api : graRes.getItems() ) { System.out.println("Found existing REST API: " + api.getName()); if ( "TestAPI".equals(api.getName())) { theApi = api; GetExportRequest geReq = new GetExportRequest() .withRestApiId(api.getId()) .withExportType("swagger") .withStageName("TEST"); GetExportResult geRes = apiClient.getExport(geReq); String f = new String(geRes.getBody().array()); int x = 1; String from = ""; PatchOperation po = new PatchOperation() .withFrom(from) .withOp(Op.Replace) .withPath(""); } } }
protected AmazonApiGateway getApiGatewayClient() { if (apiGatewayClient != null) { return apiGatewayClient; } RetryPolicy.RetryCondition retryCondition = new RetryPolicy.RetryCondition() { @Override public boolean shouldRetry(AmazonWebServiceRequest amazonWebServiceRequest, AmazonClientException amazonClientException, int i) { if (amazonClientException instanceof TooManyRequestsException) { return true; } return PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION.shouldRetry(amazonWebServiceRequest, amazonClientException, i); } }; RetryPolicy retryPolicy = new RetryPolicy(retryCondition, PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, 10, true); ClientConfiguration clientConfig = new ClientConfiguration() .withRetryPolicy(retryPolicy); apiGatewayClient = new AmazonApiGatewayClient(getAWSCredentialsProvideChain(), clientConfig).withRegion(Region.getRegion(Regions.fromName(deployment.getRegion()))); return apiGatewayClient; }