Amazon Polly API

I am trying to use the Amazon Polly REST API.
Can someone please help me to do this?
I am using Java and OkHttp3 and tried this:

    String url = "https://polly.us-west-2.amazonaws.com/v1/speech";
    String postBody = "{\"OutputFormat\":\"mp3\",\"Text\":\"Some text to listen\",\"TextType\":\"text\",\"VoiceId\":\"Joanna\"}";

    MediaType mediaType = MediaType.parse("application/json; charset=utf-8");

    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(30, TimeUnit.SECONDS)
            .readTimeout(30, TimeUnit.SECONDS)
            .build();



    Request request = new Request.Builder()
            .url(url)
            .addHeader("Authorization", "AWS <accessKey>:<secretKey>")
            .post(RequestBody.create(mediaType, postBody))
            .build();

    Response response = client.newCall(request).execute();

      

And I got a "403 forbidden" answer. Then I tried to make this POST request online on this service and got this: enter image description here What am I doing wrong? What should I fix? Thank!

Amazon docs: link
And please don't suggest that I use the SDK!


I have read this , this , this , this and this and do not understand anything.

  • I understand that my secret is secret and that I need to use encryption.
  • I need to run a query, as described here , but I can not figure out how to make your own request ... My options: method=POST

    , host=polly.us-west-2.amazonaws.com

    , endpoint=https://polly.us-west-2.amazonaws.com/v1/speech

    , region=us-west-2

    , content-type=application/json

    , body of post request={...}

    , accessKey=...

    , secretKey=...

    ..... And how to make this request using OkHttp? Please, help!
+3


source to share


1 answer


addHeader("Authorization", "AWS <accessKey>:<secretKey>")

never runs on AWS. Your private key is private.

Requests are authenticated by signing them using a series of HMAC-SHA iterations based on your private key.

There are good reasons for not using the SDK, but you will need to read and understand the documentation to generate signatures.



When you use the AWS Command Line Interface (AWS CLI) or one of the AWS SDKs for AWS Requests, these tools automatically sign the requests for you using the access token that you provide when configuring the tools. When you use these tools, you don't need to learn how to sign requests yourself. However, when you manually create HTTP requests for AWS, you must sign the requests yourself.

http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html

The signing process is explained in detail starting with the link above.

Signature Version 4 is supported by all services in all regions.

+1


source







All Articles