Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

❗ NOTICE (ses-actions): AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration, S3 ReceiptRule cannot be created #30143

Closed
Zetten opened this issue May 10, 2024 · 13 comments · Fixed by cdklabs/aws-cdk-notices#515
Assignees
Labels
@aws-cdk/aws-ses-actions bug This issue is a bug. effort/small Small work item – less than a day of effort management/tracking Issues that track a subject or multiple issues p0

Comments

@Zetten
Copy link

Zetten commented May 10, 2024

Please add your +1 👍 to let us know you have encountered this

Status: 'IN-PROGRESS'

Describe the bug

When calling IReceiptRuleSet. addRule with an S3 action it doesn't seem possible to deploy the rule.

Expected Behavior

The receipt rule with S3 action is added to the requested ruleset.

Current Behavior

Deployment fails with a Could not write to bucket error:

1:36:13 PM | CREATE_FAILED | AWS::SES::ReceiptRule | TestRuleSetStoreToBucketRule3E41D5CF
Could not write to bucket: reprosess3rulestack-testemailstoref58b593c-dxh45g1m3y6b (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration; Request ID: 817f5520-748b-4bae-b347-ec68df52b675; Proxy: null)

Reproduction Steps

I've created a reproducing project here: https://github.com/Zetten/repro-ses-s3-rule

The S3 bucket is set up with my project's defaults, but the error is identical without any other props, i.e. it fails even if I set no encryption, versioning, lifecycle rules.

The relevant call to addRule:

    const receiptRuleSet = ses.ReceiptRuleSet.fromReceiptRuleSetName(this, 'TestRuleSet', 'TestRuleSet');

    receiptRuleSet.addRule('StoreToBucketRule', {
      receiptRuleName: 'StoreToBucketRule',
      recipients: [props.recipient],
      actions: [
        new actions.S3({
          bucket: emailStoreBucket,
          objectKeyPrefix: 'emails/',
        }),
      ],
      enabled: true,
    });

Possible Solution

The same error is received in the AWS SES console when adding a receipt rule without having previously set up the access policy.

Therefore the problem may be related to resource ordering - the S3 BucketPolicy is perhaps not created before the ReceiptRule. I note that this sounds very similar to #3726 which was resolved some years ago. The S3 action seems to carry the required policy itself, so perhaps it's a missing dependency?

Additional Information/Context

The issue does not seem explicitly related to the use of an existing ReceiptRuleSet (i.e. ReceiptRuleSet.fromReceiptRuleSetName) - the same error is observed when creatng a new one with const receiptRuleSet = new ses.ReceiptRuleSet(this, 'StoreToBucketRuleSet');.

Additionally, manually setting a dependency as mentioned in #3726 via:

const cfnBucketPolicy = emailStoreBucket.node.findChild("Policy").node.findChild("Resource") as s3.CfnBucketPolicy;
receiptRuleSet.node.addDependency(cfnBucketPolicy);

fails due to a circular dependency (even with autoDeleteObjects: false):

Circular dependency between resources: [TestEmailStorePolicyF234249E, TestRuleSetStoreToBucketRule3E41D5CF, TestEmailStoreAutoDeleteObjectsCustomResource06AE7680]

or

Circular dependency between resources: [TestEmailStorePolicyF234249E, TestRuleSetStoreToBucketRule3E41D5CF]

CDK CLI Version

2.141.0 (build 3d1c06e)

Related Issues:

#29811

Framework Version

No response

Node.js Version

18.20.2

OS

Linux

Language

TypeScript

Language Version

TypeScript (5.4.5)

Other information

No response

@Zetten Zetten added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 10, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels May 10, 2024
@khushail khushail self-assigned this May 10, 2024
@khushail
Copy link
Contributor

Hi @Zetten , thanks for reaching out. I am able to repro this error while deploying with CDK 2.141.

But I noticed this PR caused changes in S3 policy in CDK 2.139 which might have led to the error being seen here.
So i tried deploying with CDK V2.138.0 and the deployment succeeded. Sharing the code -


    const bucket = new s3.Bucket(this, 'Bucket10061');
   
    const ruleSet = new ses.ReceiptRuleSet(this, 'RuleSet', {
      dropSpam: true,
    });

    const awsRule = ruleSet.addRule('Aws', {
      recipients: ['aws.com'],
    });

    ruleSet.addRule('StoreToBucketRule', {
      receiptRuleName: 'StoreToBucketRule',
      recipients: ['aws.com'],
      actions: [
        new actions.S3({
          bucket: bucket,
          objectKeyPrefix: 'emails/',
        }),
      ],
      enabled: true,
    });

