TopicRule class
Creates and manages an AWS IoT topic rule.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const mytopic = new aws.sns.Topic("mytopic", {name: "mytopic"});
const myerrortopic = new aws.sns.Topic("myerrortopic", {name: "myerrortopic"});
const rule = new aws.iot.TopicRule("rule", {
errorAction: {
sns: {
messageFormat: "RAW",
roleArn: role.arn,
targetArn: myerrortopic.arn,
},
},
sns: [{
messageFormat: "RAW",
roleArn: role.arn,
targetArn: mytopic.arn,
}],
name: "MyRule",
description: "Example rule",
enabled: true,
sql: "SELECT * FROM 'topic/test'",
sqlVersion: "2016-03-23",
});
const assumeRole = aws.iam.getPolicyDocument({
statements: [{
principals: [{
type: "Service",
identifiers: ["iot.amazonaws.com"],
}],
effect: "Allow",
actions: ["sts:AssumeRole"],
}],
});
const myrole = new aws.iam.Role("myrole", {
name: "myrole",
assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json),
});
const mypolicy = aws.iam.getPolicyDocumentOutput({
statements: [{
effect: "Allow",
actions: ["sns:Publish"],
resources: [mytopic.arn],
}],
});
const mypolicyRolePolicy = new aws.iam.RolePolicy("mypolicy", {
name: "mypolicy",
role: myrole.id,
policy: mypolicy.json,
});
import pulumi
import pulumi_aws as aws
mytopic = aws.sns.Topic("mytopic", name="mytopic")
myerrortopic = aws.sns.Topic("myerrortopic", name="myerrortopic")
rule = aws.iot.TopicRule("rule",
error_action={
"sns": {
"message_format": "RAW",
"role_arn": role["arn"],
"target_arn": myerrortopic.arn,
},
},
sns=[{
"message_format": "RAW",
"role_arn": role["arn"],
"target_arn": mytopic.arn,
}],
name="MyRule",
description="Example rule",
enabled=True,
sql="SELECT * FROM 'topic/test'",
sql_version="2016-03-23")
assume_role = aws.iam.get_policy_document(statements=[{
"principals": [{
"type": "Service",
"identifiers": ["iot.amazonaws.com"],
}],
"effect": "Allow",
"actions": ["sts:AssumeRole"],
}])
myrole = aws.iam.Role("myrole",
name="myrole",
assume_role_policy=assume_role.json)
mypolicy = aws.iam.get_policy_document_output(statements=[{
"effect": "Allow",
"actions": ["sns:Publish"],
"resources": [mytopic.arn],
}])
mypolicy_role_policy = aws.iam.RolePolicy("mypolicy",
name="mypolicy",
role=myrole.id,
policy=mypolicy.json)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var mytopic = new Aws.Sns.Topic("mytopic", new()
{
Name = "mytopic",
});
var myerrortopic = new Aws.Sns.Topic("myerrortopic", new()
{
Name = "myerrortopic",
});
var rule = new Aws.Iot.TopicRule("rule", new()
{
ErrorAction = new Aws.Iot.Inputs.TopicRuleErrorActionArgs
{
Sns = new Aws.Iot.Inputs.TopicRuleErrorActionSnsArgs
{
MessageFormat = "RAW",
RoleArn = role.Arn,
TargetArn = myerrortopic.Arn,
},
},
Sns = new[]
{
new Aws.Iot.Inputs.TopicRuleSnsArgs
{
MessageFormat = "RAW",
RoleArn = role.Arn,
TargetArn = mytopic.Arn,
},
},
Name = "MyRule",
Description = "Example rule",
Enabled = true,
Sql = "SELECT * FROM 'topic/test'",
SqlVersion = "2016-03-23",
});
var assumeRole = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "Service",
Identifiers = new[]
{
"iot.amazonaws.com",
},
},
},
Effect = "Allow",
Actions = new[]
{
"sts:AssumeRole",
},
},
},
});
var myrole = new Aws.Iam.Role("myrole", new()
{
Name = "myrole",
AssumeRolePolicy = assumeRole.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
var mypolicy = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Effect = "Allow",
Actions = new[]
{
"sns:Publish",
},
Resources = new[]
{
mytopic.Arn,
},
},
},
});
var mypolicyRolePolicy = new Aws.Iam.RolePolicy("mypolicy", new()
{
Name = "mypolicy",
Role = myrole.Id,
Policy = mypolicy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iot"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/sns"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
mytopic, err := sns.NewTopic(ctx, "mytopic", &sns.TopicArgs{
Name: pulumi.String("mytopic"),
})
if err != nil {
return err
}
myerrortopic, err := sns.NewTopic(ctx, "myerrortopic", &sns.TopicArgs{
Name: pulumi.String("myerrortopic"),
})
if err != nil {
return err
}
_, err = iot.NewTopicRule(ctx, "rule", &iot.TopicRuleArgs{
ErrorAction: &iot.TopicRuleErrorActionArgs{
Sns: &iot.TopicRuleErrorActionSnsArgs{
MessageFormat: pulumi.String("RAW"),
RoleArn: pulumi.Any(role.Arn),
TargetArn: myerrortopic.Arn,
},
},
Sns: iot.TopicRuleSnsArray{
&iot.TopicRuleSnsArgs{
MessageFormat: pulumi.String("RAW"),
RoleArn: pulumi.Any(role.Arn),
TargetArn: mytopic.Arn,
},
},
Name: pulumi.String("MyRule"),
Description: pulumi.String("Example rule"),
Enabled: pulumi.Bool(true),
Sql: pulumi.String("SELECT * FROM 'topic/test'"),
SqlVersion: pulumi.String("2016-03-23"),
})
if err != nil {
return err
}
assumeRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
{
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "Service",
Identifiers: []string{
"iot.amazonaws.com",
},
},
},
Effect: pulumi.StringRef("Allow"),
Actions: []string{
"sts:AssumeRole",
},
},
},
}, nil)
if err != nil {
return err
}
myrole, err := iam.NewRole(ctx, "myrole", &iam.RoleArgs{
Name: pulumi.String("myrole"),
AssumeRolePolicy: pulumi.String(assumeRole.Json),
})
if err != nil {
return err
}
mypolicy := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
Statements: iam.GetPolicyDocumentStatementArray{
&iam.GetPolicyDocumentStatementArgs{
Effect: pulumi.String("Allow"),
Actions: pulumi.StringArray{
pulumi.String("sns:Publish"),
},
Resources: pulumi.StringArray{
mytopic.Arn,
},
},
},
}, nil)
_, err = iam.NewRolePolicy(ctx, "mypolicy", &iam.RolePolicyArgs{
Name: pulumi.String("mypolicy"),
Role: myrole.ID().ToIDOutput().ToStringOutput(),
Policy: mypolicy.Json(),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
data "aws_iam_getpolicydocument" "assumeRole" {
statements {
principals {
type = "Service"
identifiers = ["iot.amazonaws.com"]
}
effect = "Allow"
actions = ["sts:AssumeRole"]
}
}
data "aws_iam_getpolicydocument" "mypolicy" {
statements {
effect = "Allow"
actions = ["sns:Publish"]
resources = [aws_sns_topic.mytopic.arn]
}
}
resource "aws_iot_topicrule" "rule" {
error_action = {
sns = {
message_format = "RAW"
role_arn = role.arn
target_arn = aws_sns_topic.myerrortopic.arn
}
}
sns {
message_format = "RAW"
role_arn = role.arn
target_arn = aws_sns_topic.mytopic.arn
}
name = "MyRule"
description = "Example rule"
enabled = true
sql = "SELECT * FROM 'topic/test'"
sql_version = "2016-03-23"
}
resource "aws_sns_topic" "mytopic" {
name = "mytopic"
}
resource "aws_sns_topic" "myerrortopic" {
name = "myerrortopic"
}
resource "aws_iam_role" "myrole" {
name = "myrole"
assume_role_policy = data.aws_iam_getpolicydocument.assumeRole.json
}
resource "aws_iam_rolepolicy" "mypolicy" {
name = "mypolicy"
role = aws_iam_role.myrole.id
policy = data.aws_iam_getpolicydocument.mypolicy.json
}
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.iot.TopicRule;
import com.pulumi.aws.iot.TopicRuleArgs;
import com.pulumi.aws.iot.inputs.TopicRuleErrorActionArgs;
import com.pulumi.aws.iot.inputs.TopicRuleErrorActionSnsArgs;
import com.pulumi.aws.iot.inputs.TopicRuleSnsArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.iam.RolePolicy;
import com.pulumi.aws.iam.RolePolicyArgs;
import java.util.ArrayList;
import java.util.Arrays;
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 mytopic = new Topic("mytopic", TopicArgs.builder()
.name("mytopic")
.build());
var myerrortopic = new Topic("myerrortopic", TopicArgs.builder()
.name("myerrortopic")
.build());
var rule = new TopicRule("rule", TopicRuleArgs.builder()
.errorAction(TopicRuleErrorActionArgs.builder()
.sns(TopicRuleErrorActionSnsArgs.builder()
.messageFormat("RAW")
.roleArn(role.arn())
.targetArn(myerrortopic.arn())
.build())
.build())
.sns(TopicRuleSnsArgs.builder()
.messageFormat("RAW")
.roleArn(role.arn())
.targetArn(mytopic.arn())
.build())
.name("MyRule")
.description("Example rule")
.enabled(true)
.sql("SELECT * FROM 'topic/test'")
.sqlVersion("2016-03-23")
.build());
final var assumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("iot.amazonaws.com")
.build())
.effect("Allow")
.actions("sts:AssumeRole")
.build())
.build());
var myrole = new Role("myrole", RoleArgs.builder()
.name("myrole")
.assumeRolePolicy(assumeRole.json())
.build());
final var mypolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.effect("Allow")
.actions("sns:Publish")
.resources(mytopic.arn())
.build())
.build());
var mypolicyRolePolicy = new RolePolicy("mypolicyRolePolicy", RolePolicyArgs.builder()
.name("mypolicy")
.role(myrole.id())
.policy(mypolicy.applyValue(_mypolicy -> _mypolicy.json()))
.build());
}
}
resources:
rule:
type: aws:iot:TopicRule
properties:
errorAction:
sns:
messageFormat: RAW
roleArn: ${role.arn}
targetArn: ${myerrortopic.arn}
sns:
- messageFormat: RAW
roleArn: ${role.arn}
targetArn: ${mytopic.arn}
name: MyRule
description: Example rule
enabled: true
sql: SELECT * FROM 'topic/test'
sqlVersion: 2016-03-23
mytopic:
type: aws:sns:Topic
properties:
name: mytopic
myerrortopic:
type: aws:sns:Topic
properties:
name: myerrortopic
myrole:
type: aws:iam:Role
properties:
name: myrole
assumeRolePolicy: ${assumeRole.json}
mypolicyRolePolicy:
type: aws:iam:RolePolicy
name: mypolicy
properties:
name: mypolicy
role: ${myrole.id}
policy: ${mypolicy.json}
variables:
assumeRole:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- principals:
- type: Service
identifiers:
- iot.amazonaws.com
effect: Allow
actions:
- sts:AssumeRole
mypolicy:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- effect: Allow
actions:
- sns:Publish
resources:
- ${mytopic.arn}
Import
Using pulumi import, import IoT Topic Rules using the name. For example:
$ pulumi import aws:iot/topicRule:TopicRule rule <name>
Constructors
- TopicRule(String name, {TopicRuleArgs? args, CustomResourceOptions? options})
-
Creates a new TopicRule.
nameThe Pulumi resource name.argsArguments used to configure this TopicRule. The set of arguments for TopicRule.optionsResource options controlling this resource's behavior. - TopicRule.reference(String urn)
- Creates a typed reference to an existing TopicRule resource.
Properties
-
arn
↔ Output<
String> -
The ARN of the topic rule
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
cloudwatchAlarms
↔ Output<
List< TopicRuleCloudwatchAlarm> ?> -
latefinal
-
cloudwatchLogs
↔ Output<
List< TopicRuleCloudwatchLog> ?> -
latefinal
-
cloudwatchMetrics
↔ Output<
List< TopicRuleCloudwatchMetric> ?> -
latefinal
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
description
↔ Output<
String?> -
The description of the rule.
latefinal
-
dynamodbs
↔ Output<
List< TopicRuleDynamodb> ?> -
latefinal
-
dynamodbv2s
↔ Output<
List< TopicRuleDynamodbv2> ?> -
latefinal
-
elasticsearch
↔ Output<
List< TopicRuleElasticsearch> ?> -
latefinal
-
enabled
↔ Output<
bool> -
Specifies whether the rule is enabled.
latefinal
-
errorAction
↔ Output<
TopicRuleErrorAction?> -
Configuration block with error action to be associated with the rule. See the documentation for
cloudwatchAlarm,cloudwatchLogs,cloudwatchMetric,dynamodb,dynamodbv2,elasticsearch,firehose,http,iotAnalytics,iotEvents,kafka,kinesis,lambda,republish,s3,sns,sqs,stepFunctions,timestreamconfiguration blocks for further configuration details.latefinal -
firehoses
↔ Output<
List< TopicRuleFirehose> ?> -
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
https
↔ Output<
List< TopicRuleHttp> ?> -
latefinal
-
id
↔ Output<
String> -
getter/setter pairinherited
-
iotAnalytics
↔ Output<
List< TopicRuleIotAnalytic> ?> -
latefinal
-
iotEvents
↔ Output<
List< TopicRuleIotEvent> ?> -
latefinal
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
kafkas
↔ Output<
List< TopicRuleKafka> ?> -
latefinal
-
kineses
↔ Output<
List< TopicRuleKinesis> ?> -
latefinal
-
lambdas
↔ Output<
List< TopicRuleLambda> ?> -
latefinal
-
name
↔ Output<
String> -
The name of the rule.
latefinal
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
republishes
↔ Output<
List< TopicRuleRepublish> ?> -
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
s3
↔ Output<
List< TopicRuleS3> ?> -
latefinal
-
sns
↔ Output<
List< TopicRuleSns> ?> -
latefinal
-
sql
↔ Output<
String> -
The SQL statement used to query the topic. For more information, see AWS IoT SQL Reference (http://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html#aws-iot-sql-reference) in the AWS IoT Developer Guide.
latefinal
-
sqlVersion
↔ Output<
String> -
The version of the SQL rules engine to use when evaluating the rule.
latefinal
-
sqs
↔ Output<
List< TopicRuleSqs> ?> -
latefinal
-
stepFunctions
↔ Output<
List< TopicRuleStepFunction> ?> -
latefinal
-
Key-value map of resource tags. If configured with a provider
defaultTagsconfiguration block present, tags with matching keys will overwrite those defined at the provider-level.latefinal -
A map of tags assigned to the resource, including those inherited from the provider
defaultTagsconfiguration block.latefinal -
timestreams
↔ Output<
List< TopicRuleTimestream> ?> -
latefinal
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited