невозможно отправить голосовое сообщение с указанием AWS - PullRequest
1 голос
/ 29 января 2020

пытается заставить этот учебник работать https://docs.aws.amazon.com/pinpoint/latest/developerguide/send-messages-voice.html.

  • текущая проблема блокировки: я сталкиваюсь с этим исключением:
Caused by: java.net.UnknownHostException: sms-voice.pinpoint.us-east-1.amazonaws.com: No address associated with hostname
  • другое дело: что такое комплектация? нужен ли мне один?

Пока что все, что я сделал:

  • создание проекта на месте
  • запрос длинного кода
  • запросить производственный доступ (ранее выдавал ошибку, сообщая, что я ее требовал)

любая идея?

log:

18:53:58.342 [main] DEBUG com.amazonaws.AmazonWebServiceClient - Internal logging successfully configured to commons logger: true
18:53:58.705 [main] DEBUG com.amazonaws.monitoring.CsmConfigurationProviderChain - Unable to load configuration from com.amazonaws.monitoring.EnvironmentVariableCsmConfigurationProvider@3ecdeca4: Unable to load Client Side Monitoring configurations from environment variables!
18:53:58.705 [main] DEBUG com.amazonaws.monitoring.CsmConfigurationProviderChain - Unable to load configuration from com.amazonaws.monitoring.SystemPropertyCsmConfigurationProvider@63b96814: Unable to load Client Side Monitoring configurations from system properties variables!
18:53:58.709 [java-sdk-http-connection-reaper] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Closing connections idle longer than 60000 MILLISECONDS
18:53:58.712 [main] DEBUG com.amazonaws.monitoring.CsmConfigurationProviderChain - Unable to load configuration from com.amazonaws.monitoring.ProfileCsmConfigurationProvider@d141aa03: The 'default' profile does not define all the required properties!
18:53:58.732 [main] INFO com.amazonaws.internal.DefaultServiceEndpointBuilder - {sms-voice.pinpoint, eu-west-1} was not found in region metadata, trying to construct an endpoint using the standard pattern for this region: 'sms-voice.pinpoint.eu-west-1.amazonaws.com'.
18:53:58.809 [main] DEBUG com.amazonaws.metrics.AwsSdkMetrics - Admin mbean registered under com.amazonaws.management:type=AwsSdkMetrics
18:53:58.869 [main] DEBUG com.amazonaws.auth.AWSCredentialsProviderChain - Unable to load credentials from EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY))
18:53:58.869 [main] DEBUG com.amazonaws.auth.AWSCredentialsProviderChain - Unable to load credentials from SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey)
18:53:58.869 [main] DEBUG com.amazonaws.auth.AWSCredentialsProviderChain - Unable to load credentials from WebIdentityTokenCredentialsProvider: To use assume role profiles the aws-java-sdk-sts module must be on the class path.
18:53:58.871 [main] DEBUG com.amazonaws.auth.AWSCredentialsProviderChain - Loading credentials from com.amazonaws.auth.profile.ProfileCredentialsProvider@24e02a53
18:53:58.877 [main] DEBUG com.amazonaws.request - Sending Request: POST https://sms-voice.pinpoint.eu-west-1.amazonaws.com /v1/sms-voice/voice/message Headers: (amz-sdk-invocation-id: XXX, Content-Length: 394, Content-Type: , User-Agent: aws-sdk-java/1.11.714 Linux/5.3.0-26-generic Eclipse_OpenJ9_VM/openj9-0.15.1 java/1.8.0_222 groovy/2.4.1 vendor/Eclipse_OpenJ9, )
18:53:58.956 [main] DEBUG com.amazonaws.auth.AWS4Signer - AWS4 Canonical Request: '"POST
/v1/sms-voice/voice/message

amz-sdk-invocation-id:XXXXX
amz-sdk-retry:0/0/500
content-length:394
content-type:
host:sms-voice.pinpoint.eu-west-1.amazonaws.com
user-agent:aws-sdk-java/1.11.714 Linux/5.3.0-26-generic Eclipse_OpenJ9_VM/openj9-0.15.1 java/1.8.0_222 groovy/2.4.1 vendor/Eclipse_OpenJ9
x-amz-date:XXXX

amz-sdk-invocation-id;amz-sdk-retry;content-length;content-type;host;user-agent;x-amz-date
XXXX"
18:53:58.957 [main] DEBUG com.amazonaws.auth.AWS4Signer - AWS4 String to Sign: '"XXXX
20200127T185358Z
20200127/eu-west-1/sms-voice/aws4_request
XXXX"
18:53:58.967 [main] DEBUG com.amazonaws.auth.AWS4Signer - Generating a new signing key as the signing key not available in the cache for the date 1580083200000
18:53:59.002 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
18:53:59.010 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
18:53:59.012 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://sms-voice.pinpoint.eu-west-1.amazonaws.com:443][total kept alive: 0; route allocated: 0 of 50; total allocated: 0 of 50]
18:53:59.026 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://sms-voice.pinpoint.eu-west-1.amazonaws.com:443][total kept alive: 0; route allocated: 1 of 50; total allocated: 1 of 50]
18:53:59.028 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {s}->https://sms-voice.pinpoint.eu-west-1.amazonaws.com:443
18:53:59.053 [main] DEBUG com.amazonaws.http.conn.ClientConnectionManagerFactory -
java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76)
at com.amazonaws.http.conn.$Proxy8.connect(Unknown Source)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1311)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1127)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:784)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:752)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
at com.amazonaws.services.pinpointsmsvoice.AmazonPinpointSMSVoiceClient.doInvoke(AmazonPinpointSMSVoiceClient.java:713)
at com.amazonaws.services.pinpointsmsvoice.AmazonPinpointSMSVoiceClient.invoke(AmazonPinpointSMSVoiceClient.java:680)
at com.amazonaws.services.pinpointsmsvoice.AmazonPinpointSMSVoiceClient.invoke(AmazonPinpointSMSVoiceClient.java:669)
at com.amazonaws.services.pinpointsmsvoice.AmazonPinpointSMSVoiceClient.executeSendVoiceMessage(AmazonPinpointSMSVoiceClient.java:569)
at com.amazonaws.services.pinpointsmsvoice.AmazonPinpointSMSVoiceClient.sendVoiceMessage(AmazonPinpointSMSVoiceClient.java:540)
at com.helloworld.AlertVoiceMessageService.main(AlertVoiceMessageService.java:79)
Caused by: java.net.UnknownHostException: sms-voice.pinpoint.eu-west-1.amazonaws.com: No address associated with hostname
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getAllByName0(InetAddress.java:1277)
at java.net.InetAddress.getAllByName(InetAddress.java:1193)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
at com.amazonaws.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:27)
at com.amazonaws.http.DelegatingDnsResolver.resolve(DelegatingDnsResolver.java:38)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:112)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
... 28 common frames omitted
18:53:59.053 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
18:53:59.053 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
18:53:59.053 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://sms-voice.pinpoint.eu-west-1.amazonaws.com:443][total kept alive: 0; route allocated: 0 of 50; total allocated: 0 of 50]

