AWS::SNS::Subscription
AWS::SNS::Subscription
リソースは、エンドポイントを Amazon Simple Notification Service (Amazon SNS) トピックにサブスクライブします。作成するサブスクリプションについては、エンドポイントの所有者はサブスクリプションを確認する必要があります。
構文
AWS CloudFormation テンプレートでこのエンティティを宣言するには、次の構文を使用します。
JSON
{ "Type" : "AWS::SNS::Subscription", "Properties" : { "DeliveryPolicy" :
Json
, "Endpoint" :String
, "FilterPolicy" :Json
, "Protocol" :String
, "RawMessageDelivery" :Boolean
, "RedrivePolicy" :Json
, "Region" :String
, "TopicArn" :String
} }
YAML
Type: AWS::SNS::Subscription Properties: DeliveryPolicy:
Json
Endpoint:String
FilterPolicy:Json
Protocol:String
RawMessageDelivery:Boolean
RedrivePolicy:Json
Region:String
TopicArn:String
プロパティ
DeliveryPolicy
-
サブスクリプションに割り当てられている配信ポリシーの JSON。トピックにサブスクライブされている HTTP/S エンドポイントの場合、受信者がメッセージ配信の再試行戦略を定義できるようにします。詳細については、Amazon Simple Notification Service API リファレンスの「
GetSubscriptionAttributes
」および 「Amazon SNS 開発者ガイドの「メッセージ配信の再試行」を参照してください。必須: いいえ
タイプ: Json
Update requires: No interruption
Endpoint
-
サブスクリプションのエンドポイント。エンドポイント値は、指定したプロトコルによって異なります。詳細については、Amazon Simple Notification Service API リファレンスの「
Subscribe
アクションのEndpoint
パラメータ」を参照してください。必須: いいえ
タイプ: 文字列
Update requires: Replacement
FilterPolicy
-
サブスクリプションに割り当てられているフィルターポリシーの JSON。受信者が不要なメッセージのフィルタ処理を行えるようにします。詳細については、Amazon Simple Notification Service API リファレンスの「
GetSubscriptionAttributes
」および Amazon SNS 開発者ガイドの「メッセージのフィルタ処理」を参照してください。必須: いいえ
タイプ: Json
Update requires: No interruption
Protocol
-
サブスクリプションのプロトコル。詳細については、Amazon Simple Notification Service API リファレンスの「
Subscribe
アクションのProtocol
パラメータ」を参照してください。必須: はい
タイプ: 文字列
Update requires: Replacement
RawMessageDelivery
-
true
に設定すると、raw メッセージ配信が有効になります。raw メッセージには JSON 形式はなく、Amazon SQS および HTTP/S エンドポイントに送信できます。詳細については、Amazon Simple Notification Service API リファレンスの「GetSubscriptionAttributes
」を参照してください。必須: いいえ
タイプ: ブール値
Update requires: No interruption
RedrivePolicy
-
指定すると、指定された Amazon SQS デッドレターキューに配信不能メッセージを送信します。クライアントエラー(例: サブスクライブされたエンドポイントに到達できない)またはサーバーエラー(例: サブスクライブされたエンドポイントに電力を供給するサービスが使用できなくなる)が原因で配信できないメッセージは、詳細な分析や再処理のためにデッドレターキューに保持されます。
必須: いいえ
タイプ: Json
Update requires: No interruption
Region
-
クロスリージョンサブスクリプションの場合、トピックが存在するリージョン。
リージョンが指定されていない場合、CloudFormation は発信者のリージョンをデフォルトとして使用します。
AWS::SNS::Subscription
リソースのRegion
プロパティのみを更新する更新オペレーションを実行すると、次のいずれかの操作を行わない限り、そのオペレーションは失敗します。-
Region
を 発信者リージョンからNULL
に更新する。 -
Region
から 発信者リージョンNULL
への更新。
必須: いいえ
タイプ: 文字列
Update requires: No interruption
-
TopicArn
-
サブスクライブ先のトピックの ARN。
必須: はい
タイプ: 文字列
Update requires: Replacement
例
必須属性でサブスクリプションを作成
次の例では、エンドポイント、プロトコル、トピック ARN のみを使用してサブスクリプションを作成します。
JSON
"MySubscription" : { "Type" : "AWS::SNS::Subscription", "Properties" : { "Endpoint" : "test@example.com", "Protocol" : "email", "TopicArn" : { "Ref" : "MySNSTopic" } } }
YAML
MySubscription: Type: AWS::SNS::Subscription Properties: Endpoint: test@example.com Protocol: email TopicArn: !Ref 'MySNSTopic'
オプションの属性でサブスクリプションを作成
次の例では、フィルターポリシー、配信ポリシー、raw メッセージ配信を有効にしてサブスクリプションを作成します。
サブスクリプション属性は、スタンドアロンの Amazon SNS サブスクリプションでのみ設定できます (トピックにネストされたサブスクリプションでは設定できません)。
YAML
AWSTemplateFormatVersion: 2010-09-09 Resources: CarSalesTopic: Type: 'AWS::SNS::Topic' ERPSubscription: Type: 'AWS::SNS::Subscription' Properties: TopicArn: !Ref CarSalesTopic Endpoint: !GetAtt - ERPIntegrationQueue - Arn Protocol: sqs RawMessageDelivery: 'true' CRMSubscription: Type: 'AWS::SNS::Subscription' Properties: TopicArn: !Ref CarSalesTopic Endpoint: !GetAtt - CRMIntegrationQueue - Arn Protocol: sqs RawMessageDelivery: 'true' FilterPolicy: buyer-class: - vip SCMSubscription: Type: 'AWS::SNS::Subscription' Properties: TopicArn: !Ref CarSalesTopic Endpoint: !Ref myHttpEndpoint Protocol: https DeliveryPolicy: healthyRetryPolicy: numRetries: 20 minDelayTarget: 10 maxDelayTarget: 30 numMinDelayRetries: 3 numMaxDelayRetries: 17 numNoDelayRetries: 0 backoffFunction: exponential ERPIntegrationQueue: Type: 'AWS::SQS::Queue' Properties: {} CRMIntegrationQueue: Type: 'AWS::SQS::Queue' Properties: {} Parameters: myHttpEndpoint: Type: String
JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "CarSalesTopic": { "Type": "AWS::SNS::Topic" }, "ERPSubscription": { "Type": "AWS::SNS::Subscription", "Properties": { "TopicArn": { "Ref": "CarSalesTopic" }, "Endpoint": { "Fn::GetAtt": ["ERPIntegrationQueue", "Arn"] }, "Protocol": "sqs", "RawMessageDelivery": "true" } }, "CRMSubscription": { "Type": "AWS::SNS::Subscription", "Properties": { "TopicArn": { "Ref": "CarSalesTopic" }, "Endpoint": { "Fn::GetAtt": ["CRMIntegrationQueue", "Arn"] }, "Protocol": "sqs", "RawMessageDelivery": "true", "FilterPolicy": { "buyer-class": [ "vip" ] } } }, "SCMSubscription": { "Type": "AWS::SNS::Subscription", "Properties": { "TopicArn": { "Ref": "CarSalesTopic" }, "Endpoint": { "Ref": "myHttpEndpoint" }, "Protocol": "https", "DeliveryPolicy": { "healthyRetryPolicy": { "numRetries": 20, "minDelayTarget": 10, "maxDelayTarget": 30, "numMinDelayRetries": 3, "numMaxDelayRetries": 17, "numNoDelayRetries": 0, "backoffFunction": "exponential" } } } }, "ERPIntegrationQueue": { "Type": "AWS::SQS::Queue", "Properties": {} }, "CRMIntegrationQueue": { "Type": "AWS::SQS::Queue", "Properties": {} } }, "Parameters": { "myHttpEndpoint": { "Type": "String" } } }