翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
SMS メッセージプリファレンスを設定する
Amazon SNS を使用して、SMS メッセージングのプリファレンスを指定します。例えば、配信をコストまたは信頼性に対して最適化するかや、毎月の使用量の上限、配信がログに記録される方法、SMS の毎日の使用状況レポートをサブスクライブするかどうか、などを指定できます。
これらの設定は、アカウントから送信するすべての SMS メッセージに対して有効になりますが、個々のメッセージの送信時に上書きすることができます。詳細については、「携帯電話に発行する」を参照してください。
を使用して SMS メッセージプリファレンスを設定する AWS Management Console
Amazon SNS コンソールにサインインします。
-
SMS メッセージングをサポートしているリージョンを選択します。
-
ナビゲーションパネルで、[モバイル]、[(テキストメッセージング (SMS)] を選択します。
-
[モバイルテキストメッセージング (SMS)] ページの [テキストメッセージプリファレンス] セクションで、[編集] を選択します。
-
[テキストメッセージングの優先設定の編集] ページの [詳細] セクションで、以下の操作を実行します。
-
[デフォルトメッセージタイプ] で、次のいずれかを選択します。
プロモーションおよびトランザクションメッセージの料金表の詳細については、「グローバル SMS 料金表」を参照してください。
-
[アカウントの使用料制限] に、各暦月で SMS メッセージに使用する額 (USD) を入力します。
-
デフォルトでは、使用限度は 1.00 USD に設定されます。サービス限度を引き上げるには、リクエストを送信します。
-
コンソールに設定した量がサービス限度を超える場合、Amazon SNS は SMS メッセージの発行を停止します。
-
Amazon SNS は分散システムであるため、使用クォータを超えると数分以内に SMS メッセージの送信を停止します。その間に SMS メッセージを送信し続けると、クォータを超えるコストが発生する可能性があります。
-
(オプション) [デフォルトの送信者 ID] にカスタム ID (ビジネスブランドなど) を入力します。これは、受信デバイスに送信者として表示されます。
送信者 ID のサポートについては、国によって異なります。
-
(オプション) 使用状況レポート用の Amazon S3 バケット名の名前を入力します。
S3 バケットポリシーによって Amazon SNS への書き込みアクセスが付与される必要があります。
-
[変更を保存]をクリックします。
プリファレンスの設定 (AWS SDK)
いずれかの AWS SDK を使用して SMS プリファレンスを設定するには、Amazon SNS API SetSMSAttributes
のリクエストに対応するその SDK のアクションを使用します。このリクエストによって、月ごとの使用限度およびデフォルトの SMS タイプ (プロモーションまたはトランザクション) などの、異なる SMS の属性に値を割り当てます。利用可能な SMS 属性の詳細については、『Amazon Simple Notification Service API リファレンス』の「SetSMSAttributes」を参照してください。
以下のコード例は使用方法を示しています。SetSMSAttributes
- C++
-
- SDK for C++
-
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();
}
- CLI
-
- AWS CLI
-
SMS メッセージ属性を設定するには
次の set-sms-attributes
の例では、SMS メッセージのデフォルトの送信者 ID を MyName
に設定します。
aws sns set-sms-attributes \
--attributes DefaultSenderID=MyName
このコマンドでは何も出力されません。
- Java
-
- SDK for Java 2.x
-
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);
}
}
}
- JavaScript
-
- JavaScript (v3) 用 SDK
-
別のモジュールでクライアントを作成し、エクスポートします。
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
-
$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());
}