SMS メッセージプリファレンスを設定する - Amazon Simple Notification Service

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

SMS メッセージプリファレンスを設定する

Amazon SNS を使用して、SMS メッセージングのプリファレンスを指定します。例えば、配信をコストまたは信頼性に対して最適化するかや、毎月の使用量の上限、配信がログに記録される方法、SMS の毎日の使用状況レポートをサブスクライブするかどうか、などを指定できます。

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

を使用して 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 SNS は SMS メッセージの発行を停止します。

      • Amazon SNS は分散システムであるため、使用クォータを超えると数分以内に SMS メッセージの送信を停止します。その間に SMS メッセージを送信し続けると、クォータを超えるコストが発生する可能性があります。

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

    注記

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

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

    注記

    S3 バケットポリシーによって Amazon SNS への書き込みアクセスが付与される必要があります。

  8. [変更を保存]をクリックします。

プリファレンスの設定 (AWS SDK)

いずれかの AWS SDK を使用して 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
JavaScript (v3) 用 SDK
注記

まだまだあります。 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; };
  • 詳細については、AWS SDK for JavaScript デベロッパーガイドを参照してください。

  • API の詳細については、AWS SDK for JavaScript API リファレンスの「SetSMSAttributes」を参照してください。

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