let me know if deploying with CDK 2.138 also works for you

@khushail khushail added p2 effort/small Small work item – less than a day of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels May 10, 2024
@CZhang1997
Copy link

Hi @khushail , 2.138 does not work for me, but I found another workaround by create the bucket in somewhere else, then use

    this.incomingEmailEventBucket = Bucket.fromBucketArn(
      this,
      "incoming-email-event-bucket-arn",
      s3BucketsStack.incomingEmailEventBucket.bucketArn
    );

to apply to the S3 action

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 11, 2024
@sudoplatform-engineering

I'm seeing the same issue, rolling back to 2.138.0 addresses the issue for me. I'm creating the bucket in the same stack as my receipt rules.

I wonder if a way to inhibit automatic policy being created would help here? Or deferring whatever test that checks that S3 is able to be written to is deferred until after the bucket policy is set. Though I think this is an SES API so that might not be possible.

@khushail khushail removed their assignment May 13, 2024
@Zetten
Copy link
Author

Zetten commented May 14, 2024

Hi @khushail, thanks for the suggestion. For me downgrading to aws-cdk@2.138.0 and aws-cdk-lib@2.138.0 didn't solve the issue.

Our project adopted a slightly different workaround from @CZhang1997, although still using a separate stack - we create the ruleset and bucket, and manually create a bucket policy which allows a wildcard of receipt-rule-set/MyReceiptRuleSet/receipt-rule/*. Then the app stack can successfully provision its own rules. It's a bit clunky but it follows patterns we're using elsewhere for resource reuse.

I agree with @sudoplatform-engineering's suggestion that being able to disable the policy creation should allow other workarounds with manual dependency ordering (as well as custom policies in general), but (perhaps naively) it feels like it should be possible with the implicit creation.

@jonathanbodart
Copy link

At our side, just as for @sudoplatform-engineering , downgrading to aws-cdk-lib@2.138.0 and having the ingestion bucket in the same stack has the Receipt Rule resolved the issue.

@guckin
Copy link

guckin commented May 17, 2024

We see the same bug on our side. Downgrading to aws-cdk-lib@2.138.0 seems to resolve the issue.

@AbbadV
Copy link

AbbadV commented May 28, 2024

Seeing the same issue. I downgraded from aws-cdk-lib==2.143.0 to aws-cdk-lib==2.138.0 which seemed to fix.

@amine-mf
Copy link
Contributor

amine-mf commented May 28, 2024

Downgrading is "workaround", not a fix. It locks you on a specific version.
Looks important enough to be handled quickly IMHO.

@khushail khushail added p1 p0 and removed p2 p1 labels May 28, 2024
@shikha372 shikha372 changed the title aws-ses-actions: S3 ReceiptRule cannot be created aws-ses-actions: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration, S3 ReceiptRule cannot be created May 29, 2024
@shikha372 shikha372 changed the title aws-ses-actions: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration, S3 ReceiptRule cannot be created ❗ NOTICE aws-ses-actions: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration, S3 ReceiptRule cannot be created May 29, 2024
@shikha372 shikha372 changed the title ❗ NOTICE aws-ses-actions: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration, S3 ReceiptRule cannot be created ❗ NOTICE (ses-actions): AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration, S3 ReceiptRule cannot be created May 29, 2024
@shikha372 shikha372 self-assigned this May 29, 2024
@shikha372 shikha372 added the management/tracking Issues that track a subject or multiple issues label May 29, 2024
@shikha372 shikha372 pinned this issue May 29, 2024
shikha372 added a commit to cdklabs/aws-cdk-notices that referenced this issue May 29, 2024
shikha372 added a commit to cdklabs/aws-cdk-notices that referenced this issue May 29, 2024
shikha372 added a commit to cdklabs/aws-cdk-notices that referenced this issue May 29, 2024
paulhcsun added a commit to cdklabs/aws-cdk-notices that referenced this issue May 29, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@paulhcsun paulhcsun reopened this May 29, 2024
mergify bot pushed a commit that referenced this issue May 29, 2024
### Issue # (if applicable)

Closes #[30143](#30143).

### Reason for this change

Fix the below deployment failure
Deployment fails with a Could not write to bucket error:

1:36:13 PM | CREATE_FAILED | AWS::SES::ReceiptRule | TestRuleSetStoreToBucketRule3E41D5CF
Could not write to bucket: reprosess3rulestack-testemailstoref58b593c-dxh45g1m3y6b (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration; Request ID: 817f5520-748b-4bae-b347-ec68df52b675; Proxy: null)


This PR reverts the changes introduced in 
PR #29833


### Description of changes

This PR reverts the change that was made in CDK v2.139.0 to reduce overly broad permissions allocated to SES for the S3 receipt rule action. This resulted in deployment failure where SES is unable to write to s3 bucket.


### Description of how you validated changes

Dry-run for integration tests 

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
shikha372 added a commit that referenced this issue May 30, 2024
### Issue # (if applicable)

Closes #[30143](#30143).

### Reason for this change

Fix the below deployment failure
Deployment fails with a Could not write to bucket error:

1:36:13 PM | CREATE_FAILED | AWS::SES::ReceiptRule | TestRuleSetStoreToBucketRule3E41D5CF
Could not write to bucket: reprosess3rulestack-testemailstoref58b593c-dxh45g1m3y6b (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration; Request ID: 817f5520-748b-4bae-b347-ec68df52b675; Proxy: null)


This PR reverts the changes introduced in 
PR #29833


### Description of changes

This PR reverts the change that was made in CDK v2.139.0 to reduce overly broad permissions allocated to SES for the S3 receipt rule action. This resulted in deployment failure where SES is unable to write to s3 bucket.


### Description of how you validated changes

Dry-run for integration tests 

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@shikha372
Copy link
Contributor

shikha372 commented May 30, 2024

Update

We've merged the revert PR ( Reference here ) to fix this issue, this will be released as part of version 2.143.1. We'll be doing the patch release soon.

@shikha372
Copy link
Contributor

Closing Notes

Fix released in version https://github.com/aws/aws-cdk/releases/tag/v2.143.1

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

atanaspam pushed a commit to atanaspam/aws-cdk that referenced this issue Jun 3, 2024
…0375)

### Issue # (if applicable)

Closes #[30143](aws#30143).

### Reason for this change

Fix the below deployment failure
Deployment fails with a Could not write to bucket error:

1:36:13 PM | CREATE_FAILED | AWS::SES::ReceiptRule | TestRuleSetStoreToBucketRule3E41D5CF
Could not write to bucket: reprosess3rulestack-testemailstoref58b593c-dxh45g1m3y6b (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration; Request ID: 817f5520-748b-4bae-b347-ec68df52b675; Proxy: null)


This PR reverts the changes introduced in 
PR aws#29833


### Description of changes

This PR reverts the change that was made in CDK v2.139.0 to reduce overly broad permissions allocated to SES for the S3 receipt rule action. This resulted in deployment failure where SES is unable to write to s3 bucket.


### Description of how you validated changes

Dry-run for integration tests 

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
vdahlberg pushed a commit to vdahlberg/aws-cdk that referenced this issue Jun 10, 2024
…0375)

### Issue # (if applicable)

Closes #[30143](aws#30143).

### Reason for this change

Fix the below deployment failure
Deployment fails with a Could not write to bucket error:

1:36:13 PM | CREATE_FAILED | AWS::SES::ReceiptRule | TestRuleSetStoreToBucketRule3E41D5CF
Could not write to bucket: reprosess3rulestack-testemailstoref58b593c-dxh45g1m3y6b (Service: AmazonSimpleEmailService; Status Code: 400; Error Code: InvalidS3Configuration; Request ID: 817f5520-748b-4bae-b347-ec68df52b675; Proxy: null)


This PR reverts the changes introduced in 
PR aws#29833


### Description of changes

This PR reverts the change that was made in CDK v2.139.0 to reduce overly broad permissions allocated to SES for the S3 receipt rule action. This resulted in deployment failure where SES is unable to write to s3 bucket.


### Description of how you validated changes

Dry-run for integration tests 

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@moelasmar moelasmar unpinned this issue Jun 24, 2024
@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-ses-actions bug This issue is a bug. effort/small Small work item – less than a day of effort management/tracking Issues that track a subject or multiple issues p0
Projects
None yet
Development

Successfully merging a pull request may close this issue.