Skip to content
v2.274.0

Sns Class ​

Publishes the email content within a notification to Amazon SNS.

Example ​

ts
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as actions from 'aws-cdk-lib/aws-ses-actions';

const bucket = new s3.Bucket(this, 'Bucket');
const topic = new sns.Topic(this, 'Topic');

new ses.ReceiptRuleSet(this, 'RuleSet', {
  rules: [
    {
      recipients: ['hello@aws.com'],
      actions: [
        new actions.AddHeader({
          name: 'X-Special-Header',
          value: 'aws',
        }),
        new actions.S3({
          bucket,
          objectKeyPrefix: 'emails/',
          topic,
        }),
      ],
    },
    {
      recipients: ['aws.com'],
      actions: [
        new actions.Sns({
          topic,
        }),
      ],
    },
  ],
});
python
import aws_cdk.aws_s3 as s3
import aws_cdk.aws_ses_actions as actions


bucket = s3.Bucket(self, "Bucket")
topic = sns.Topic(self, "Topic")

ses.ReceiptRuleSet(self, "RuleSet",
    rules=[ses.ReceiptRuleOptions(
        recipients=["hello@aws.com"],
        actions=[
            actions.AddHeader(
                name="X-Special-Header",
                value="aws"
            ),
            actions.S3(
                bucket=bucket,
                object_key_prefix="emails/",
                topic=topic
            )
        ]
    ), ses.ReceiptRuleOptions(
        recipients=["aws.com"],
        actions=[
            actions.Sns(
                topic=topic
            )
        ]
    )
    ]
)
java
import software.amazon.awscdk.services.s3.*;
import software.amazon.awscdk.services.ses.actions.*;


Bucket bucket = new Bucket(this, "Bucket");
Topic topic = new Topic(this, "Topic");

ReceiptRuleSet.Builder.create(this, "RuleSet")
        .rules(List.of(ReceiptRuleOptions.builder()
                .recipients(List.of("hello@aws.com"))
                .actions(List.of(
                    AddHeader.Builder.create()
                            .name("X-Special-Header")
                            .value("aws")
                            .build(),
                    S3.Builder.create()
                            .bucket(bucket)
                            .objectKeyPrefix("emails/")
                            .topic(topic)
                            .build()))
                .build(), ReceiptRuleOptions.builder()
                .recipients(List.of("aws.com"))
                .actions(List.of(
                    Sns.Builder.create()
                            .topic(topic)
                            .build()))
                .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.S3;
using Amazon.CDK.AWS.SES.Actions;


var bucket = new Bucket(this, "Bucket");
var topic = new Topic(this, "Topic");

new ReceiptRuleSet(this, "RuleSet", new ReceiptRuleSetProps {
    Rules = new [] { new ReceiptRuleOptions {
        Recipients = new [] { "hello@aws.com" },
        Actions = new [] {
            new AddHeader(new AddHeaderProps {
                Name = "X-Special-Header",
                Value = "aws"
            }),
            new S3(new S3Props {
                Bucket = bucket,
                ObjectKeyPrefix = "emails/",
                Topic = topic
            }) }
    }, new ReceiptRuleOptions {
        Recipients = new [] { "aws.com" },
        Actions = new [] {
            new Sns(new SnsProps {
                Topic = topic
            }) }
    } }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import s3 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"


bucket := s3.NewBucket(this, jsii.String("Bucket"))
topic := sns.NewTopic(this, jsii.String("Topic"))

ses.NewReceiptRuleSet(this, jsii.String("RuleSet"), &ReceiptRuleSetProps{
	Rules: []ReceiptRuleOptions{
		&ReceiptRuleOptions{
			Recipients: []*string{
				jsii.String("hello@aws.com"),
			},
			Actions: []IReceiptRuleAction{
				actions.NewAddHeader(&AddHeaderProps{
					Name: jsii.String("X-Special-Header"),
					Value: jsii.String("aws"),
				}),
				actions.NewS3(&S3Props{
					Bucket: *Bucket,
					ObjectKeyPrefix: jsii.String("emails/"),
					Topic: *Topic,
				}),
			},
		},
		&ReceiptRuleOptions{
			Recipients: []*string{
				jsii.String("aws.com"),
			},
			Actions: []IReceiptRuleAction{
				actions.NewSns(&SnsProps{
					Topic: *Topic,
				}),
			},
		},
	},
})

Initializer ​

ts
new Sns(props: SnsProps)
python
Sns(props: SnsProps)
java
new Sns(SnsProps props)
csharp
new Sns(SnsProps props)
go
NewSns(Props SnsProps)

Methods ​

bind(_rule: IReceiptRuleRef): ReceiptRuleActionConfigdef bind(self, _rule: IReceiptRuleRef) -> ReceiptRuleActionConfigpublic ReceiptRuleActionConfig bind(IReceiptRuleRef _rule)public ReceiptRuleActionConfig Bind(IReceiptRuleRef _rule)func Bind(_rule IReceiptRuleRef) ReceiptRuleActionConfig#
Returns the receipt rule action specification.