Topic Rule Args
data class TopicRuleArgs(val cloudwatchAlarms: Output<List<TopicRuleCloudwatchAlarmArgs>>? = null, val cloudwatchLogs: Output<List<TopicRuleCloudwatchLogArgs>>? = null, val cloudwatchMetrics: Output<List<TopicRuleCloudwatchMetricArgs>>? = null, val description: Output<String>? = null, val dynamodbs: Output<List<TopicRuleDynamodbArgs>>? = null, val dynamodbv2s: Output<List<TopicRuleDynamodbv2Args>>? = null, val elasticsearch: Output<List<TopicRuleElasticsearchArgs>>? = null, val enabled: Output<Boolean>? = null, val errorAction: Output<TopicRuleErrorActionArgs>? = null, val firehoses: Output<List<TopicRuleFirehoseArgs>>? = null, val https: Output<List<TopicRuleHttpArgs>>? = null, val iotAnalytics: Output<List<TopicRuleIotAnalyticArgs>>? = null, val iotEvents: Output<List<TopicRuleIotEventArgs>>? = null, val kafkas: Output<List<TopicRuleKafkaArgs>>? = null, val kineses: Output<List<TopicRuleKinesisArgs>>? = null, val lambdas: Output<List<TopicRuleLambdaArgs>>? = null, val name: Output<String>? = null, val republishes: Output<List<TopicRuleRepublishArgs>>? = null, val s3: Output<List<TopicRuleS3Args>>? = null, val sns: Output<List<TopicRuleSnsArgs>>? = null, val sql: Output<String>? = null, val sqlVersion: Output<String>? = null, val sqs: Output<List<TopicRuleSqsArgs>>? = null, val stepFunctions: Output<List<TopicRuleStepFunctionArgs>>? = null, val tags: Output<Map<String, String>>? = null, val timestreams: Output<List<TopicRuleTimestreamArgs>>? = null) : ConvertibleToJava<TopicRuleArgs>
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", {
name: "MyRule",
description: "Example rule",
enabled: true,
sql: "SELECT * FROM 'topic/test'",
sqlVersion: "2016-03-23",
sns: [{
messageFormat: "RAW",
roleArn: role.arn,
targetArn: mytopic.arn,
}],
errorAction: {
sns: {
messageFormat: "RAW",
roleArn: role.arn,
targetArn: myerrortopic.arn,
},
},
});
const assumeRole = aws.iam.getPolicyDocument({
statements: [{
effect: "Allow",
principals: [{
type: "Service",
identifiers: ["iot.amazonaws.com"],
}],
actions: ["sts:AssumeRole"],
}],
});
const myrole = new aws.iam.Role("myrole", {
name: "myrole",
assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json),
});
const mypolicy = mytopic.arn.apply(arn => aws.iam.getPolicyDocumentOutput({
statements: [{
effect: "Allow",
actions: ["sns:Publish"],
resources: [arn],
}],
}));
const mypolicyRolePolicy = new aws.iam.RolePolicy("mypolicy", {
name: "mypolicy",
role: myrole.id,
policy: mypolicy.apply(mypolicy => mypolicy.json),
});
Content copied to clipboard
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",
name="MyRule",
description="Example rule",
enabled=True,
sql="SELECT * FROM 'topic/test'",
sql_version="2016-03-23",
sns=[{
"message_format": "RAW",
"role_arn": role["arn"],
"target_arn": mytopic.arn,
}],
error_action={
"sns": {
"message_format": "RAW",
"role_arn": role["arn"],
"target_arn": myerrortopic.arn,
},
})
assume_role = aws.iam.get_policy_document(statements=[{
"effect": "Allow",
"principals": [{
"type": "Service",
"identifiers": ["iot.amazonaws.com"],
}],
"actions": ["sts:AssumeRole"],
}])
myrole = aws.iam.Role("myrole",
name="myrole",
assume_role_policy=assume_role.json)
mypolicy = mytopic.arn.apply(lambda arn: aws.iam.get_policy_document_output(statements=[{
"effect": "Allow",
"actions": ["sns:Publish"],
"resources": [arn],
}]))
mypolicy_role_policy = aws.iam.RolePolicy("mypolicy",
name="mypolicy",
role=myrole.id,
policy=mypolicy.json)
Content copied to clipboard
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()
{
Name = "MyRule",
Description = "Example rule",
Enabled = true,
Sql = "SELECT * FROM 'topic/test'",
SqlVersion = "2016-03-23",
Sns = new[]
{
new Aws.Iot.Inputs.TopicRuleSnsArgs
{
MessageFormat = "RAW",
RoleArn = role.Arn,
TargetArn = mytopic.Arn,
},
},
ErrorAction = new Aws.Iot.Inputs.TopicRuleErrorActionArgs
{
Sns = new Aws.Iot.Inputs.TopicRuleErrorActionSnsArgs
{
MessageFormat = "RAW",
RoleArn = role.Arn,
TargetArn = myerrortopic.Arn,
},
},
});
var assumeRole = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Effect = "Allow",
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "Service",
Identifiers = new[]
{
"iot.amazonaws.com",
},
},
},
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),
});
});
Content copied to clipboard
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iot"
"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 {
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{
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"),
Sns: iot.TopicRuleSnsArray{
&iot.TopicRuleSnsArgs{
MessageFormat: pulumi.String("RAW"),
RoleArn: pulumi.Any(role.Arn),
TargetArn: mytopic.Arn,
},
},
ErrorAction: &iot.TopicRuleErrorActionArgs{
Sns: &iot.TopicRuleErrorActionSnsArgs{
MessageFormat: pulumi.String("RAW"),
RoleArn: pulumi.Any(role.Arn),
TargetArn: myerrortopic.Arn,
},
},
})
if err != nil {
return err
}
assumeRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
{
Effect: pulumi.StringRef("Allow"),
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "Service",
Identifiers: []string{
"iot.amazonaws.com",
},
},
},
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 := mytopic.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
return iam.GetPolicyDocumentResult(interface{}(iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
Statements: []iam.GetPolicyDocumentStatement{
{
Effect: "Allow",
Actions: []string{
"sns:Publish",
},
Resources: interface{}{
arn,
},
},
},
}, nil))), nil
}).(iam.GetPolicyDocumentResultOutput)
_, err = iam.NewRolePolicy(ctx, "mypolicy", &iam.RolePolicyArgs{
Name: pulumi.String("mypolicy"),
Role: myrole.ID(),
Policy: pulumi.String(mypolicy.ApplyT(func(mypolicy iam.GetPolicyDocumentResult) (*string, error) {
return &mypolicy.Json, nil
}).(pulumi.StringPtrOutput)),
})
if err != nil {
return err
}
return nil
})
}
Content copied to clipboard
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.TopicRuleSnsArgs;
import com.pulumi.aws.iot.inputs.TopicRuleErrorActionArgs;
import com.pulumi.aws.iot.inputs.TopicRuleErrorActionSnsArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
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.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 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()
.name("MyRule")
.description("Example rule")
.enabled(true)
.sql("SELECT * FROM 'topic/test'")
.sqlVersion("2016-03-23")
.sns(TopicRuleSnsArgs.builder()
.messageFormat("RAW")
.roleArn(role.arn())
.targetArn(mytopic.arn())
.build())
.errorAction(TopicRuleErrorActionArgs.builder()
.sns(TopicRuleErrorActionSnsArgs.builder()
.messageFormat("RAW")
.roleArn(role.arn())
.targetArn(myerrortopic.arn())
.build())
.build())
.build());
final var assumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.effect("Allow")
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("iot.amazonaws.com")
.build())
.actions("sts:AssumeRole")
.build())
.build());
var myrole = new Role("myrole", RoleArgs.builder()
.name("myrole")
.assumeRolePolicy(assumeRole.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.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(getPolicyDocumentResult -> getPolicyDocumentResult).applyValue(mypolicy -> mypolicy.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json())))
.build());
}
}
Content copied to clipboard
resources:
rule:
type: aws:iot:TopicRule
properties:
name: MyRule
description: Example rule
enabled: true
sql: SELECT * FROM 'topic/test'
sqlVersion: 2016-03-23
sns:
- messageFormat: RAW
roleArn: ${role.arn}
targetArn: ${mytopic.arn}
errorAction:
sns:
messageFormat: RAW
roleArn: ${role.arn}
targetArn: ${myerrortopic.arn}
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:
- effect: Allow
principals:
- type: Service
identifiers:
- iot.amazonaws.com
actions:
- sts:AssumeRole
mypolicy:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- effect: Allow
actions:
- sns:Publish
resources:
- ${mytopic.arn}
Content copied to clipboard
Import
Using pulumi import
, import IoT Topic Rules using the name
. For example:
$ pulumi import aws:iot/topicRule:TopicRule rule <name>
Content copied to clipboard
Constructors
Link copied to clipboard
constructor(cloudwatchAlarms: Output<List<TopicRuleCloudwatchAlarmArgs>>? = null, cloudwatchLogs: Output<List<TopicRuleCloudwatchLogArgs>>? = null, cloudwatchMetrics: Output<List<TopicRuleCloudwatchMetricArgs>>? = null, description: Output<String>? = null, dynamodbs: Output<List<TopicRuleDynamodbArgs>>? = null, dynamodbv2s: Output<List<TopicRuleDynamodbv2Args>>? = null, elasticsearch: Output<List<TopicRuleElasticsearchArgs>>? = null, enabled: Output<Boolean>? = null, errorAction: Output<TopicRuleErrorActionArgs>? = null, firehoses: Output<List<TopicRuleFirehoseArgs>>? = null, https: Output<List<TopicRuleHttpArgs>>? = null, iotAnalytics: Output<List<TopicRuleIotAnalyticArgs>>? = null, iotEvents: Output<List<TopicRuleIotEventArgs>>? = null, kafkas: Output<List<TopicRuleKafkaArgs>>? = null, kineses: Output<List<TopicRuleKinesisArgs>>? = null, lambdas: Output<List<TopicRuleLambdaArgs>>? = null, name: Output<String>? = null, republishes: Output<List<TopicRuleRepublishArgs>>? = null, s3: Output<List<TopicRuleS3Args>>? = null, sns: Output<List<TopicRuleSnsArgs>>? = null, sql: Output<String>? = null, sqlVersion: Output<String>? = null, sqs: Output<List<TopicRuleSqsArgs>>? = null, stepFunctions: Output<List<TopicRuleStepFunctionArgs>>? = null, tags: Output<Map<String, String>>? = null, timestreams: Output<List<TopicRuleTimestreamArgs>>? = null)
Properties
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
The description of the rule.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Configuration block with error action to be associated with the rule. See the documentation for cloudwatch_alarm
, cloudwatch_logs
, cloudwatch_metric
, dynamodb
, dynamodbv2
, elasticsearch
, firehose
, http
, iot_analytics
, iot_events
, kafka
, kinesis
, lambda
, republish
, s3
, sns
, sqs
, step_functions
, timestream
configuration blocks for further configuration details.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
The version of the SQL rules engine to use when evaluating the rule.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard