java - 无法在 AWS pinpoint 上发送语音消息

标签 java amazon-web-services aws-pinpoint

尝试让本教程发挥作用 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
  • 另一件事:configurationSet 是什么?我需要一个吗?

到目前为止我所做的事情:

  • 在 pinpoint 上创建项目
  • 请求长代码
  • 请求生产访问权限(之前抛出错误告诉我需要它)

有什么想法吗?

日志:

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());
}
}

}

在 pom.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>

谢谢!

最佳答案

我已经检查了您的 Java 代码片段,并且我可以尽我所能确认您的代码没有任何问题。

我已确认以下内容:

  • 我已经在您发布的文档链接上测试了示例 Java 代码示例,并且运行没有问题。

建议:

  1. 我已确认 us-east-1 和 eu-west-1 均支持 Pinpoint 短信和语音。但是,由于您在代码中使用“eu-west-1”区域,因此请确保环境变量或 .aws/credentails 文件中指定的区域也匹配“eu-west-1”而不是“us-east-1” “

  2. 根据错误,由于您使用的是 Java.net,我怀疑您的公司网络可能正在使用代理。如果是这种情况,您需要通过 ClientConfiguration 配置代理服务器设置(代理主机、端口和用户名/密码)。对象。

关于java - 无法在 AWS pinpoint 上发送语音消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59972330/

相关文章:

amazon-web-services - AWS EC2 Auto Scaling 组 : I get Min and Max, 但所需实例限制是什么?

html - 静态网站 AWS S3 上的多个页面

key - 通过 Cloudformation 支持 AWS Pinpoint APNS channel

aws-pinpoint - 如何使用 Pinpoint 创建深度链接推送通知?

java - 我将 getHostAddress() 与 try-catch 一起使用,但是当我运行它时,它只是不运行 这有什么问题吗?

java - 给定由 LinkedList 组成的 java hashmap 中的键,如何更新值?

java - 递归函数JAVA中的返回值

java - 如何在 JDialog 打开时暂停执行

node.js - 如何使用 AWS Elastic Beanstalk 部署 Node/Express 服务器

java - AWS Pinpoint 端点 ID 查找