Recipient rule set to put emails into dynamic s3 b

2019-08-01 09:08发布

问题:

I am trying to set up amazon SES recipient rule set for putting emails into an s3 bucket. I have created an s3 bucket and I want these mails to sent into folders according to the email id. For example if an email is coming to 1@mydomain.com it should go into mytestbucket/1 and if it is coming to 2@mydomain.com it should go into mytestbucket/2.

    AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
    AmazonSimpleEmailServiceClient sesClient = new AmazonSimpleEmailServiceClient(awsCredentials);
    ;
    if (sesClient != null) {
        CreateReceiptRuleRequest req = new CreateReceiptRuleRequest();
        req.withRuleSetName(ruleSetName);
        ReceiptRule rule = new ReceiptRule();
        rule.setEnabled(true);
        rule.setName(customerIdString + "-email");
        rule.withRecipients(customerIdString + "@" + mydomain.com);
        List<ReceiptAction> actions = new ArrayList<ReceiptAction>();
        ReceiptAction action = new ReceiptAction();
        S3Action s3Action = new S3Action();
        s3Action.setBucketName(mytestbucket);
        s3Action.setObjectKeyPrefix(customerIdString);
        action.setS3Action(s3Action);
        actions.add(action);
        rule.setActions(actions);
        req.setRule(rule);
        CreateReceiptRuleResult response = sesClient.createReceiptRule(req);
        return true;
    }

Whenever I add a customer I was calling this method to create a rule to my active ruleset. But it looks like only 100 rules can be added. My usecase will be for at least 100 000. How can I achieve this?

Something I am expecting to do is

  1. Have a single recipient rule which says any email comes to mysubdomain invoke a lambda function

  2. Lambda function should put the email into subfolders of s3

回答1:

Follow these steps to achieve what you desire...

  1. Create a single SES rule to place ALL emails into a single S3 folder unsorted_emails (you can call it anything).

  2. Create a Lambda function that places emails into their proper folders.

  3. Set unsorted_emails as an event source to trigger your lambda function.

  4. Now, whenever new emails are added to unsorted_emails, your lambda function will be triggered and move the email into a proper folder.

Let me know if these steps make sense, if you have any questions, or if I can clarify more.