Restarting app server using AWS API - java

I need to restart my AWS app server, for this I tried to use AWS API and have done the following:
1) Used the aws java sdk maven repository
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-elasticbeanstalk</artifactId>
<version>1.11.86</version>
</dependency>
2) Used the below code segment:
AWSElasticBeanstalk client = new AWSElasticBeanstalkClient();
RestartAppServerRequest request = new RestartAppServerRequest()
.withEnvironmentId("<myEnvId>")
.withEnvironmentName("<myEnvName>");
RestartAppServerResult response = client.restartAppServer(request);
I get the below error:
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)
The <myEnvId> and <myEnvName> are correct as they are taken from the AWS dashboard.
I also tried including the aws.accessKeyId and aws.secretKey to java system properties. Still I get the same error.
Is there something I am missing or doing wrong? Please advice.
Thanks,
Clyde

It sounds like you need to configure the region. For example to configure the region to us-west-2 you would use the following code:
AWSElasticBeanstalk client = new AWSElasticBeanstalkClient();
client.configureRegion(Regions.US_WEST_2);

Thanks to all who posted. I manged to solve the issue. The code segment used is as follows:
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);
This worked find.

Related

watson speech to text unauthorized request error401

I tried to use the code from IBM Watson GitHub repository I had to change a little bit for some errors I got when pasting it. I tried then to run the code to see it transcript from an audio file to text. But I got error 401 unauthorized. I tried to see solutions but didn't find one. Her is my code,
SpeechToText service = new SpeechToText();
IamOptions options1 = new IamOptions.Builder()
.apiKey("{apikey}")
.build();
service.setIamCredentials(options1);
File audio = new File("C:\\Users\\usern\\Downloads\\audio-file.FLAC");
RecognizeOptions options = new RecognizeOptions.Builder()
.audio(audio)
.contentType(HttpMediaType.AUDIO_FLAC)
.build();
SpeechRecognitionResults transcript = service.recognize(options).execute().getResult();
System.out.println(transcript);
So the answer was for me to solve this was to add service.setEndPoint("https://gateway-lon.watsonplatform.net/speech-to-text/api");
as the second line. URL for me was found looking at the Credentials at the IBM cloud service website, not that the URL might be different compared to mine where mine is located at London.

AWS Polly Java Client gives error: Unable to load region information from any provider in the chain

I am using the JAVA SDK from AWS to create a Polly client.
Like this:
BasicAWSCredentials awsCreds = new BasicAWSCredentials("<IAM access Key>", "IAM secret key>");
AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.build();
SynthesizeSpeechRequest tssRequest = new SynthesizeSpeechRequest();
tssRequest.setText(<text>);
tssRequest.setVoiceId(<voiceid>);
tssRequest.setOutputFormat(OutputFormat.Mp3);
SynthesizeSpeechResult tssResult = apClient.synthesizeSpeech(tssRequest);
When I run this code, I get the following error message:
Exception in thread "main" com.amazonaws.SdkClientException: Unable to
load region information from any provider in the chain at
com.amazonaws.regions.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:56)
at
com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:319)
at
com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:295)
at
com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:38)
at com.eoffice.aws.speech.Polly.main(Polly.java:42)
I checked the credentials using the IAM Policy Simulator. This works fine, permissions are OK.
The method to set the Region in the ClientBuilder is NOT visible for the AmazonPollyClientBuilder, so I have no (Java SDK) way to specify the region.
Update:
When I just ask the defaultAwsREgionProviderChain, I get the same error message
DefaultAwsRegionProviderChain defaultAwsRegionProviderChain = new DefaultAwsRegionProviderChain();
System.out.println(defaultAwsRegionProviderChain.getRegion());
Updat 2:
When I create a config file in de .aws folder with the following content:
[default]
region = eu-west-1
It works, but I need a way to set this without relying on the file system.
Providing a System Environment variable with name "AWS_REGION" did the trick.
See screenshot for configuration in IBM Bluemix
I think you can set Region like this
AmazonPollyClient apClient = (AmazonPollyClient) AmazonPollyClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion("<aws-region>").build();

WS.url fails when proxy options are set in Play Framework 2.2.x

I am using WS to make a REST call to a server behind a proxy that required.
I tried to set proxyserver and port in application.conf and as JVM arg when I launch the application. But I keep getting "Error Code: 407 Proxy Authentication Required".
I tried to set ws.useProxyProperties at false and true, but it still doesn't work. I saw that it is a common problem, but no workaround has been published.
Do you have any idea?
Thanks
I managed to resolve this issue by using the dependancy
"com.ning" % "async-http-client" % "1.8.14"
And changing my code to
AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setProxyServer(new
ProxyServer(host, port, user, pwd)).build();
c = new AsyncHttpClient(cf);
AsyncHttpClient.BoundRequestBuilder req = c.prepareGet("http://api.example.com/");
// and many other parameters ...

How to get tags from RDS DBInstance

I have a problem when I try to get Tags from RDS DBInstances on java.
AmazonRDS rds = new AmazonRDSClient(credentialsProvider);
ListTagsForResourceRequest request = new ListTagsForResourceRequest();
ListTagsForResourceResult resultedTags = rds.listTagsForResource(request);
Status Code: 500, AWS Service: AmazonRDS, AWS Request ID: ..., AWS Error Code: InternalFailure, AWS Error Message: An internal error has occurred. Please try your query again at a later time.
Stack Trace:
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:614)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:312)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:165)
at com.amazonaws.services.rds.AmazonRDSClient.invoke(AmazonRDSClient.java:1992)
at com.amazonaws.services.rds.AmazonRDSClient.listTagsForResource(AmazonRDSClient.java:746)
at com.vqs.AwsConsoleApp.getRDSInstances(AwsConsoleApp.java:98)
at com.vqs.AwsConsoleApp.main(AwsConsoleApp.java:73)
thank you in advance
From the Amazon RDS API reference, it looks like the ResourceName parameter on the request is required:
http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_ListTagsForResource.html
Try setting that request parameter with one of your RDS DB instance IDs and you should get a good response back.
I'm not sure why you didn't get a more helpful error message back from the service. I'll pass that info along to the RDS team.
Hope that helps!

How to upload file from GAE to Amazon S3 using URLFetchService?

I am trying to upload files to Amazon S3 from Google App Engine (in Java) using the URLFetchService, but I am not getting very far. For a start I have never done any REST programming before, nor GAE.
I have looked through the documentation for S3, and have come up with the following code. Am I going along the right path?
final URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
final URL url = new URL("http", AWS_BUCKET+".s3.amazonaws.com/myFile.jpg", "");
final HTTPRequest request = new HTTPRequest(url, HTTPMethod.PUT, followRedirects());
request.addHeader(new HTTPHeader("Content-Type", contentType));
request.addHeader(new HTTPHeader("Content-Length", Integer.toString(pictureBytes.length)));
request.addHeader(new HTTPHeader("Expect", "100-continue"));
request.addHeader(new HTTPHeader("Authorization", "AWS "+AWS_ACCESS_KEY+":"+AWS_SECRET_KEY));
request.setPayload(pictureBytes);
urlFetchService.fetch(request);
When I run the above code, I get Entity enclosing requests cannot be redirected without user intervention as an error message.
Thanks in advance for any hints/tips/pointers/URLs/solutions :)
Cheers
Rich
Ok, after all that, the sample code from Amazon themselves works just fine!
I wasn't expecting the Amazon code to work because of the sandbox that GAE/J runs in, but I should've tested it first.

Categories