Home > Net >  AWS Amplify / CDK: Updating existing SES Email Template
AWS Amplify / CDK: Updating existing SES Email Template

Time:03-11

I created a custom resource in my amplify project for an SES template we use.

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,
      }
    });

I'm realizing now that updating the HTML file that is the source doesn't update the CDK, so it doesn't attempt to do anything with the template.

Then I tried changing the "TemplateID" to something like "TemplateIDv1", but that broke as well because ... well, it's not a good idea to change the ID after creating the resource...

The only remaining idea I have is to change this custom resource to use CDK 2, which adds a tags property that might allow me to change something on the resource to trigger an update...

Any ideas?

CodePudding user response:

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

That is not the exepected behaviour. If you modify htmlPart, textPart, or subjectPart, your SES template will update without interruption when you deploy your Stack.

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

Indeed. This is unnecessary and will result in resource replacement.

Any ideas?

The problem will be with your implementation, perhaps how the string is being loaded from the file. Find the CloudFormation JSON template artefact that CDK outputs to cdk.out. The template's AWS::SES::Template resource will change when your code is properly modifying a "part" attribute. Make a change, run cdk synth and look for diffs. A changed template will trigger a resource update on deploy.

  • Related