我正在尝试弄清楚如何使用 CloudFormation 在 AWS 中自动创建多个云资源。
现在我需要包括SES(简单电子邮件服务)域的创建,但找不到文档,但我已经检查过:
AWS 在 CloudFormation 中支持 SES 吗?
CloudFormation 提供了多种内置的 Amazon SES 资源类型,但截至 2018 2020 2022 仍然缺少许多人需要的资源类型:域和电子邮件验证。
AWS::SES::EmailIdentity
(2022年中)。这个答案的其余部分不再是必要的。
之前的回答...
幸运的是,CloudFormation 能够定义您自己的自定义资源类型。我构建了
Custom::SES_Domain
和 Custom::SES_EmailIdentity
资源,旨在与其他 CloudFormation 资源良好配合。在这里获取它们:https://github.com/medmunds/aws-cfn-ses-domain。
CfnSESResources
拖入模板后,您可以像这样验证 SES 域:
Resources:
# Provision a domain with Amazon SES:
MySESDomain:
Type: Custom::SES_Domain
Properties:
ServiceToken: !GetAtt CfnSESResources.Outputs.CustomDomainIdentityArn
Domain: "example.com"
EnableSend: true
EnableReceive: false
# Then add all required DNS records for SES verification and usage:
MyRoute53RecordsForSES:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: "example.com."
RecordSets: !GetAtt MySESDomain.Route53RecordSets
完整说明位于存储库中。
Custom::SES_Domain
具有用于控制多个常见 SES 域选项的 properties,并公开可馈入 CloudFormation DNS 资源的 attributes:如上所示的标准 AWS::Route53::RecordSetGroup
资源,或通过区域文件条目的其他(外部)DNS 提供商.
不幸的是,目前不支持此功能,但谁知道 Re:Invent 2017 即将到来 ,,,
可以通过创建自定义函数、一些关于 SES 和 cloudformation 的博客来实现。
虽然目前不支持 AWS Cloudformation,但请使用 AWS SDK(例如 Node SDK)来配置所需的 SES 资源。
将自定义代码与 AWS 开发工具包和 AWS CLI 命令结合使用 CloudFormation 来配置 AWS 资源是一种常见的做法,因为根据参数、资源数量、重复次数等,每种方法都各有优势。
2022 年 10 月更新
CloudFormation 现在支持 AWS::SES::EmailIdentity 资源,它允许我们通过基础设施即代码定义域和电子邮件地址。
根据 CloudFormation 发布历史,此资源于 2022 年 6 月 30 日添加。
CloudFormation 现在提供原生 AWS::SES::EmailIdentity 资源。 (自2022年7月30日起)
以下是自动 Route53 DEKIM 设置/验证的示例:
EmailIdentity:
Type: AWS::SES::EmailIdentity
Properties:
EmailIdentity: {your.domain.com}
Route53DEKIM:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneId: {ZoneId}
RecordSets:
- Name: !GetAtt EmailIdentity.DkimDNSTokenName1
Type: CNAME
TTL: '3600'
ResourceRecords:
- !GetAtt EmailIdentity.DkimDNSTokenValue1
- Name: !GetAtt EmailIdentity.DkimDNSTokenName2
Type: CNAME
TTL: '3600'
ResourceRecords:
- !GetAtt EmailIdentity.DkimDNSTokenValue2
- Name: !GetAtt EmailIdentity.DkimDNSTokenName3
Type: CNAME
TTL: '3600'
ResourceRecords:
- !GetAtt EmailIdentity.DkimDNSTokenValue3
{your.domain.com}
和 {ZoneId}
必须进行调整。
以下是 CloudFormation 支持的 SES 资源类型的当前列表:
AWS::SES::配置集
AWS::SES::ConfigurationSetEventDestination
AWS::SES::收据过滤器
AWS::SES::收据规则
AWS::SES::收据规则集
AWS::SES::模板
不支持。但是,你可以让它由 lambda 处理。
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: >-
A simple email example
Resources:
FunctionEmailHandler:
Type: 'AWS::Serverless::Function'
Properties:
Handler: email.handler
Runtime: nodejs6.10
CodeUri: ..
Description: >-
...
Tags:
App: your app
MemorySize: 128
Timeout: 10
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 's3:GetObject'
Resource: '*'
LambdaInvokePermission:
Type: "AWS::Lambda::Permission"
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !GetAtt FunctionEmailHandler.Arn
Principal: ses.amazonaws.com
SESEmailRecievedRule:
Type: "AWS::SES::ReceiptRule"
Properties:
RuleSetName: your default rule set name
After: store-email-to-s3
Rule:
Name: email-recieved-rule
Enabled: true
Actions:
- LambdaAction:
FunctionArn: !GetAtt FunctionEmailHandler.Arn
InvocationType: Event