использовал следующий код:

package com.helloworld;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;

import com.amazonaws.services.pinpointsmsvoice.AmazonPinpointSMSVoice;
import com.amazonaws.services.pinpointsmsvoice.AmazonPinpointSMSVoiceClientBuilder;
import com.amazonaws.services.pinpointsmsvoice.model.SSMLMessageType;
import com.amazonaws.services.pinpointsmsvoice.model.SendVoiceMessageRequest;
import com.amazonaws.services.pinpointsmsvoice.model.VoiceMessageContent;
public class AlertVoiceMessageService {

// The AWS Region that you want to use to send the voice message. For a list of
// AWS Regions where the Amazon Pinpoint SMS and Voice API is available, see
// https://docs.aws.amazon.com/pinpoint-sms-voice/latest/APIReference/
static final String region = "eu-west-1";

// The phone number that the message is sent from. The phone number that you
// specify has to be associated with your Amazon Pinpoint account. For best
// results, you should specify the phone number in E.164 format.
static final String originationNumber = "+XXX";

// The recipient's phone number.  For best results, you should specify the
// phone number in E.164 format.
static final String destinationNumber = "+XXX";

// The Amazon Polly voice that you want to use to send the message. For a list
// of voices, see https://docs.aws.amazon.com/polly/latest/dg/voicelist.html
static final String voiceName = "Brian";

// The language to use when sending the message. For a list of supported
// languages, see https://docs.aws.amazon.com/polly/latest/dg/SupportedLanguage.html
static final String languageCode = "en-GB-WLS";

// The content of the message. This example uses SSML to customize and control
// certain aspects of the message, such as by adding pauses and changing
// phonation. The message can't contain any line breaks.
static final String ssmlMessage = "<speak>This is an alert message sent from "
        + "<emphasis>XXX</emphasis>."
        + "<amazon:effect phonation='soft'>Thank "
        + "you for listening.</amazon:effect></speak>";

// The phone number that you want to appear on the recipient's device. The
// phone number that you specify has to be associated with your Amazon Pinpoint
// account.
static final String callerId = "+XXXX";

// The configuration set that you want to use to send the message.
static final String configurationSet = "ConfigSet";

public static void main(String[] args) throws IOException {
    try {
        AmazonPinpointSMSVoice client = AmazonPinpointSMSVoiceClientBuilder.standard()
                .withRegion(region).build();
        SendVoiceMessageRequest request = new SendVoiceMessageRequest()
                .withCallerId(callerId)
                .withDestinationPhoneNumber(destinationNumber)
                .withOriginationPhoneNumber(originationNumber)
// .withConfigurationSetName(configurationSet)
.withContent(new VoiceMessageContent()
.withSSMLMessage(new SSMLMessageType()
.withLanguageCode(languageCode)
.withVoiceId(voiceName)
.withText(ssmlMessage)
)
);
client.sendVoiceMessage(request);
System.out.println("The message was sent successfully.");
} catch (Exception ex) {
System.out.println("The message wasn't sent. Error message: " + ex.getMessage());
}
}

}

использовал следующие зависимости в пом. xml

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.714</version>
<type>pom</type>
<scope>import</scope>
</dependency>

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-pinpointsmsvoice</artifactId>
        <version>1.11.714</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.9</version>
    </dependency>

Спасибо!

1 Ответ

1 голос
/ 30 января 2020

Я изучил ваш Java фрагмент кода и могу в меру своих сил подтвердить, что с вашим кодом все в порядке.

Я подтвердил следующее:

  • Я протестировал пример кода Java кода на размещенной вами ссылке на документы, и он запустился без проблем.

Предложение:

  1. Я подтвердил, что и us-east-1, и eu-west-1 поддерживают Pinpoint SMS & Voice. Однако, поскольку в вашем коде вы используете регион «eu-west-1», убедитесь, что регион, указанный в переменных среды или в файле .aws / credentails, также соответствует «eu-west-1», а не «us-east-1». "

  2. Из-за ошибки, поскольку вы используете Java. net, я подозреваю, что ваша корпоративная сеть, вероятно, использует прокси. В этом случае вам необходимо настроить параметры прокси-сервера (прокси-хост, порт и имя пользователя / пароль) через объект ClientConfiguration .

...