Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

459
Views
How to solve circular dependency between AWS resources using AWS CDK

I am creating S3, SQS, and KMS resources using aws cdk. I enabled encryption on the S3 and SQS resources. When I enabled the notification from S3 to SQS, I am getting a circular dependency error. When I remove the KMS settings from my code, it works.

GitHub repo: https://github.com/techcoderunner/s3-sqs-kms-sample

from aws_cdk import aws_kms as kms
from aws_cdk import aws_s3 as s3
from aws_cdk import aws_sqs as sqs
from aws_cdk import aws_s3_notifications as s3notif

kms_key = kms.Key(self, 'ssl_s3_sqs_kms_key',
    alias='sslS3SqsKmsKey',
    description='This is kms key',
    enabled=True,
    enable_key_rotation=True,
    policy=kms_policy_document,
)

# Create the S3 bucket
bucket = s3.Bucket(
    self, "ssl_s3_bucket_raw_kms",
    bucket_name="ssl-s3-bucket-kms-raw",
    encryption=s3.BucketEncryption.KMS,
    encryption_key=kms_key,
)

# Create the SQS queue
queue = sqs.Queue(
    self, "ssl_sqs_event_queue",
    queue_name="ssl-sqs-kms-event-queue",
    encryption=sqs.QueueEncryption.KMS,
    encryption_master_key=kms_key,
)

# Create S3 notification object which points to SQS
notification = s3notif.SqsDestination(queue)
filter1 = s3.NotificationKeyFilter(prefix="home/")

# Attach notificaton event to S3 bucket
bucket.add_event_notification(s3.EventType.OBJECT_CREATED,notification,filter1)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I opened a GitHub bug report for this.

It looks like the root problem is that the following condition is added to the KMS key:

CDK output template ssls3sqskmskey83E47315.Properties.KeyPolicy.Statement[1]:

{
    "Action": [
        "kms:Decrypt",
        "kms:Encrypt",
         "kms:ReEncrypt*",
         "kms:GenerateDataKey*"
     ],
     "Condition": {
        "ArnLike": {
            "aws:SourceArn": {
                "Fn::GetAtt": [
                    "ssls3bucketrawkms4B1E1122",
                    "Arn"
                 ]
             }
         }
     },
},

The S3 bucket depends on the KMS key for encryption, and the KMS key has a condition that depends on the S3 bucket.

Workaround

I was able to deploy the stack after using escape hatches to delete the condition:

# Delete the circular reference
cfn_kms_key = kms_key.node.default_child
cfn_kms_key.add_property_deletion_override("KeyPolicy.Statement.1")

workaround code available here

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!