Amazon SNS에서 SMS 메시징 기본 설정 지정 - Amazon Simple Notification Service

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon SNS에서 SMS 메시징 기본 설정 지정

Amazon SNS를 사용하여 SMS 메시징에 대한 기본 설정을 지정합니다. 예를 들어 비용 또는 안정성을 위해 전송을 최적화할지 여부, 월별 지출 한도, 전송을 로그하는 방법 및 일일 SMS 사용 보고서를 구독할지 여부를 지정할 수 있습니다.

이러한 기본 설정은 계정에서 보내는 모든 SMS 메시지에 적용되지만, 개별 메시지를 전송할 때 일부 설정을 무시할 수 있습니다. 자세한 내용은 Amazon SNS를 사용하여 휴대전화에 SMS 메시지 게시 단원을 참조하십시오.

AWS Management Console을 사용하여 SMS 메시지 기본 설정 지정

  1. Amazon SNS 콘솔에 로그인합니다.

  2. SMS 메시징을 지원하는 리전을 선택합니다.

  3. 탐색 창에서 모바일, 문자 메시지(SMS)를 차례로 선택합니다.

  4. 모바일 문자 메시지(SMS) 페이지의 문자 메시지 기본 설정 섹션에서 편집을 선택합니다.

  5. Edit text messaging preferences(문자 메시지 기본 설정 편집) 페이지의 세부 정보 섹션에서 다음을 수행합니다.

    1. 기본 메시지 유형에서 다음 중 하나를 선택합니다.

      • 프로모션 – 중요하지 않은 메시지(예: 마케팅)입니다. Amazon SNS는 최소 비용이 발생하도록 메시지 전송을 최적화합니다.

      • 트랜잭션(기본값) – 고객 트랜잭션을 지원하는 중요한 메시지입니다(예: 멀티 팩터 인증을 위한 일회용 암호). Amazon SNS는 최고의 안정성을 달성하도록 메시지 전송을 최적화합니다.

      프로모션 및 트랜잭션 메시지에 대한 요금 정보는 글로벌 SMS 요금에서 확인하세요.

    2. (선택 사항) 계정 지출 한도에 매월 SMS 메시지에 지출하려는 최대 금액(USD)을 입력합니다.

      중요
      • 기본적으로 지출 할당량은 1.00USD로 설정됩니다. 서비스 할당량을 늘리려면 요청을 제출하세요.

      • 콘솔에서 설정된 금액이 서비스 할당량을 초과할 경우 Amazon SNS에서 SMS 메시지 게시를 중지합니다.

      • Amazon SNS는 분산 시스템이므로 초과되는 지출 할당량(분) 이내에 SMS 메시지 전송을 중지합니다. 이 기간 사이에 SMS 메시지 전송을 계속하는 경우 할당량 초과 비용이 발생할 수 있습니다.

  6. (선택 사항) 기본 발신자 ID에 기업 브랜드와 같은 사용자 지정 ID를 입력합니다. 이 ID는 수신하는 디바이스의 발신자로 표시됩니다.

    참고

    발신자 ID에 대한 지원은 국가별로 다릅니다.

  7. (선택 사항) Amazon S3 bucket name for usage reports(사용 보고서용 Amazon S3 버킷 이름)의 이름을 입력합니다.

    참고

    Amazon S3 버킷 정책은 Amazon SNS에 대한 쓰기 액세스 권한을 부여해야 합니다.

  8. Save changes(변경 사항 저장)를 선택합니다.

기본 설정(AWS SDKs)

AWS SDKs 중 하나를 사용하여 SMS 기본 설정을 지정하려면 Amazon SNS API의 SetSMSAttributes 요청에 해당하는 SDK의 작업을 사용합니다. 이 요청을 통해 월 지출 할당량 및 기본 SMS 유형(프로모션 또는 트랜잭션) 등의 다양한 SMS 속성에 값을 할당합니다. 모든 SMS 속성은 Amazon Simple Notification Service API 참조SetSMSAttributes를 참조하세요.

다음 코드 예제는 SetSMSAttributes의 사용 방법을 보여 줍니다.

C++
SDK for C++
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

Amazon SNS를 사용하여 DefaultSMSType 속성을 설정하는 방법입니다.

//! Set the default settings for sending SMS messages. /*! \param smsType: The type of SMS message that you will send by default. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SNS::setSMSType(const Aws::String &smsType, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SNS::SNSClient snsClient(clientConfiguration); Aws::SNS::Model::SetSMSAttributesRequest request; request.AddAttributes("DefaultSMSType", smsType); const Aws::SNS::Model::SetSMSAttributesOutcome outcome = snsClient.SetSMSAttributes( request); if (outcome.IsSuccess()) { std::cout << "SMS Type set successfully " << std::endl; } else { std::cerr << "Error while setting SMS Type: '" << outcome.GetError().GetMessage() << "'" << std::endl; } return outcome.IsSuccess(); }
  • API 세부 정보는 AWS SDK for C++ API 참조SetSMSAttributes를 참조하세요.

CLI
AWS CLI

SMS 메시지 속성을 설정하려면

다음 set-sms-attributes예제에서는 SMS 메시지의 기본 발신자 ID를 MyName으로 설정합니다.

aws sns set-sms-attributes \ --attributes DefaultSenderID=MyName

이 명령은 출력을 생성하지 않습니다.

  • API 세부 정보는 AWS CLI 명령 참조SetSMSAttributes를 참조하세요.

