class Topic (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.SNS.Topic |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awssns#Topic |
Java | software.amazon.awscdk.services.sns.Topic |
Python | aws_cdk.aws_sns.Topic |
TypeScript (source) | aws-cdk-lib » aws_sns » Topic |
Implements
IConstruct
, IDependable
, IResource
, ITopic
, INotification
A new SNS topic.
Example
import * as sns from 'aws-cdk-lib/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. |
enforce | boolean | Adds a statement to enforce encryption of data in transit when publishing to the topic. |
fifo? | boolean | Set to true to create a FIFO topic. |
logging | Logging [] | The list of delivery status logging configurations for the topic. |
master | IKey | A KMS Key, either managed by this CDK app, or imported. |
message | number | The number of days Amazon SNS retains messages. |
signature | string | The signature version corresponds to the hashing algorithm used while creating the signature of the notifications, subscription confirmations, or unsubscribe confirmation messages sent by Amazon SNS. |
topic | string | A name for the topic. |
tracing | Tracing | Tracing mode of an Amazon SNS 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.
The display name must be maximum 100 characters long, including hyphens (-), underscores (_), spaces, and tabs.
enforceSSL?
Type:
boolean
(optional, default: false)
Adds a statement to enforce encryption of data in transit when publishing to the topic.
fifo?
Type:
boolean
(optional, default: None)
Set to true to create a FIFO topic.
loggingConfigs?
Type:
Logging
[]
(optional, default: None)
The list of delivery status logging configurations for the topic.
See also: https://docs.aws.amazon.com/sns/latest/dg/sns-topic-attributes.html.
masterKey?
Type:
IKey
(optional, default: None)
A KMS Key, either managed by this CDK app, or imported.
messageRetentionPeriodInDays?
Type:
number
(optional, default: do not archive messages)
The number of days Amazon SNS retains messages.
It can only be set for FIFO topics.
See also: https://docs.aws.amazon.com/sns/latest/dg/fifo-message-archiving-replay.html
signatureVersion?
Type:
string
(optional, default: 1)
The signature version corresponds to the hashing algorithm used while creating the signature of the notifications, subscription confirmations, or unsubscribe confirmation messages sent by Amazon SNS.
See also: https://docs.aws.amazon.com/sns/latest/dg/sns-verify-signature-of-message.html.
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.
tracingConfig?
Type:
Tracing
(optional, default: TracingConfig.PASS_THROUGH)
Tracing mode of an Amazon SNS topic.
See also: https://docs.aws.amazon.com/sns/latest/dg/sns-active-tracing.html
Properties
Name | Type | Description |
---|---|---|
auto | boolean | Controls automatic creation of policy objects. |
content | boolean | Enables content-based deduplication for FIFO topics. |
env | Resource | The environment this resource belongs to. |
fifo | boolean | Whether this topic is an Amazon SNS FIFO queue. |
node | Node | The tree node. |
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.
contentBasedDeduplication
Type:
boolean
Enables content-based deduplication for FIFO topics.
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:
Node
The tree node.
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 | Adds a delivery status logging configuration to the topic. |
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. |
grant | Grant topic subscribing 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. |
static from | Import an existing SNS topic provided a topic attributes. |
LoggingConfig(config)
addpublic addLoggingConfig(config: LoggingConfig): void
Parameters
- config
Logging
Config
Adds a delivery status logging configuration to the topic.
Subscription(topicSubscription)
addpublic addSubscription(topicSubscription: ITopicSubscription): Subscription
Parameters
- topicSubscription
ITopic
Subscription
Returns
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 addToResourcePolicy
. 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.
Subscribe(grantee)
grantpublic grantSubscribe(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
Returns
Grant topic subscribing 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.
TopicAttributes(scope, id, attrs)
static frompublic static fromTopicAttributes(scope: Construct, id: string, attrs: TopicAttributes): ITopic
Parameters
- scope
Construct
— The parent creating construct. - id
string
— The construct's name. - attrs
Topic
— the attributes of the topic to import.Attributes
Returns
Import an existing SNS topic provided a topic attributes.