fix(sns) Allow to publish SMS using phone-number (#138)

Co-authored-by: tada <tada20591@cs.saisoncard.co.jp>
This commit is contained in:
Masatoshi Tadaandtada authored and GitHub committed 2026-03-31 16:00:46 -05:00
1 parent 35e129d024
commit 788cf01d2c
4 files changed
+21 -6

No files matched your search

@@ -150,6 +150,7 @@ public class SnsJsonHandler {
private Response handlePublish(JsonNode request, String region) {
String topicArn = request.path("TopicArn").asText(null);
String targetArn = request.path("TargetArn").asText(null);
String phoneNumber = request.path("PhoneNumber").asText(null);
String message = request.path("Message").asText(null);
String subject = request.path("Subject").asText(null);
@@ -161,7 +162,7 @@ public class SnsJsonHandler {
});
}
String messageId = snsService.publish(topicArn, targetArn, message, subject, attributes, region);
String messageId = snsService.publish(topicArn, targetArn, phoneNumber, message, subject, attributes, region);
ObjectNode response = objectMapper.createObjectNode();
response.put("MessageId", messageId);
return Response.ok(response).build();
@@ -175,6 +175,7 @@ public class SnsQueryHandler {
private Response handlePublish(MultivaluedMap<String, String> params, String region) {
String topicArn = getParam(params, "TopicArn");
String targetArn = getParam(params, "TargetArn");
String phoneNumber = getParam(params, "PhoneNumber");
String message = getParam(params, "Message");
String subject = getParam(params, "Subject");
String messageGroupId = getParam(params, "MessageGroupId");
@@ -189,7 +190,7 @@ public class SnsQueryHandler {
}
try {
String messageId = snsService.publish(topicArn, targetArn, message, subject,
String messageId = snsService.publish(topicArn, targetArn, phoneNumber, message, subject,
attributes, messageGroupId, messageDeduplicationId, region);
String result = new XmlBuilder().elem("MessageId", messageId).build();
@@ -238,19 +238,26 @@ public class SnsService {
return subscriptionsByTopic(topicArn, region);
}
// Since this method is called by S3 and EventBridge, this doesn't need "phoneNumber" parameter.
public String publish(String topicArn, String targetArn, String message,
String subject, String region) {
return publish(topicArn, targetArn, message, subject, null, null, null, region);
return publish(topicArn, targetArn, null, message, subject, null, null, null, region);
}
public String publish(String topicArn, String targetArn, String message,
public String publish(String topicArn, String targetArn, String phoneNumber, String message,
String subject, Map<String, String> messageAttributes, String region) {
return publish(topicArn, targetArn, message, subject, messageAttributes, null, null, region);
return publish(topicArn, targetArn, phoneNumber, message, subject, messageAttributes, null, null, region);
}
public String publish(String topicArn, String targetArn, String message,
public String publish(String topicArn, String targetArn, String phoneNumber, String message,
String subject, Map<String, String> messageAttributes,
String messageGroupId, String messageDeduplicationId, String region) {
// Send SMS
if (phoneNumber != null) {
return UUID.randomUUID().toString();
}
// Send a message to topic or directly to a target ARN
String effectiveArn = topicArn != null ? topicArn : targetArn;
if (effectiveArn == null) {
throw new AwsException("InvalidParameter", "TopicArn or TargetArn is required.", 400);