Java
SDK for Java 2.x
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.sns.SnsClient; import software.amazon.awssdk.services.sns.model.SetSmsAttributesRequest; import software.amazon.awssdk.services.sns.model.SetSmsAttributesResponse; import software.amazon.awssdk.services.sns.model.SnsException; import java.util.HashMap; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class SetSMSAttributes { public static void main(String[] args) { HashMap<String, String> attributes = new HashMap<>(1); attributes.put("DefaultSMSType", "Transactional"); attributes.put("UsageReportS3Bucket", "janbucket"); SnsClient snsClient = SnsClient.builder() .region(Region.US_EAST_1) .build(); setSNSAttributes(snsClient, attributes); snsClient.close(); } public static void setSNSAttributes(SnsClient snsClient, HashMap<String, String> attributes) { try { SetSmsAttributesRequest request = SetSmsAttributesRequest.builder() .attributes(attributes) .build(); SetSmsAttributesResponse result = snsClient.setSMSAttributes(request); System.out.println("Set default Attributes to " + attributes + ". Status was " + result.sdkHttpResponse().statusCode()); } catch (SnsException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • API 세부 정보는 AWS SDK for Java 2.x API 참조SetSMSAttributes를 참조하세요.

JavaScript
SDK for JavaScript (v3)
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

별도의 모듈에서 클라이언트를 생성하고 내보냅니다.

import { SNSClient } from "@aws-sdk/client-sns"; // The AWS Region can be provided here using the `region` property. If you leave it blank // the SDK will default to the region set in your AWS config. export const snsClient = new SNSClient({});

SDK 및 클라이언트 모듈을 가져오고 API를 호출합니다.

import { SetSMSAttributesCommand } from "@aws-sdk/client-sns"; import { snsClient } from "../libs/snsClient.js"; /** * @param {"Transactional" | "Promotional"} defaultSmsType */ export const setSmsType = async (defaultSmsType = "Transactional") => { const response = await snsClient.send( new SetSMSAttributesCommand({ attributes: { // Promotional – (Default) Noncritical messages, such as marketing messages. // Transactional – Critical messages that support customer transactions, // such as one-time passcodes for multi-factor authentication. DefaultSMSType: defaultSmsType, }, }), ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '1885b977-2d7e-535e-8214-e44be727e265', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };
PHP
SDK for PHP
참고

GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

$SnSclient = new SnsClient([ 'profile' => 'default', 'region' => 'us-east-1', 'version' => '2010-03-31' ]); try { $result = $SnSclient->SetSMSAttributes([ 'attributes' => [ 'DefaultSMSType' => 'Transactional', ], ]); var_dump($result); } catch (AwsException $e) { // output error message if fails error_log($e->getMessage()); }

국가별 전송 시 SMS 메시징 기본 설정 지정

특정 대상 국가로만 메시지를 전송하여 SMS 트래픽을 관리하고 제어할 수 있습니다. 이렇게 하면 메시지가 승인된 국가로만 전송되므로 원치 않는 SMS 요금을 방지할 수 있습니다. 다음 설명에서는 Amazon Pinpoint의 보호 구성을 사용하여 허용하거나 차단하려는 국가를 지정합니다.

  1. https://console.aws.amazon.com/sms-voice/ AWS SMS 콘솔을 엽니다.

  2. 탐색 창의 개요에 있는 빠른 시작 섹션에서 보호 구성 생성을 선택합니다.

  3. 구성 세부 정보 보호에 보호 구성의 비즈니스에 적합한 이름(예: Allow-Only-AU)을 입력합니다.

  4. SMS 국가 규칙에서 리전/국가 확인란을 선택하여 모든 지원되는 국가로 메시지가 전송되는 것을 차단합니다.

  5. 메시지를 보내려는 국가의 확인란은 선택 취소합니다. 예를 들어 오스트레일리아에만 메시지를 허용하려면 오스트레일리아의 확인란을 선택 취소합니다.

  6. 보호 구성 연결 섹션의 연결 유형에서 계정 기본값을 선택합니다. 이렇게 하면 AWS 최종 사용자 메시징 SMS 보호 구성이 Amazon SNS, Amazon Cognito 및 Amazon Pinpoint SendMessages API 호출을 통해 전송되는 모든 메시지에 영향을 미칩니다.

  7. 보호 구성 생성을 선택하여 설정을 저장합니다.

    다음의 확인 메시지가 표시됩니다.

    Success Protect configuration protect-abc0123456789 has been created.
  8. Amazon SNS 콘솔에 로그인합니다.

  9. 인도 등의 차단된 국가 중 하나에 메시지를 게시합니다.

    메시지가 전송되지 않습니다. CloudWatch를 사용하여 전송 실패 로그에서 이를 확인할 수 있습니다. 로그 그룹(sns/region/AccountID/DirectPublishToPhoneNumber/Failure)에서 다음 예제와 유사한 응답을 검색합니다.

    { "notification": { "messageId": "bd59a509-XXXX-XXXX-82f8-fbdb8cb68217", "timestamp": "YYYY-MM-DD XX:XX:XX.XXXX“ }, "delivery": { "destination": "+91XXXXXXXXXX", "smsType": "Transactional", "providerResponse": "Cannot deliver message to the specified destination country", "dwellTimeMs": 85 }, "status": "FAILURE" }