TL;DR S3 Notifications don't work with sqs.QueueEncryption.KMS_MANAGED
. Use a customer-managed key to encrypt the queue.
AWS Knowledge Base: Why aren’t Amazon S3 event notifications delivered to an Amazon SQS queue that uses server-side encryption?:
The default AWS managed KMS key can't be modified. You must use a customer managed key ... and add permissions to the KMS key to allow access to a specified service principal.
Here's a minimal working example:
// S3 Notifications to a Encrypted Queue
export class S3SqsStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
const bucket = new s3.Bucket(this, 'MyBucket', {
encryption: s3.BucketEncryption.S3_MANAGED,
});
// https://aws.amazon.com/premiumsupport/knowledge-center/sqs-s3-event-notification-sse/
const key = new kms.Key(this, 'MyCustomerKey', {
policy: new iam.PolicyDocument({
statements: [
new iam.PolicyStatement({
actions: ['kms:GenerateDataKey', 'kms:Decrypt'],
resources: ['*'], // avoid circularity by not limiting the resource
principals: [new iam.ServicePrincipal('s3.amazonaws.com')],
}),
],
}),
});
const queue = new sqs.Queue(this, 'MyQueue', {
encryption: sqs.QueueEncryption.KMS,
encryptionMasterKey: key,
});
bucket.addEventNotification(s3.EventType.OBJECT_CREATED, new s3n.SqsDestination(queue));
}
}