class Topic (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.SNS.Topic |
Java | software.amazon.awscdk.services.sns.Topic |
Python | aws_cdk.aws_sns.Topic |
TypeScript (source) | @aws-cdk/aws-sns » Topic |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, ITopic
, INotification
A new SNS topic.
Example
import * as sns from '@aws-cdk/aws-sns';
const topic = new sns.Topic(this, 'MyTopic');
const topicRule = new iot.TopicRule(this, 'TopicRule', {
sql: iot.IotSql.fromStringAsVer20160323(
"SELECT topic(2) as device_id, year, month, day FROM 'device/+/data'",
),
actions: [
new actions.SnsTopicAction(topic, {
messageFormat: actions.SnsActionMessageFormat.JSON, // optional property, default is SnsActionMessageFormat.RAW
}),
],
});
Initializer
new Topic(scope: Construct, id: string, props?: TopicProps)
Parameters
- scope
Construct
- id
string
- props
Topic
Props
Construct Props
Name | Type | Description |
---|---|---|
content | boolean | Enables content-based deduplication for FIFO topics. |
display | string | A developer-defined string that can be used to identify this SNS topic. |
fifo? | boolean | Set to true to create a FIFO topic. |
master | IKey | A KMS Key, either managed by this CDK app, or imported. |
topic | string | A name for the topic. |
contentBasedDeduplication?
Type:
boolean
(optional, default: None)
Enables content-based deduplication for FIFO topics.
displayName?
Type:
string
(optional, default: None)
A developer-defined string that can be used to identify this SNS topic.
fifo?
Type:
boolean
(optional, default: None)
Set to true to create a FIFO topic.
masterKey?
Type:
IKey
(optional, default: None)
A KMS Key, either managed by this CDK app, or imported.
topicName?
Type:
string
(optional, default: Generated name)
A name for the topic.
If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the topic name. For more information, see Name Type.
Properties
Name | Type | Description |
---|---|---|
auto | boolean | Controls automatic creation of policy objects. |
env | Resource | The environment this resource belongs to. |
fifo | boolean | Whether this topic is an Amazon SNS FIFO queue. |
node | Construct | The construct tree node associated with this construct. |
stack | Stack | The stack in which this resource is defined. |
topic | string | The ARN of the topic. |
topic | string | The name of the topic. |
autoCreatePolicy
Type:
boolean
Controls automatic creation of policy objects.
Set by subclasses.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
fifo
Type:
boolean
Whether this topic is an Amazon SNS FIFO queue.
If false, this is a standard topic.
node
Type:
Construct
The construct tree node associated with this construct.
stack
Type:
Stack
The stack in which this resource is defined.
topicArn
Type:
string
The ARN of the topic.
topicName
Type:
string
The name of the topic.
Methods
Name | Description |
---|---|
add | Subscribe some endpoint to this topic. |
add | Adds a statement to the IAM resource policy associated with this topic. |
apply | Apply the given removal policy to this resource. |
bind | Represents a notification target That allows SNS topic to associate with this rule target. |
grant | Grant topic publishing permissions to the given identity. |
metric(metricName, props?) | Return the given named metric for this Topic. |
metric | The number of messages published to your Amazon SNS topics. |
metric | The number of messages successfully delivered from your Amazon SNS topics to subscribing endpoints. |
metric | The number of messages that Amazon SNS failed to deliver. |
metric | The number of messages that were rejected by subscription filter policies. |
metric | The number of messages that were rejected by subscription filter policies because the messages' attributes are invalid. |
metric | The number of messages that were rejected by subscription filter policies because the messages have no attributes. |
metric | Metric for the size of messages published through this topic. |
metric | The charges you have accrued since the start of the current calendar month for sending SMS messages. |
metric | The rate of successful SMS message deliveries. |
to | Returns a string representation of this construct. |
static from | Import an existing SNS topic provided an ARN. |
Subscription(subscription)
addpublic addSubscription(subscription: ITopicSubscription): void
Parameters
- subscription
ITopic
Subscription
Subscribe some endpoint to this topic.
ToResourcePolicy(statement)
addpublic addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult
Parameters
- statement
Policy
Statement
Returns
Adds a statement to the IAM resource policy associated with this topic.
If this topic was created in this stack (new Topic
), a topic policy
will be automatically created upon the first call to addToPolicy
. If
the topic is imported (Topic.import
), then this is a no-op.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
AsNotificationRuleTarget(_scope)
bindpublic bindAsNotificationRuleTarget(_scope: Construct): NotificationRuleTargetConfig
Parameters
- _scope
Construct
Returns
Represents a notification target That allows SNS topic to associate with this rule target.
Publish(grantee)
grantpublic grantPublish(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant topic publishing permissions to the given identity.
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this Topic.
NumberOfMessagesPublished(props?)
metricpublic metricNumberOfMessagesPublished(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages published to your Amazon SNS topics.
Sum over 5 minutes
NumberOfNotificationsDelivered(props?)
metricpublic metricNumberOfNotificationsDelivered(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages successfully delivered from your Amazon SNS topics to subscribing endpoints.
Sum over 5 minutes
NumberOfNotificationsFailed(props?)
metricpublic metricNumberOfNotificationsFailed(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages that Amazon SNS failed to deliver.
Sum over 5 minutes
NumberOfNotificationsFilteredOut(props?)
metricpublic metricNumberOfNotificationsFilteredOut(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages that were rejected by subscription filter policies.
Sum over 5 minutes
NumberOfNotificationsFilteredOutInvalidAttributes(props?)
metricpublic metricNumberOfNotificationsFilteredOutInvalidAttributes(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages that were rejected by subscription filter policies because the messages' attributes are invalid.
Sum over 5 minutes
NumberOfNotificationsFilteredOutNoMessageAttributes(props?)
metricpublic metricNumberOfNotificationsFilteredOutNoMessageAttributes(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages that were rejected by subscription filter policies because the messages have no attributes.
Sum over 5 minutes
PublishSize(props?)
metricpublic metricPublishSize(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
Metric for the size of messages published through this topic.
Average over 5 minutes
SMSMonthToDateSpentUSD(props?)
metricpublic metricSMSMonthToDateSpentUSD(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The charges you have accrued since the start of the current calendar month for sending SMS messages.
Maximum over 5 minutes
SMSSuccessRate(props?)
metricpublic metricSMSSuccessRate(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The rate of successful SMS message deliveries.
Sum over 5 minutes
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
TopicArn(scope, id, topicArn)
static frompublic static fromTopicArn(scope: Construct, id: string, topicArn: string): ITopic
Parameters
- scope
Construct
— The parent creating construct. - id
string
— The construct's name. - topicArn
string
— topic ARN (i.e. arn:aws:sns:us-east-2:444455556666:MyTopic).
Returns
Import an existing SNS topic provided an ARN.