问题
I tried sending SMS from AWS SNS API through JAVA which worked for two days then suddenly stopped delivering messages but the response from API is 200 ok with a proper message ID without delivering messages. I am trying to post the request through postman to get more clarity of the issue but cannot find any collection or request signature.
`
public class SNS {
public static void sendSMS(String phoneNumber,String message)
{
BasicAWSCredentials basicCred = new BasicAWSCredentials("XXXXXXXXXXX", "XXXXXXXXXXXXX");
AmazonSNSClient snsClient = (AmazonSNSClient) AmazonSNSClientBuilder.standard()
.withClientConfiguration(
new ClientConfiguration()
.withMaxErrorRetry(0)
.withConnectionTimeout(1000))
.withCredentials(new AWSStaticCredentialsProvider(basicCred))
.withRegion("us-east-1")
.build();
Map<String, MessageAttributeValue> smsAttributes =
new HashMap<String, MessageAttributeValue>();
smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
.withStringValue("Sender") //The sender ID shown on the device.
.withDataType("String"));
smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
.withStringValue("Transactional") //Sets the type to Transactional.
.withDataType("String"));
sendSMSMessage(snsClient, message, phoneNumber, smsAttributes);
}
public static void sendSMSMessage(AmazonSNSClient snsClient, String message,
String phoneNumber, Map<String, MessageAttributeValue> smsAttributes)
{
PublishResult result = snsClient.publish(new PublishRequest()
.withMessage(message)
.withPhoneNumber(phoneNumber)
.withMessageAttributes(smsAttributes));
}
public static void main(String[] args) {
sendSMS("+91XXXXXXXXXX", "Hi This is Test message from SNS");
}
}`
I am using the above code which is giving 200 O in response along with request and message Id but the message is not delivered.
回答1:
You can refer these examples from AWS to form the request.
Alternative, you can enable verbose logging in your java code to see request. refer this or this document from AWS to enable verbose logging.
or
execute aws cli to send sms from aws sns with --debug true
option, which will also print the request on command line.
来源:https://stackoverflow.com/questions/65732170/aws-sns-stopped-delivering-messages