Skip to content
GitHubXDiscord

ReceiptRule

The ReceiptRule resource lets you manage AWS SES ReceiptRules for processing incoming email. Receipt rules enable you to define actions for incoming messages, such as storing them in S3, triggering Lambda functions, or sending notifications.

Create a basic receipt rule that stores incoming emails in an S3 bucket:

import AWS from "alchemy/aws/control";
const receiptRule = await AWS.SES.ReceiptRule("basicReceiptRule", {
Rule: {
Name: "StoreIncomingEmails",
Actions: [
{
S3Action: {
BucketName: "my-email-bucket",
ObjectKeyPrefix: "emails/",
}
}
],
Recipients: ["info@example.com"],
Enabled: true,
TlsPolicy: "Optional"
},
RuleSetName: "default-rule-set",
After: "previousRule" // Optional: specify a rule to place this rule after
});

Configure a receipt rule to trigger a Lambda function for processing incoming emails:

const lambdaReceiptRule = await AWS.SES.ReceiptRule("lambdaReceiptRule", {
Rule: {
Name: "ProcessIncomingEmails",
Actions: [
{
LambdaAction: {
FunctionArn: "arn:aws:lambda:us-west-2:123456789012:function:processEmail",
InvocationType: "Event"
}
}
],
Recipients: ["support@example.com"],
Enabled: true,
TlsPolicy: "Require"
},
RuleSetName: "default-rule-set"
});

Create a receipt rule that sends notifications to an Amazon SNS topic:

const snsReceiptRule = await AWS.SES.ReceiptRule("snsReceiptRule", {
Rule: {
Name: "NotifyOnIncomingEmails",
Actions: [
{
SnsAction: {
TopicArn: "arn:aws:sns:us-west-2:123456789012:EmailNotifications",
Encoding: "UTF-8"
}
}
],
Recipients: ["alerts@example.com"],
Enabled: true,
TlsPolicy: "Optional"
},
RuleSetName: "default-rule-set"
});

Demonstrate how to create a series of receipt rules that chain actions together:

const firstRule = await AWS.SES.ReceiptRule("firstRule", {
Rule: {
Name: "FirstRule",
Actions: [
{
S3Action: {
BucketName: "my-email-bucket",
ObjectKeyPrefix: "first/"
}
}
],
Recipients: ["chain@example.com"],
Enabled: true,
TlsPolicy: "Optional"
},
RuleSetName: "default-rule-set"
});
const secondRule = await AWS.SES.ReceiptRule("secondRule", {
Rule: {
Name: "SecondRule",
Actions: [
{
SnsAction: {
TopicArn: "arn:aws:sns:us-west-2:123456789012:EmailChainNotifications",
Encoding: "UTF-8"
}
}
],
Recipients: ["chain@example.com"],
Enabled: true,
TlsPolicy: "Require"
},
RuleSetName: "default-rule-set",
After: firstRule.name // Place this rule after the first rule
});