通过 CDK 验证 SES 电子邮件地址 [英] Verify SES email address through CDK

查看:34
本文介绍了通过 CDK 验证 SES 电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的 CDK 本身验证一个电子邮件地址,这样当我的堆栈部署到其他一些区域时,此验证会自动触发,而不是转到 AWS 控制台并手动执行.

I wan to verify an email address from my CDK itself so that when my stack is deployed tto some other regions this verification is automatically triggered, rather than going to AWS console and doing it manually.

推荐答案

您可以使用 @aws-cdk/custom-resources 中的 AwsCustomResource 来做到这一点,它看起来类似于您可以在此处找到的用于验证域的示例:自定义资源示例.

You can either do that using AwsCustomResource from @aws-cdk/custom-resources and it looks similar to the example that you can find here for validating a domain: Custom Resource Examples.

使用 TypeScript 验证电子邮件

我正在为您的用例调整此处的示例:

I'm adjusting the example here for your use case:

const verifyDomainIdentity = new AwsCustomResource(this, 'VerifyDomainIdentity', {
  onCreate: {
    service: 'SES',
    action: 'verifyEmailIdentity',
    parameters: {
      EmailAddress: 'your@example.com'
    },
    physicalResourceId: PhysicalResourceId.of('verify-email-address')
  },
  policy: AwsCustomResourcePolicy.fromSdkCalls({resources: AwsCustomResourcePolicy.ANY_RESOURCE}) // This does not work somehow with SES or maybe I did something wrong :-(
});

不幸的是,这不是开箱即用的,因为以某种方式生成的策略包含一个 email: 前缀而不是 ses: 并且您需要提供您自己的策略.但下面还有一个选择.

Unfortunately this does not work out of the box because somehow the generated policy includes an email: prefix instead of ses: and you need to provide your own policy. But there's an alternative below.

在 TypeScript 中使用现有的 CDK 结构

另一种选择是使用已经为您执行此操作的 CDK 构造.我最近遇到了和你一样的问题,为此我发布了一个 CDK 结构:ses-验证身份.然后你可以这样做:

The other alternative is to use a CDK Construct which is already doing that for you. I recently ran into the same problem like you and I've published a CDK Construct for that: ses-verify-identities. You can then do it like this:

new VerifySesEmailAddress(this, 'SesEmailVerification', {
  emailAddress: 'hello@example.org'
});

您可以找到 CDK 构造的源代码 这里 如果您有兴趣.验证域.

You can find the source code of the CDK construct here in case you are interested. The same is possible for verifying domains.

这篇关于通过 CDK 验证 SES 电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