aws.sns.TopicSubscription
Explore with Pulumi AI
Provides a resource for subscribing to SNS topics. Requires that an SNS topic exist for the subscription to attach to. This resource allows you to automatically place messages sent to SNS topics in SQS queues, send them as HTTP(S) POST requests to a given endpoint, send SMS messages, or notify devices / applications. The most likely use case for provider users will probably be SQS queues.
NOTE: If the SNS topic and SQS queue are in different AWS regions, the
aws.sns.TopicSubscription
must use an AWS provider that is in the same region as the SNS topic. If theaws.sns.TopicSubscription
uses a provider with a different region than the SNS topic, this provider will fail to create the subscription.
NOTE: Setup of cross-account subscriptions from SNS topics to SQS queues requires the provider to have access to BOTH accounts.
NOTE: If an SNS topic and SQS queue are in different AWS accounts but the same region, the
aws.sns.TopicSubscription
must use the AWS provider for the account with the SQS queue. Ifaws.sns.TopicSubscription
uses a Provider with a different account than the SQS queue, this provider creates the subscription but does not keep state and tries to re-create the subscription at everyapply
.
NOTE: If an SNS topic and SQS queue are in different AWS accounts and different AWS regions, the subscription needs to be initiated from the account with the SQS queue but in the region of the SNS topic.
NOTE: You cannot unsubscribe to a subscription that is pending confirmation. If you use
email-json
, orhttp
/https
(without auto-confirmation enabled), until the subscription is confirmed (e.g., outside of this provider), AWS does not allow this provider to delete / unsubscribe the subscription. If youdestroy
an unconfirmed subscription, this provider will remove the subscription from its state but the subscription will still exist in AWS. However, if you delete an SNS topic, SNS deletes all the subscriptions associated with the topic. Also, you can import a subscription after confirmation and then have the capability to delete it.
Example Usage
Basic usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const userUpdates = new aws.sns.Topic("user_updates", {name: "user-updates-topic"});
const sqsQueuePolicy = userUpdates.arn.apply(arn => aws.iam.getPolicyDocumentOutput({
policyId: "arn:aws:sqs:us-west-2:123456789012:user_updates_queue/SQSDefaultPolicy",
statements: [{
sid: "user_updates_sqs_target",
effect: "Allow",
principals: [{
type: "Service",
identifiers: ["sns.amazonaws.com"],
}],
actions: ["SQS:SendMessage"],
resources: ["arn:aws:sqs:us-west-2:123456789012:user-updates-queue"],
conditions: [{
test: "ArnEquals",
variable: "aws:SourceArn",
values: [arn],
}],
}],
}));
const userUpdatesQueue = new aws.sqs.Queue("user_updates_queue", {
name: "user-updates-queue",
policy: sqsQueuePolicy.apply(sqsQueuePolicy => sqsQueuePolicy.json),
});
const userUpdatesSqsTarget = new aws.sns.TopicSubscription("user_updates_sqs_target", {
topic: userUpdates.arn,
protocol: "sqs",
endpoint: userUpdatesQueue.arn,
});
import pulumi
import pulumi_aws as aws
user_updates = aws.sns.Topic("user_updates", name="user-updates-topic")
sqs_queue_policy = user_updates.arn.apply(lambda arn: aws.iam.get_policy_document_output(policy_id="arn:aws:sqs:us-west-2:123456789012:user_updates_queue/SQSDefaultPolicy",
statements=[{
"sid": "user_updates_sqs_target",
"effect": "Allow",
"principals": [{
"type": "Service",
"identifiers": ["sns.amazonaws.com"],
}],
"actions": ["SQS:SendMessage"],
"resources": ["arn:aws:sqs:us-west-2:123456789012:user-updates-queue"],
"conditions": [{
"test": "ArnEquals",
"variable": "aws:SourceArn",
"values": [arn],
}],
}]))
user_updates_queue = aws.sqs.Queue("user_updates_queue",
name="user-updates-queue",
policy=sqs_queue_policy.json)
user_updates_sqs_target = aws.sns.TopicSubscription("user_updates_sqs_target",
topic=user_updates.arn,
protocol="sqs",
endpoint=user_updates_queue.arn)
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sns"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sqs"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
userUpdates, err := sns.NewTopic(ctx, "user_updates", &sns.TopicArgs{
Name: pulumi.String("user-updates-topic"),
})
if err != nil {
return err
}
sqsQueuePolicy := userUpdates.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
return iam.GetPolicyDocumentResult(interface{}(iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
PolicyId: "arn:aws:sqs:us-west-2:123456789012:user_updates_queue/SQSDefaultPolicy",
Statements: []iam.GetPolicyDocumentStatement{
{
Sid: "user_updates_sqs_target",
Effect: "Allow",
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "Service",
Identifiers: []string{
"sns.amazonaws.com",
},
},
},
Actions: []string{
"SQS:SendMessage",
},
Resources: []string{
"arn:aws:sqs:us-west-2:123456789012:user-updates-queue",
},
Conditions: []iam.GetPolicyDocumentStatementCondition{
{
Test: "ArnEquals",
Variable: "aws:SourceArn",
Values: interface{}{
arn,
},
},
},
},
},
}, nil))), nil
}).(iam.GetPolicyDocumentResultOutput)
userUpdatesQueue, err := sqs.NewQueue(ctx, "user_updates_queue", &sqs.QueueArgs{
Name: pulumi.String("user-updates-queue"),
Policy: pulumi.String(sqsQueuePolicy.ApplyT(func(sqsQueuePolicy iam.GetPolicyDocumentResult) (*string, error) {
return &sqsQueuePolicy.Json, nil
}).(pulumi.StringPtrOutput)),
})
if err != nil {
return err
}
_, err = sns.NewTopicSubscription(ctx, "user_updates_sqs_target", &sns.TopicSubscriptionArgs{
Topic: userUpdates.Arn,
Protocol: pulumi.String("sqs"),
Endpoint: userUpdatesQueue.Arn,
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var userUpdates = new Aws.Sns.Topic("user_updates", new()
{
Name = "user-updates-topic",
});
var sqsQueuePolicy = Aws.Iam.GetPolicyDocument.Invoke(new()
{
PolicyId = "arn:aws:sqs:us-west-2:123456789012:user_updates_queue/SQSDefaultPolicy",
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Sid = "user_updates_sqs_target",
Effect = "Allow",
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "Service",
Identifiers = new[]
{
"sns.amazonaws.com",
},
},
},
Actions = new[]
{
"SQS:SendMessage",
},
Resources = new[]
{
"arn:aws:sqs:us-west-2:123456789012:user-updates-queue",
},
Conditions = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
{
Test = "ArnEquals",
Variable = "aws:SourceArn",
Values = new[]
{
userUpdates.Arn,
},
},
},
},
},
});
var userUpdatesQueue = new Aws.Sqs.Queue("user_updates_queue", new()
{
Name = "user-updates-queue",
Policy = sqsQueuePolicy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
var userUpdatesSqsTarget = new Aws.Sns.TopicSubscription("user_updates_sqs_target", new()
{
Topic = userUpdates.Arn,
Protocol = "sqs",
Endpoint = userUpdatesQueue.Arn,
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.sns.Topic;
import com.pulumi.aws.sns.TopicArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.sqs.Queue;
import com.pulumi.aws.sqs.QueueArgs;
import com.pulumi.aws.sns.TopicSubscription;
import com.pulumi.aws.sns.TopicSubscriptionArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var userUpdates = new Topic("userUpdates", TopicArgs.builder()
.name("user-updates-topic")
.build());
final var sqsQueuePolicy = userUpdates.arn().applyValue(_arn -> IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.policyId("arn:aws:sqs:us-west-2:123456789012:user_updates_queue/SQSDefaultPolicy")
.statements(GetPolicyDocumentStatementArgs.builder()
.sid("user_updates_sqs_target")
.effect("Allow")
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("sns.amazonaws.com")
.build())
.actions("SQS:SendMessage")
.resources("arn:aws:sqs:us-west-2:123456789012:user-updates-queue")
.conditions(GetPolicyDocumentStatementConditionArgs.builder()
.test("ArnEquals")
.variable("aws:SourceArn")
.values(_arn)
.build())
.build())
.build()));
var userUpdatesQueue = new Queue("userUpdatesQueue", QueueArgs.builder()
.name("user-updates-queue")
.policy(sqsQueuePolicy.applyValue(_sqsQueuePolicy -> _sqsQueuePolicy.json()))
.build());
var userUpdatesSqsTarget = new TopicSubscription("userUpdatesSqsTarget", TopicSubscriptionArgs.builder()
.topic(userUpdates.arn())
.protocol("sqs")
.endpoint(userUpdatesQueue.arn())
.build());
}
}
resources:
userUpdates:
type: aws:sns:Topic
name: user_updates
properties:
name: user-updates-topic
userUpdatesQueue:
type: aws:sqs:Queue
name: user_updates_queue
properties:
name: user-updates-queue
policy: ${sqsQueuePolicy.json}
userUpdatesSqsTarget:
type: aws:sns:TopicSubscription
name: user_updates_sqs_target
properties:
topic: ${userUpdates.arn}
protocol: sqs
endpoint: ${userUpdatesQueue.arn}
variables:
sqsQueuePolicy:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
policyId: arn:aws:sqs:us-west-2:123456789012:user_updates_queue/SQSDefaultPolicy
statements:
- sid: user_updates_sqs_target
effect: Allow
principals:
- type: Service
identifiers:
- sns.amazonaws.com
actions:
- SQS:SendMessage
resources:
- arn:aws:sqs:us-west-2:123456789012:user-updates-queue
conditions:
- test: ArnEquals
variable: aws:SourceArn
values:
- ${userUpdates.arn}
Example Cross-account Subscription
You can subscribe SNS topics to SQS queues in different Amazon accounts and regions:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const config = new pulumi.Config();
const sns = config.getObject<any>("sns") || {
"account-id": "111111111111",
displayName: "example",
name: "example-sns-topic",
region: "us-west-1",
"role-name": "service/service",
};
const sqs = config.getObject<any>("sqs") || {
"account-id": "222222222222",
name: "example-sqs-queue",
region: "us-east-1",
"role-name": "service/service",
};
const snsTopicPolicy = aws.iam.getPolicyDocument({
policyId: "__default_policy_ID",
statements: [
{
actions: [
"SNS:Subscribe",
"SNS:SetTopicAttributes",
"SNS:RemovePermission",
"SNS:Publish",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:DeleteTopic",
"SNS:AddPermission",
],
conditions: [{
test: "StringEquals",
variable: "AWS:SourceOwner",
values: [sns["account-id"]],
}],
effect: "Allow",
principals: [{
type: "AWS",
identifiers: ["*"],
}],
resources: [`arn:aws:sns:${sns.region}:${sns["account-id"]}:${sns.name}`],
sid: "__default_statement_ID",
},
{
actions: [
"SNS:Subscribe",
"SNS:Receive",
],
conditions: [{
test: "StringLike",
variable: "SNS:Endpoint",
values: [`arn:aws:sqs:${sqs.region}:${sqs["account-id"]}:${sqs.name}`],
}],
effect: "Allow",
principals: [{
type: "AWS",
identifiers: ["*"],
}],
resources: [`arn:aws:sns:${sns.region}:${sns["account-id"]}:${sns.name}`],
sid: "__console_sub_0",
},
],
});
const sqsQueuePolicy = aws.iam.getPolicyDocument({
policyId: `arn:aws:sqs:${sqs.region}:${sqs["account-id"]}:${sqs.name}/SQSDefaultPolicy`,
statements: [{
sid: "example-sns-topic",
effect: "Allow",
principals: [{
type: "AWS",
identifiers: ["*"],
}],
actions: ["SQS:SendMessage"],
resources: [`arn:aws:sqs:${sqs.region}:${sqs["account-id"]}:${sqs.name}`],
conditions: [{
test: "ArnEquals",
variable: "aws:SourceArn",
values: [`arn:aws:sns:${sns.region}:${sns["account-id"]}:${sns.name}`],
}],
}],
});
const snsTopic = new aws.sns.Topic("sns_topic", {
name: sns.name,
displayName: sns.display_name,
policy: snsTopicPolicy.then(snsTopicPolicy => snsTopicPolicy.json),
});
const sqsQueue = new aws.sqs.Queue("sqs_queue", {
name: sqs.name,
policy: sqsQueuePolicy.then(sqsQueuePolicy => sqsQueuePolicy.json),
});
const snsTopicTopicSubscription = new aws.sns.TopicSubscription("sns_topic", {
topic: snsTopic.arn,
protocol: "sqs",
endpoint: sqsQueue.arn,
});
import pulumi
import pulumi_aws as aws
config = pulumi.Config()
sns = config.get_object("sns")
if sns is None:
sns = {
"account-id": "111111111111",
"displayName": "example",
"name": "example-sns-topic",
"region": "us-west-1",
"role-name": "service/service",
}
sqs = config.get_object("sqs")
if sqs is None:
sqs = {
"account-id": "222222222222",
"name": "example-sqs-queue",
"region": "us-east-1",
"role-name": "service/service",
}
sns_topic_policy = aws.iam.get_policy_document(policy_id="__default_policy_ID",
statements=[
{
"actions": [
"SNS:Subscribe",
"SNS:SetTopicAttributes",
"SNS:RemovePermission",
"SNS:Publish",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:DeleteTopic",
"SNS:AddPermission",
],
"conditions": [{
"test": "StringEquals",
"variable": "AWS:SourceOwner",
"values": [sns["account-id"]],
}],
"effect": "Allow",
"principals": [{
"type": "AWS",
"identifiers": ["*"],
}],
"resources": [f"arn:aws:sns:{sns['region']}:{sns['account-id']}:{sns['name']}"],
"sid": "__default_statement_ID",
},
{
"actions": [
"SNS:Subscribe",
"SNS:Receive",
],
"conditions": [{
"test": "StringLike",
"variable": "SNS:Endpoint",
"values": [f"arn:aws:sqs:{sqs['region']}:{sqs['account-id']}:{sqs['name']}"],
}],
"effect": "Allow",
"principals": [{
"type": "AWS",
"identifiers": ["*"],
}],
"resources": [f"arn:aws:sns:{sns['region']}:{sns['account-id']}:{sns['name']}"],
"sid": "__console_sub_0",
},
])
sqs_queue_policy = aws.iam.get_policy_document(policy_id=f"arn:aws:sqs:{sqs['region']}:{sqs['account-id']}:{sqs['name']}/SQSDefaultPolicy",
statements=[{
"sid": "example-sns-topic",
"effect": "Allow",
"principals": [{
"type": "AWS",
"identifiers": ["*"],
}],
"actions": ["SQS:SendMessage"],
"resources": [f"arn:aws:sqs:{sqs['region']}:{sqs['account-id']}:{sqs['name']}"],
"conditions": [{
"test": "ArnEquals",
"variable": "aws:SourceArn",
"values": [f"arn:aws:sns:{sns['region']}:{sns['account-id']}:{sns['name']}"],
}],
}])
sns_topic = aws.sns.Topic("sns_topic",
name=sns["name"],
display_name=sns["display_name"],
policy=sns_topic_policy.json)
sqs_queue = aws.sqs.Queue("sqs_queue",
name=sqs["name"],
policy=sqs_queue_policy.json)
sns_topic_topic_subscription = aws.sns.TopicSubscription("sns_topic",
topic=sns_topic.arn,
protocol="sqs",
endpoint=sqs_queue.arn)
package main
import (
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sns"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sqs"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
cfg := config.New(ctx, "")
sns := map[string]interface{}{
"account-id": "111111111111",
"displayName": "example",
"name": "example-sns-topic",
"region": "us-west-1",
"role-name": "service/service",
};
if param := cfg.GetObject("sns"); param != nil {
sns = param
}
sqs := map[string]interface{}{
"account-id": "222222222222",
"name": "example-sqs-queue",
"region": "us-east-1",
"role-name": "service/service",
};
if param := cfg.GetObject("sqs"); param != nil {
sqs = param
}
snsTopicPolicy, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
PolicyId: pulumi.StringRef("__default_policy_ID"),
Statements: []iam.GetPolicyDocumentStatement{
{
Actions: []string{
"SNS:Subscribe",
"SNS:SetTopicAttributes",
"SNS:RemovePermission",
"SNS:Publish",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:DeleteTopic",
"SNS:AddPermission",
},
Conditions: []iam.GetPolicyDocumentStatementCondition{
{
Test: "StringEquals",
Variable: "AWS:SourceOwner",
Values: interface{}{
sns.AccountId,
},
},
},
Effect: pulumi.StringRef("Allow"),
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "AWS",
Identifiers: []string{
"*",
},
},
},
Resources: []string{
fmt.Sprintf("arn:aws:sns:%v:%v:%v", sns.Region, sns.AccountId, sns.Name),
},
Sid: pulumi.StringRef("__default_statement_ID"),
},
{
Actions: []string{
"SNS:Subscribe",
"SNS:Receive",
},
Conditions: []iam.GetPolicyDocumentStatementCondition{
{
Test: "StringLike",
Variable: "SNS:Endpoint",
Values: []string{
fmt.Sprintf("arn:aws:sqs:%v:%v:%v", sqs.Region, sqs.AccountId, sqs.Name),
},
},
},
Effect: pulumi.StringRef("Allow"),
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "AWS",
Identifiers: []string{
"*",
},
},
},
Resources: []string{
fmt.Sprintf("arn:aws:sns:%v:%v:%v", sns.Region, sns.AccountId, sns.Name),
},
Sid: pulumi.StringRef("__console_sub_0"),
},
},
}, nil);
if err != nil {
return err
}
sqsQueuePolicy, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
PolicyId: pulumi.StringRef(fmt.Sprintf("arn:aws:sqs:%v:%v:%v/SQSDefaultPolicy", sqs.Region, sqs.AccountId, sqs.Name)),
Statements: []iam.GetPolicyDocumentStatement{
{
Sid: pulumi.StringRef("example-sns-topic"),
Effect: pulumi.StringRef("Allow"),
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "AWS",
Identifiers: []string{
"*",
},
},
},
Actions: []string{
"SQS:SendMessage",
},
Resources: []string{
fmt.Sprintf("arn:aws:sqs:%v:%v:%v", sqs.Region, sqs.AccountId, sqs.Name),
},
Conditions: []iam.GetPolicyDocumentStatementCondition{
{
Test: "ArnEquals",
Variable: "aws:SourceArn",
Values: []string{
fmt.Sprintf("arn:aws:sns:%v:%v:%v", sns.Region, sns.AccountId, sns.Name),
},
},
},
},
},
}, nil);
if err != nil {
return err
}
snsTopic, err := sns.NewTopic(ctx, "sns_topic", &sns.TopicArgs{
Name: pulumi.Any(sns.Name),
DisplayName: pulumi.Any(sns.Display_name),
Policy: pulumi.String(snsTopicPolicy.Json),
})
if err != nil {
return err
}
sqsQueue, err := sqs.NewQueue(ctx, "sqs_queue", &sqs.QueueArgs{
Name: pulumi.Any(sqs.Name),
Policy: pulumi.String(sqsQueuePolicy.Json),
})
if err != nil {
return err
}
_, err = sns.NewTopicSubscription(ctx, "sns_topic", &sns.TopicSubscriptionArgs{
Topic: snsTopic.Arn,
Protocol: pulumi.String("sqs"),
Endpoint: sqsQueue.Arn,
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var sns = config.GetObject<dynamic>("sns") ??
{
{ "account-id", "111111111111" },
{ "displayName", "example" },
{ "name", "example-sns-topic" },
{ "region", "us-west-1" },
{ "role-name", "service/service" },
};
var sqs = config.GetObject<dynamic>("sqs") ??
{
{ "account-id", "222222222222" },
{ "name", "example-sqs-queue" },
{ "region", "us-east-1" },
{ "role-name", "service/service" },
};
var snsTopicPolicy = Aws.Iam.GetPolicyDocument.Invoke(new()
{
PolicyId = "__default_policy_ID",
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Actions = new[]
{
"SNS:Subscribe",
"SNS:SetTopicAttributes",
"SNS:RemovePermission",
"SNS:Publish",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:DeleteTopic",
"SNS:AddPermission",
},
Conditions = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
{
Test = "StringEquals",
Variable = "AWS:SourceOwner",
Values = new[]
{
sns.Account_id,
},
},
},
Effect = "Allow",
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "AWS",
Identifiers = new[]
{
"*",
},
},
},
Resources = new[]
{
$"arn:aws:sns:{sns.Region}:{sns.Account_id}:{sns.Name}",
},
Sid = "__default_statement_ID",
},
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Actions = new[]
{
"SNS:Subscribe",
"SNS:Receive",
},
Conditions = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
{
Test = "StringLike",
Variable = "SNS:Endpoint",
Values = new[]
{
$"arn:aws:sqs:{sqs.Region}:{sqs.Account_id}:{sqs.Name}",
},
},
},
Effect = "Allow",
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "AWS",
Identifiers = new[]
{
"*",
},
},
},
Resources = new[]
{
$"arn:aws:sns:{sns.Region}:{sns.Account_id}:{sns.Name}",
},
Sid = "__console_sub_0",
},
},
});
var sqsQueuePolicy = Aws.Iam.GetPolicyDocument.Invoke(new()
{
PolicyId = $"arn:aws:sqs:{sqs.Region}:{sqs.Account_id}:{sqs.Name}/SQSDefaultPolicy",
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Sid = "example-sns-topic",
Effect = "Allow",
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "AWS",
Identifiers = new[]
{
"*",
},
},
},
Actions = new[]
{
"SQS:SendMessage",
},
Resources = new[]
{
$"arn:aws:sqs:{sqs.Region}:{sqs.Account_id}:{sqs.Name}",
},
Conditions = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
{
Test = "ArnEquals",
Variable = "aws:SourceArn",
Values = new[]
{
$"arn:aws:sns:{sns.Region}:{sns.Account_id}:{sns.Name}",
},
},
},
},
},
});
var snsTopic = new Aws.Sns.Topic("sns_topic", new()
{
Name = sns.Name,
DisplayName = sns.Display_name,
Policy = snsTopicPolicy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
var sqsQueue = new Aws.Sqs.Queue("sqs_queue", new()
{
Name = sqs.Name,
Policy = sqsQueuePolicy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
var snsTopicTopicSubscription = new Aws.Sns.TopicSubscription("sns_topic", new()
{
Topic = snsTopic.Arn,
Protocol = "sqs",
Endpoint = sqsQueue.Arn,
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.sns.Topic;
import com.pulumi.aws.sns.TopicArgs;
import com.pulumi.aws.sqs.Queue;
import com.pulumi.aws.sqs.QueueArgs;
import com.pulumi.aws.sns.TopicSubscription;
import com.pulumi.aws.sns.TopicSubscriptionArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var config = ctx.config();
final var sns = config.get("sns").orElse(Map.ofEntries(
Map.entry("account-id", "111111111111"),
Map.entry("displayName", "example"),
Map.entry("name", "example-sns-topic"),
Map.entry("region", "us-west-1"),
Map.entry("role-name", "service/service")
));
final var sqs = config.get("sqs").orElse(Map.ofEntries(
Map.entry("account-id", "222222222222"),
Map.entry("name", "example-sqs-queue"),
Map.entry("region", "us-east-1"),
Map.entry("role-name", "service/service")
));
final var snsTopicPolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.policyId("__default_policy_ID")
.statements(
GetPolicyDocumentStatementArgs.builder()
.actions(
"SNS:Subscribe",
"SNS:SetTopicAttributes",
"SNS:RemovePermission",
"SNS:Publish",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:DeleteTopic",
"SNS:AddPermission")
.conditions(GetPolicyDocumentStatementConditionArgs.builder()
.test("StringEquals")
.variable("AWS:SourceOwner")
.values(sns.account-id())
.build())
.effect("Allow")
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("AWS")
.identifiers("*")
.build())
.resources(String.format("arn:aws:sns:%s:%s:%s", sns.region(),sns.account-id(),sns.name()))
.sid("__default_statement_ID")
.build(),
GetPolicyDocumentStatementArgs.builder()
.actions(
"SNS:Subscribe",
"SNS:Receive")
.conditions(GetPolicyDocumentStatementConditionArgs.builder()
.test("StringLike")
.variable("SNS:Endpoint")
.values(String.format("arn:aws:sqs:%s:%s:%s", sqs.region(),sqs.account-id(),sqs.name()))
.build())
.effect("Allow")
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("AWS")
.identifiers("*")
.build())
.resources(String.format("arn:aws:sns:%s:%s:%s", sns.region(),sns.account-id(),sns.name()))
.sid("__console_sub_0")
.build())
.build());
final var sqsQueuePolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.policyId(String.format("arn:aws:sqs:%s:%s:%s/SQSDefaultPolicy", sqs.region(),sqs.account-id(),sqs.name()))
.statements(GetPolicyDocumentStatementArgs.builder()
.sid("example-sns-topic")
.effect("Allow")
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("AWS")
.identifiers("*")
.build())
.actions("SQS:SendMessage")
.resources(String.format("arn:aws:sqs:%s:%s:%s", sqs.region(),sqs.account-id(),sqs.name()))
.conditions(GetPolicyDocumentStatementConditionArgs.builder()
.test("ArnEquals")
.variable("aws:SourceArn")
.values(String.format("arn:aws:sns:%s:%s:%s", sns.region(),sns.account-id(),sns.name()))
.build())
.build())
.build());
var snsTopic = new Topic("snsTopic", TopicArgs.builder()
.name(sns.name())
.displayName(sns.display_name())
.policy(snsTopicPolicy.json())
.build());
var sqsQueue = new Queue("sqsQueue", QueueArgs.builder()
.name(sqs.name())
.policy(sqsQueuePolicy.json())
.build());
var snsTopicTopicSubscription = new TopicSubscription("snsTopicTopicSubscription", TopicSubscriptionArgs.builder()
.topic(snsTopic.arn())
.protocol("sqs")
.endpoint(sqsQueue.arn())
.build());
}
}
configuration:
sns:
type: dynamic
default:
account-id: '111111111111'
displayName: example
name: example-sns-topic
region: us-west-1
role-name: service/service
sqs:
type: dynamic
default:
account-id: '222222222222'
name: example-sqs-queue
region: us-east-1
role-name: service/service
resources:
snsTopic:
type: aws:sns:Topic
name: sns_topic
properties:
name: ${sns.name}
displayName: ${sns.display_name}
policy: ${snsTopicPolicy.json}
sqsQueue:
type: aws:sqs:Queue
name: sqs_queue
properties:
name: ${sqs.name}
policy: ${sqsQueuePolicy.json}
snsTopicTopicSubscription:
type: aws:sns:TopicSubscription
name: sns_topic
properties:
topic: ${snsTopic.arn}
protocol: sqs
endpoint: ${sqsQueue.arn}
variables:
snsTopicPolicy:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
policyId: __default_policy_ID
statements:
- actions:
- SNS:Subscribe
- SNS:SetTopicAttributes
- SNS:RemovePermission
- SNS:Publish
- SNS:ListSubscriptionsByTopic
- SNS:GetTopicAttributes
- SNS:DeleteTopic
- SNS:AddPermission
conditions:
- test: StringEquals
variable: AWS:SourceOwner
values:
- ${sns"account-id"[%!s(MISSING)]}
effect: Allow
principals:
- type: AWS
identifiers:
- '*'
resources:
- arn:aws:sns:${sns.region}:${sns"account-id"[%!s(MISSING)]}:${sns.name}
sid: __default_statement_ID
- actions:
- SNS:Subscribe
- SNS:Receive
conditions:
- test: StringLike
variable: SNS:Endpoint
values:
- arn:aws:sqs:${sqs.region}:${sqs"account-id"[%!s(MISSING)]}:${sqs.name}
effect: Allow
principals:
- type: AWS
identifiers:
- '*'
resources:
- arn:aws:sns:${sns.region}:${sns"account-id"[%!s(MISSING)]}:${sns.name}
sid: __console_sub_0
sqsQueuePolicy:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
policyId: arn:aws:sqs:${sqs.region}:${sqs"account-id"[%!s(MISSING)]}:${sqs.name}/SQSDefaultPolicy
statements:
- sid: example-sns-topic
effect: Allow
principals:
- type: AWS
identifiers:
- '*'
actions:
- SQS:SendMessage
resources:
- arn:aws:sqs:${sqs.region}:${sqs"account-id"[%!s(MISSING)]}:${sqs.name}
conditions:
- test: ArnEquals
variable: aws:SourceArn
values:
- arn:aws:sns:${sns.region}:${sns"account-id"[%!s(MISSING)]}:${sns.name}
Example with Delivery Policy
This example demonstrates how to define a delivery_policy
for an HTTPS subscription. Unlike the aws.sns.Topic
resource, the delivery_policy
for aws.sns.TopicSubscription
should not be wrapped in an "http"
object.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const exampleWithDeliveryPolicy = new aws.sns.TopicSubscription("example_with_delivery_policy", {
topic: "arn:aws:sns:us-west-2:123456789012:my-topic",
protocol: "https",
endpoint: "https://example.com/endpoint",
rawMessageDelivery: true,
deliveryPolicy: `{
"healthyRetryPolicy": {
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numRetries": 3,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 0,
"numMinDelayRetries": 0,
"backoffFunction": "linear"
},
"sicklyRetryPolicy": null,
"throttlePolicy": null,
"requestPolicy": {
"headerContentType": "text/plain; application/json"
},
"guaranteed": false
}
`,
});
import pulumi
import pulumi_aws as aws
example_with_delivery_policy = aws.sns.TopicSubscription("example_with_delivery_policy",
topic="arn:aws:sns:us-west-2:123456789012:my-topic",
protocol="https",
endpoint="https://example.com/endpoint",
raw_message_delivery=True,
delivery_policy="""{
"healthyRetryPolicy": {
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numRetries": 3,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 0,
"numMinDelayRetries": 0,
"backoffFunction": "linear"
},
"sicklyRetryPolicy": null,
"throttlePolicy": null,
"requestPolicy": {
"headerContentType": "text/plain; application/json"
},
"guaranteed": false
}
""")
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sns"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := sns.NewTopicSubscription(ctx, "example_with_delivery_policy", &sns.TopicSubscriptionArgs{
Topic: pulumi.Any("arn:aws:sns:us-west-2:123456789012:my-topic"),
Protocol: pulumi.String("https"),
Endpoint: pulumi.String("https://example.com/endpoint"),
RawMessageDelivery: pulumi.Bool(true),
DeliveryPolicy: pulumi.String(`{
"healthyRetryPolicy": {
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numRetries": 3,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 0,
"numMinDelayRetries": 0,
"backoffFunction": "linear"
},
"sicklyRetryPolicy": null,
"throttlePolicy": null,
"requestPolicy": {
"headerContentType": "text/plain; application/json"
},
"guaranteed": false
}
`),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var exampleWithDeliveryPolicy = new Aws.Sns.TopicSubscription("example_with_delivery_policy", new()
{
Topic = "arn:aws:sns:us-west-2:123456789012:my-topic",
Protocol = "https",
Endpoint = "https://example.com/endpoint",
RawMessageDelivery = true,
DeliveryPolicy = @"{
""healthyRetryPolicy"": {
""minDelayTarget"": 20,
""maxDelayTarget"": 20,
""numRetries"": 3,
""numMaxDelayRetries"": 0,
""numNoDelayRetries"": 0,
""numMinDelayRetries"": 0,
""backoffFunction"": ""linear""
},
""sicklyRetryPolicy"": null,
""throttlePolicy"": null,
""requestPolicy"": {
""headerContentType"": ""text/plain; application/json""
},
""guaranteed"": false
}
",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.sns.TopicSubscription;
import com.pulumi.aws.sns.TopicSubscriptionArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var exampleWithDeliveryPolicy = new TopicSubscription("exampleWithDeliveryPolicy", TopicSubscriptionArgs.builder()
.topic("arn:aws:sns:us-west-2:123456789012:my-topic")
.protocol("https")
.endpoint("https://example.com/endpoint")
.rawMessageDelivery(true)
.deliveryPolicy("""
{
"healthyRetryPolicy": {
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numRetries": 3,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 0,
"numMinDelayRetries": 0,
"backoffFunction": "linear"
},
"sicklyRetryPolicy": null,
"throttlePolicy": null,
"requestPolicy": {
"headerContentType": "text/plain; application/json"
},
"guaranteed": false
}
""")
.build());
}
}
resources:
exampleWithDeliveryPolicy:
type: aws:sns:TopicSubscription
name: example_with_delivery_policy
properties:
topic: arn:aws:sns:us-west-2:123456789012:my-topic
protocol: https
endpoint: https://example.com/endpoint
rawMessageDelivery: true
deliveryPolicy: |
{
"healthyRetryPolicy": {
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numRetries": 3,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 0,
"numMinDelayRetries": 0,
"backoffFunction": "linear"
},
"sicklyRetryPolicy": null,
"throttlePolicy": null,
"requestPolicy": {
"headerContentType": "text/plain; application/json"
},
"guaranteed": false
}
Create TopicSubscription Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new TopicSubscription(name: string, args: TopicSubscriptionArgs, opts?: CustomResourceOptions);
@overload
def TopicSubscription(resource_name: str,
args: TopicSubscriptionArgs,
opts: Optional[ResourceOptions] = None)
@overload
def TopicSubscription(resource_name: str,
opts: Optional[ResourceOptions] = None,
endpoint: Optional[str] = None,
protocol: Optional[str] = None,
topic: Optional[str] = None,
confirmation_timeout_in_minutes: Optional[int] = None,
delivery_policy: Optional[str] = None,
endpoint_auto_confirms: Optional[bool] = None,
filter_policy: Optional[str] = None,
filter_policy_scope: Optional[str] = None,
raw_message_delivery: Optional[bool] = None,
redrive_policy: Optional[str] = None,
replay_policy: Optional[str] = None,
subscription_role_arn: Optional[str] = None)
func NewTopicSubscription(ctx *Context, name string, args TopicSubscriptionArgs, opts ...ResourceOption) (*TopicSubscription, error)
public TopicSubscription(string name, TopicSubscriptionArgs args, CustomResourceOptions? opts = null)
public TopicSubscription(String name, TopicSubscriptionArgs args)
public TopicSubscription(String name, TopicSubscriptionArgs args, CustomResourceOptions options)
type: aws:sns:TopicSubscription
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args TopicSubscriptionArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args TopicSubscriptionArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args TopicSubscriptionArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args TopicSubscriptionArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args TopicSubscriptionArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var topicSubscriptionResource = new Aws.Sns.TopicSubscription("topicSubscriptionResource", new()
{
Endpoint = "string",
Protocol = "string",
Topic = "string",
ConfirmationTimeoutInMinutes = 0,
DeliveryPolicy = "string",
EndpointAutoConfirms = false,
FilterPolicy = "string",
FilterPolicyScope = "string",
RawMessageDelivery = false,
RedrivePolicy = "string",
ReplayPolicy = "string",
SubscriptionRoleArn = "string",
});
example, err := sns.NewTopicSubscription(ctx, "topicSubscriptionResource", &sns.TopicSubscriptionArgs{
Endpoint: pulumi.String("string"),
Protocol: pulumi.String("string"),
Topic: pulumi.Any("string"),
ConfirmationTimeoutInMinutes: pulumi.Int(0),
DeliveryPolicy: pulumi.String("string"),
EndpointAutoConfirms: pulumi.Bool(false),
FilterPolicy: pulumi.String("string"),
FilterPolicyScope: pulumi.String("string"),
RawMessageDelivery: pulumi.Bool(false),
RedrivePolicy: pulumi.String("string"),
ReplayPolicy: pulumi.String("string"),
SubscriptionRoleArn: pulumi.String("string"),
})
var topicSubscriptionResource = new TopicSubscription("topicSubscriptionResource", TopicSubscriptionArgs.builder()
.endpoint("string")
.protocol("string")
.topic("string")
.confirmationTimeoutInMinutes(0)
.deliveryPolicy("string")
.endpointAutoConfirms(false)
.filterPolicy("string")
.filterPolicyScope("string")
.rawMessageDelivery(false)
.redrivePolicy("string")
.replayPolicy("string")
.subscriptionRoleArn("string")
.build());
topic_subscription_resource = aws.sns.TopicSubscription("topicSubscriptionResource",
endpoint="string",
protocol="string",
topic="string",
confirmation_timeout_in_minutes=0,
delivery_policy="string",
endpoint_auto_confirms=False,
filter_policy="string",
filter_policy_scope="string",
raw_message_delivery=False,
redrive_policy="string",
replay_policy="string",
subscription_role_arn="string")
const topicSubscriptionResource = new aws.sns.TopicSubscription("topicSubscriptionResource", {
endpoint: "string",
protocol: "string",
topic: "string",
confirmationTimeoutInMinutes: 0,
deliveryPolicy: "string",
endpointAutoConfirms: false,
filterPolicy: "string",
filterPolicyScope: "string",
rawMessageDelivery: false,
redrivePolicy: "string",
replayPolicy: "string",
subscriptionRoleArn: "string",
});
type: aws:sns:TopicSubscription
properties:
confirmationTimeoutInMinutes: 0
deliveryPolicy: string
endpoint: string
endpointAutoConfirms: false
filterPolicy: string
filterPolicyScope: string
protocol: string
rawMessageDelivery: false
redrivePolicy: string
replayPolicy: string
subscriptionRoleArn: string
topic: string
TopicSubscription Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The TopicSubscription resource accepts the following input properties:
- Endpoint string
- Endpoint to send data to. The contents vary with the protocol. See details below.
- Protocol string
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - Topic string | string
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- Confirmation
Timeout intIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - Delivery
Policy string - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- Endpoint
Auto boolConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - Filter
Policy string - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- Filter
Policy stringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - Raw
Message boolDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - Redrive
Policy string - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- Replay
Policy string - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- Subscription
Role stringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- Endpoint string
- Endpoint to send data to. The contents vary with the protocol. See details below.
- Protocol string
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - Topic string | string
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- Confirmation
Timeout intIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - Delivery
Policy string - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- Endpoint
Auto boolConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - Filter
Policy string - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- Filter
Policy stringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - Raw
Message boolDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - Redrive
Policy string - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- Replay
Policy string - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- Subscription
Role stringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- endpoint String
- Endpoint to send data to. The contents vary with the protocol. See details below.
- protocol String
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - topic String | String
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- confirmation
Timeout IntegerIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - delivery
Policy String - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint
Auto BooleanConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter
Policy String - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter
Policy StringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - raw
Message BooleanDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive
Policy String - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay
Policy String - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription
Role StringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- endpoint string
- Endpoint to send data to. The contents vary with the protocol. See details below.
- protocol string
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - topic string | Topic
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- confirmation
Timeout numberIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - delivery
Policy string - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint
Auto booleanConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter
Policy string - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter
Policy stringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - raw
Message booleanDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive
Policy string - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay
Policy string - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription
Role stringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- endpoint str
- Endpoint to send data to. The contents vary with the protocol. See details below.
- protocol str
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - topic str | str
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- confirmation_
timeout_ intin_ minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - delivery_
policy str - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint_
auto_ boolconfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter_
policy str - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter_
policy_ strscope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - raw_
message_ booldelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive_
policy str - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay_
policy str - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription_
role_ strarn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- endpoint String
- Endpoint to send data to. The contents vary with the protocol. See details below.
- protocol String
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - topic String |
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- confirmation
Timeout NumberIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - delivery
Policy String - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint
Auto BooleanConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter
Policy String - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter
Policy StringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - raw
Message BooleanDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive
Policy String - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay
Policy String - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription
Role StringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
Outputs
All input properties are implicitly available as output properties. Additionally, the TopicSubscription resource produces the following output properties:
- Arn string
- ARN of the subscription.
- Confirmation
Was boolAuthenticated - Whether the subscription confirmation request was authenticated.
- Id string
- The provider-assigned unique ID for this managed resource.
- Owner
Id string - AWS account ID of the subscription's owner.
- Pending
Confirmation bool - Whether the subscription has not been confirmed.
- Arn string
- ARN of the subscription.
- Confirmation
Was boolAuthenticated - Whether the subscription confirmation request was authenticated.
- Id string
- The provider-assigned unique ID for this managed resource.
- Owner
Id string - AWS account ID of the subscription's owner.
- Pending
Confirmation bool - Whether the subscription has not been confirmed.
- arn String
- ARN of the subscription.
- confirmation
Was BooleanAuthenticated - Whether the subscription confirmation request was authenticated.
- id String
- The provider-assigned unique ID for this managed resource.
- owner
Id String - AWS account ID of the subscription's owner.
- pending
Confirmation Boolean - Whether the subscription has not been confirmed.
- arn string
- ARN of the subscription.
- confirmation
Was booleanAuthenticated - Whether the subscription confirmation request was authenticated.
- id string
- The provider-assigned unique ID for this managed resource.
- owner
Id string - AWS account ID of the subscription's owner.
- pending
Confirmation boolean - Whether the subscription has not been confirmed.
- arn str
- ARN of the subscription.
- confirmation_
was_ boolauthenticated - Whether the subscription confirmation request was authenticated.
- id str
- The provider-assigned unique ID for this managed resource.
- owner_
id str - AWS account ID of the subscription's owner.
- pending_
confirmation bool - Whether the subscription has not been confirmed.
- arn String
- ARN of the subscription.
- confirmation
Was BooleanAuthenticated - Whether the subscription confirmation request was authenticated.
- id String
- The provider-assigned unique ID for this managed resource.
- owner
Id String - AWS account ID of the subscription's owner.
- pending
Confirmation Boolean - Whether the subscription has not been confirmed.
Look up Existing TopicSubscription Resource
Get an existing TopicSubscription resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: TopicSubscriptionState, opts?: CustomResourceOptions): TopicSubscription
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
arn: Optional[str] = None,
confirmation_timeout_in_minutes: Optional[int] = None,
confirmation_was_authenticated: Optional[bool] = None,
delivery_policy: Optional[str] = None,
endpoint: Optional[str] = None,
endpoint_auto_confirms: Optional[bool] = None,
filter_policy: Optional[str] = None,
filter_policy_scope: Optional[str] = None,
owner_id: Optional[str] = None,
pending_confirmation: Optional[bool] = None,
protocol: Optional[str] = None,
raw_message_delivery: Optional[bool] = None,
redrive_policy: Optional[str] = None,
replay_policy: Optional[str] = None,
subscription_role_arn: Optional[str] = None,
topic: Optional[str] = None) -> TopicSubscription
func GetTopicSubscription(ctx *Context, name string, id IDInput, state *TopicSubscriptionState, opts ...ResourceOption) (*TopicSubscription, error)
public static TopicSubscription Get(string name, Input<string> id, TopicSubscriptionState? state, CustomResourceOptions? opts = null)
public static TopicSubscription get(String name, Output<String> id, TopicSubscriptionState state, CustomResourceOptions options)
resources: _: type: aws:sns:TopicSubscription get: id: ${id}
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Arn string
- ARN of the subscription.
- Confirmation
Timeout intIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - Confirmation
Was boolAuthenticated - Whether the subscription confirmation request was authenticated.
- Delivery
Policy string - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- Endpoint string
- Endpoint to send data to. The contents vary with the protocol. See details below.
- Endpoint
Auto boolConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - Filter
Policy string - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- Filter
Policy stringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - Owner
Id string - AWS account ID of the subscription's owner.
- Pending
Confirmation bool - Whether the subscription has not been confirmed.
- Protocol string
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - Raw
Message boolDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - Redrive
Policy string - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- Replay
Policy string - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- Subscription
Role stringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- Topic string | string
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- Arn string
- ARN of the subscription.
- Confirmation
Timeout intIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - Confirmation
Was boolAuthenticated - Whether the subscription confirmation request was authenticated.
- Delivery
Policy string - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- Endpoint string
- Endpoint to send data to. The contents vary with the protocol. See details below.
- Endpoint
Auto boolConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - Filter
Policy string - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- Filter
Policy stringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - Owner
Id string - AWS account ID of the subscription's owner.
- Pending
Confirmation bool - Whether the subscription has not been confirmed.
- Protocol string
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - Raw
Message boolDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - Redrive
Policy string - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- Replay
Policy string - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- Subscription
Role stringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- Topic string | string
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- arn String
- ARN of the subscription.
- confirmation
Timeout IntegerIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - confirmation
Was BooleanAuthenticated - Whether the subscription confirmation request was authenticated.
- delivery
Policy String - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint String
- Endpoint to send data to. The contents vary with the protocol. See details below.
- endpoint
Auto BooleanConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter
Policy String - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter
Policy StringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - owner
Id String - AWS account ID of the subscription's owner.
- pending
Confirmation Boolean - Whether the subscription has not been confirmed.
- protocol String
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - raw
Message BooleanDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive
Policy String - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay
Policy String - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription
Role StringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- topic String | String
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- arn string
- ARN of the subscription.
- confirmation
Timeout numberIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - confirmation
Was booleanAuthenticated - Whether the subscription confirmation request was authenticated.
- delivery
Policy string - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint string
- Endpoint to send data to. The contents vary with the protocol. See details below.
- endpoint
Auto booleanConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter
Policy string - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter
Policy stringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - owner
Id string - AWS account ID of the subscription's owner.
- pending
Confirmation boolean - Whether the subscription has not been confirmed.
- protocol string
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - raw
Message booleanDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive
Policy string - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay
Policy string - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription
Role stringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- topic string | Topic
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- arn str
- ARN of the subscription.
- confirmation_
timeout_ intin_ minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - confirmation_
was_ boolauthenticated - Whether the subscription confirmation request was authenticated.
- delivery_
policy str - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint str
- Endpoint to send data to. The contents vary with the protocol. See details below.
- endpoint_
auto_ boolconfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter_
policy str - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter_
policy_ strscope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - owner_
id str - AWS account ID of the subscription's owner.
- pending_
confirmation bool - Whether the subscription has not been confirmed.
- protocol str
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - raw_
message_ booldelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive_
policy str - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay_
policy str - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription_
role_ strarn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- topic str | str
ARN of the SNS topic to subscribe to.
The following arguments are optional:
- arn String
- ARN of the subscription.
- confirmation
Timeout NumberIn Minutes - Integer indicating number of minutes to wait in retrying mode for fetching subscription arn before marking it as failure. Only applicable for http and https protocols. Default is
1
. - confirmation
Was BooleanAuthenticated - Whether the subscription confirmation request was authenticated.
- delivery
Policy String - JSON String with the delivery policy (retries, backoff, etc.) that will be used in the subscription - this only applies to HTTP/S subscriptions. Refer to the SNS docs for more details.
- endpoint String
- Endpoint to send data to. The contents vary with the protocol. See details below.
- endpoint
Auto BooleanConfirms - Whether the endpoint is capable of auto confirming subscription (e.g., PagerDuty). Default is
false
. - filter
Policy String - JSON String with the filter policy that will be used in the subscription to filter messages seen by the target resource. Refer to the SNS docs for more details.
- filter
Policy StringScope - Whether the
filter_policy
applies toMessageAttributes
(default) orMessageBody
. - owner
Id String - AWS account ID of the subscription's owner.
- pending
Confirmation Boolean - Whether the subscription has not been confirmed.
- protocol String
- Protocol to use. Valid values are:
sqs
,sms
,lambda
,firehose
, andapplication
. Protocolsemail
,email-json
,http
andhttps
are also valid but partially supported. See details below. - raw
Message BooleanDelivery - Whether to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property). Default is
false
. - redrive
Policy String - JSON String with the redrive policy that will be used in the subscription. Refer to the SNS docs for more details.
- replay
Policy String - JSON String with the archived message replay policy that will be used in the subscription. Refer to the SNS docs for more details.
- subscription
Role StringArn - ARN of the IAM role to publish to Kinesis Data Firehose delivery stream. Refer to SNS docs.
- topic String |
ARN of the SNS topic to subscribe to.
The following arguments are optional:
Import
Using pulumi import
, import SNS Topic Subscriptions using the subscription arn
. For example:
$ pulumi import aws:sns/topicSubscription:TopicSubscription user_updates_sqs_target arn:aws:sns:us-west-2:123456789012:my-topic:8a21d249-4329-4871-acc6-7be709c6ea7f
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
aws
Terraform Provider.