AWS Amplify / CDK:更新现有的 SES 电子邮件模板

AWS Amplify / CDK: Updating existing SES Email Template

我在我的放大项目中为我们使用的 SES 模板创建了自定义资源。

import { readFileSync } from 'fs';
...

    const templateHtml = readFileSync(path.resolve(__dirname, './template.html')).toString();
    const templateTxt = readFileSync(path.resolve(__dirname, './template.txt')).toString();

    const cfnTemplate = new ses.CfnTemplate(this, 'TemplateID', {
      template: {
        templateName: 'TemplateName',
        subjectPart: 'Email subject',

        htmlPart: templateHtml,
        textPart: templateTxt,
      }
    });

我现在意识到更新作为源的 HTML 文件不会更新 CDK,因此它不会尝试对模板执行任何操作。

然后我尝试将“TemplateID”更改为“TemplateIDv1”之类的东西,但这也失败了,因为......嗯,在创建资源后更改 ID 不是一个好主意......

我唯一剩下的想法是更改此自定义资源以使用 CDK 2,它添加了一个 tags 属性,这可能允许我更改资源上的某些内容以触发更新。 ..

有什么想法吗?

I'm realizing now that updating the HTML file that is the source doesn't update the CDK

这不是预期的行为。如果您修改 htmlParttextPartsubjectPart,您的 SES 模板将在您部署 Stack 时 update without interruption

it's not a good idea to change the ID after creating the resource...

确实如此。这是不必要的,会导致资源替换。

Any ideas?

问题出在您的实现上,可能是字符串从文件中加载的方式。找到 CDK 输出到 cdk.out 的 CloudFormation JSON 模板工件。当您的代码正确修改“部分”属性时,模板的 AWS::SES::Template 资源将会更改。进行更改,运行 cdk synth 并寻找差异。更改的模板将在部署时触发资源更新。