Skip to content
v2.278.0

TopicHook Class ​

Use an SNS topic as a hook target.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_autoscaling_hooktargets as autoscaling_hooktargets } from 'aws-cdk-lib';
import { aws_sns as sns } from 'aws-cdk-lib';

declare const topic: sns.Topic;
const topicHook = new autoscaling_hooktargets.TopicHook(topic);
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_autoscaling_hooktargets as autoscaling_hooktargets
from aws_cdk import aws_sns as sns

# topic: sns.Topic

topic_hook = autoscaling_hooktargets.TopicHook(topic)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.autoscaling.hooktargets.*;
import software.amazon.awscdk.services.sns.*;

Topic topic;

TopicHook topicHook = new TopicHook(topic);
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.AutoScaling.HookTargets;
using Amazon.CDK.AWS.SNS;

Topic topic;

var topicHook = new TopicHook(topic);
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var topic Topic

topicHook := awscdk.Aws_autoscaling_hooktargets.NewTopicHook(topic)

Initializer ​

ts
new TopicHook(topic: ITopic)
python
TopicHook(topic: ITopic)
java
new TopicHook(ITopic topic)
csharp
new TopicHook(ITopic topic)
go
NewTopicHook(Topic ITopic)

Methods ​

bind(_scope: Construct, options: BindHookTargetOptions): LifecycleHookTargetConfigdef bind(self, _scope: Construct, options: BindHookTargetOptions) -> LifecycleHookTargetConfigpublic LifecycleHookTargetConfig bind(Construct _scope, BindHookTargetOptions options)public LifecycleHookTargetConfig Bind(Construct _scope, BindHookTargetOptions options)func Bind(_scope Construct, Options BindHookTargetOptions) LifecycleHookTargetConfig #
If an `IRole` is found in `options`, grant it topic publishing permissions.

Otherwise, create a new IRole and grant it topic publishing permissions.

returns

Returns: the IRole with topic publishing permissions and the ARN of the topic it has publishing permission to.