我最终解决了这个问题。我将在下面发布代码,但本质上这是随机配置错误和我的bucket上的Cors属性的组合。
我最终将我的角色和策略分离,并更改了一些小的格式更改。下面是我的资源和功能现在的样子。
functions:
emailReceived:
handler: emailHandler.emailReceived
events:
-
s3:
bucket: <my-bucket-name>
event: s3:ObjectCreated:*
resources:
Resources:
S3Bucket<My-bucket-name>:
Type: AWS::S3::Bucket
Properties:
CorsConfiguration:
CorsRules:
-
AllowedMethods:
- "PUT"
- "POST"
- "GET"
- "DELETE"
- "HEAD"
AllowedOrigins:
- "*"
SESWritableBucketPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: "SESWritableBucketPolicy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Sid: "AllowSESPuts"
Action: s3:PutObject
Resource: "arn:aws:s3:::<my-bucket-name>"
Condition:
StringEquals:
aws:Referer: "#{AWS::AccountId}"
Roles:
- SESWritableBucketRole
DependsOn: EmailReceivedLambdaFunction
SESWritableBucketRole:
Type: AWS::IAM::Role
Properties:
RoleName: "SESWritableBucketRole"
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: ses.amazonaws.com
Action: sts:AssumeRole
Condition:
StringEquals:
aws:Referer: "#{AWS::AccountId}"
DependsOn: SESWritableBucketPolicy
EmailReceivedRuleSet:
Type: AWS::SES::ReceiptRuleSet
Properties:
RuleSetName: "EmailReceivedRuleSet"
EmailReceivedRule:
Type: AWS::SES::ReceiptRule
Properties:
RuleSetName: "EmailReceivedRuleSet"
Rule:
Name: "EmailReceivedRule"
Enabled: true
Recipients:
- "subdomain.domain.com"
Actions:
-
S3Action:
BucketName: <my-bucket-name>
现在我们在子域上有了一个有效的接收规则。一个S3存储桶,SES可以在收到子域的任何电子邮件地址时将电子邮件上载到该存储桶。一种lambda函数,通过将对象上载到该bucket来触发。