Skip to content

Commit

Permalink
deploy dependency and permission fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdial89f committed Jul 28, 2024
1 parent ac7f786 commit 67592ef
Showing 1 changed file with 45 additions and 30 deletions.
75 changes: 45 additions & 30 deletions lib/stacks/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export class Email extends cdk.NestedStack {
principals: [new cdk.aws_iam.ServicePrincipal("sns.amazonaws.com")],
resources: ["*"],
}),
new cdk.aws_iam.PolicyStatement({
actions: ["kms:GenerateDataKey", "kms:Decrypt"],
principals: [new cdk.aws_iam.ServicePrincipal("ses.amazonaws.com")],
resources: ["*"],
}),
],
}),
});
Expand All @@ -63,14 +68,16 @@ export class Email extends cdk.NestedStack {
});

// Allow SES to publish to the SNS topic
emailEventTopic.addToResourcePolicy(
new cdk.aws_iam.PolicyStatement({
actions: ["sns:Publish"],
principals: [new cdk.aws_iam.ServicePrincipal("ses.amazonaws.com")],
resources: [emailEventTopic.topicArn],
effect: cdk.aws_iam.Effect.ALLOW,
}),
);
const snsPublishPolicyStatement = new cdk.aws_iam.PolicyStatement({
actions: ["sns:Publish"],
principals: [new cdk.aws_iam.ServicePrincipal("ses.amazonaws.com")],
resources: [emailEventTopic.topicArn],
effect: cdk.aws_iam.Effect.ALLOW,
});
emailEventTopic.addToResourcePolicy(snsPublishPolicyStatement);
const snsTopicPolicy = emailEventTopic.node.tryFindChild(
"Policy",
) as cdk.CfnResource;

// S3 Bucket for storing email event data
const emailDataBucket = new cdk.aws_s3.Bucket(this, "EmailDataBucket", {
Expand All @@ -97,29 +104,32 @@ export class Email extends cdk.NestedStack {
);

// SES Event Destination for Configuration Set
new cdk.aws_ses.CfnConfigurationSetEventDestination(
this,
"ConfigurationSetEventDestination",
{
configurationSetName: configurationSet.name!,
eventDestination: {
enabled: true,
matchingEventTypes: [
"send",
"reject",
"bounce",
"complaint",
"delivery",
"open",
"click",
"renderingFailure",
],
snsDestination: {
topicArn: emailEventTopic.topicArn,
const eventDestination =
new cdk.aws_ses.CfnConfigurationSetEventDestination(
this,
"ConfigurationSetEventDestination",
{
configurationSetName: configurationSet.name!,
eventDestination: {
enabled: true,
matchingEventTypes: [
"send",
"reject",
"bounce",
"complaint",
"delivery",
"open",
"click",
"renderingFailure",
],
snsDestination: {
topicArn: emailEventTopic.topicArn,
},
},
},
},
);
);

eventDestination.node.addDependency(snsTopicPolicy);

// SES Email Identity
const emailIdentity = new cdk.aws_ses.CfnEmailIdentity(
Expand Down Expand Up @@ -160,6 +170,11 @@ export class Email extends cdk.NestedStack {
],
resources: ["*"],
}),
new cdk.aws_iam.PolicyStatement({
effect: cdk.aws_iam.Effect.ALLOW,
actions: ["ec2:DescribeSecurityGroups", "ec2:DescribeVpcs"],
resources: ["*"],
}),
],
}),
},
Expand Down Expand Up @@ -210,7 +225,7 @@ export class Email extends cdk.NestedStack {
},
functionName: processEmailsLambda.functionArn,
sourceAccessConfigurations: [
...privateSubnets.map((subnet) => ({
...privateSubnets.slice(0, 3).map((subnet) => ({
type: "VPC_SUBNET",
uri: subnet.subnetId,
})),
Expand Down

0 comments on commit 67592ef

Please sign in to comment.