Amazon でのSMSメッセージング設定の設定 SNS - Amazon Simple Notification Service

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon でのSMSメッセージング設定の設定 SNS

Amazon SNSを使用してSMSメッセージングの設定を指定します。例えば、コストや信頼性のために配信を最適化するかどうか、月別使用制限、配信のログ記録方法、日次SMS使用状況レポートをサブスクライブするかどうかを指定できます。

これらの設定は、アカウントから送信するすべてのSMSメッセージに対して有効になりますが、個々のメッセージを送信するときに一部の設定を上書きできます。詳細については、「Amazon を使用して携帯電話にSMSメッセージを発行する SNS」を参照してください。

を使用したSMSメッセージング設定の設定 AWS Management Console

  1. Amazon SNSコンソール にサインインします。

  2. SMS メッセージング をサポートするリージョンを選択します。

  3. ナビゲーションパネルで、モバイル、テキストメッセージ (SMS) を選択します。

  4. モバイルテキストメッセージング (SMS) ページの「テキストメッセージの設定」セクションで、「編集」を選択します。

  5. [テキストメッセージングの優先設定の編集] ページの [詳細] セクションで、以下の操作を実行します。

    1. [デフォルトメッセージタイプ] で、次のいずれかを選択します。

      • [プロモーション] — 重要度が低いメッセージ (広告など)。Amazon は、メッセージ配信SNSを最適化して、コストを最小限に抑えます。

      • [トランザクション] - 多要素認証のワンタイムパスコードなど、お客様のトランザクションをサポートするクリティカルメッセージ。Amazon はメッセージ配信SNSを最適化して、最高の信頼性を実現します。

      プロモーションメッセージとトランザクションメッセージの料金情報については、「グローバルSMS料金」を参照してください。

    2. (オプション) アカウントの使用制限 に、毎月SMSのメッセージに費やす金額 ( でUSD) を入力します。

      重要
      • デフォルトでは、支出クォータは 1.00 に設定されていますUSD。サービス限度を引き上げるには、リクエストを送信します。

      • コンソールで設定された量がサービスクォータを超えると、Amazon はSMSメッセージの発行をSNS停止します。

      • Amazon SNSは分散システムであるため、支出クォータを超過してから数分以内にSMSメッセージの送信を停止します。この間隔でSMSメッセージを引き続き送信すると、クォータを超えるコストが発生する可能性があります。

  6. (オプション) [デフォルトの送信者 ID] にカスタム ID (ビジネスブランドなど) を入力します。これは、受信デバイスに送信者として表示されます。

    注記

    送信者のサポートIDsは国によって異なります。

  7. (オプション) 使用状況レポート用の Amazon S3 バケット名の名前を入力します。

    注記

    S3 バケットポリシーは、Amazon への書き込みアクセスを許可する必要がありますSNS。

  8. [Save changes] (変更の保存) をクリックします。

を使用した設定 AWS SDKs

のいずれかを使用してSMS設定を行うには AWS SDKs、Amazon の SetSMSAttributesリクエストSDKに対応する SNS アクションを使用しますAPI。このリクエストでは、毎月の支出クォータやデフォルトのSMSタイプ (プロモーションまたはトランザクション) など、さまざまなSMS属性に値を割り当てます。すべてのSMS属性については、「Amazon Simple Notification Service APIリファレンス」の「SetSMSAttributes」を参照してください。

以下のコード例は、SetSMSAttributes の使用方法を示しています。

C++
SDK C++ 用
注記

については、「」を参照してください GitHub。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

Amazon を使用して D efaultSMSType 属性SNSを設定する方法。

//! 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 詳細については、「 リファレンス」の「SetSMSAttributes」を参照してください。 AWS SDK for C++ API

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 詳細については、「 リファレンス」の「SetSMSAttributes」を参照してください。 AWS SDK for Java 2.x API

JavaScript
SDK の 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
PHP に関する SDK
注記

については、「」を参照してください 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 の Protect 設定を使用して、許可またはブロックする国を指定します。

  1. で AWS SMS コンソールを開きますhttps://console.aws.amazon.com/sms-voice/

  2. ナビゲーションペインの概要 クイックスタートセクションで、保護設定の作成 を選択します。

  3. 「Protect 設定の詳細」に、保護設定のビジネスフレンドリ名を入力します (Allow-Only-AU など)。

  4. SMS 国ルール で、リージョン/国チェックボックスをオンにして、サポートされているすべての国へのメッセージの送信をブロックします。

  5. メッセージを送信する国のチェックボックスをオフにします。例えば、オーストラリアへのメッセージのみを許可するには、オーストラリア のチェックボックスをオフにします。

  6. 「設定の関連付けの保護」セクションの「関連付けタイプ」で、「アカウントのデフォルト」を選択します。これにより、 AWS End User Messaging SMS Protect 設定が Amazon 、Amazon Amazon Cognito SNS、および Amazon Pinpoint SendMessagesAPI呼び出しを介して送信されるすべてのメッセージに影響を与えるようになります。

  7. 保護設定の作成を選択して設定を保存します。

    次の確認メッセージが表示されます。

    Success Protect configuration protect-abc0123456789 has been created.
  8. Amazon SNSコンソール にサインインします。

  9. India など、ブロックされている国の 1 つにメッセージを発行します。

    メッセージは配信されません。これは、 を使用して配信失敗ログで確認できます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" }