Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@haftahave/serverless-ses-template

Enase13kMIT6.2.0TypeScript support: included

Serverless template sync plugin for Amazon Simple Email Service

serverless, AWS SES, Amazon Simple Email Service, plugin

readme

NPM npm Build Status slack Made in Ukraine

Stand With Ukraine

Template sync plugin for Amazon Simple Email Service

A serverless plugin that allows automatically creating, updating and removing AWS SES Templates using a configuration file and keeps your AWS SES Templates synced with your configuration file.

REQUIRES nodejs 20+


:zap: Features

  • Allows declaring email templates that will be synced in pre-deploy phase
  • Allows you to optionally add stage to template names while syncing
  • Allows you to list and delete SES template by specified name

Examples


🚨 Important Notice:

Starting from 6.x version, plugin has transitioned to pure ESM and requires serverless v3.2.0 or newer.

If you need for CJS package use 5.x plugin series

If you need compatibility with serverless<3.0.0, please use tag v4.0.7.


Installation

npm install @haftahave/serverless-ses-template

Configuration

  • All @haftahave/serverless-ses-template configuration parameters are optional
# add to your serverless.yml

plugins:
  - '@haftahave/serverless-ses-template'

custom:
  sesTemplates:
    addStage: true                             # Specifies whether to add stage to template name (default false)
    configFile: './custom-config-file/path.js' # Config file path (default './ses-email-templates/index.js')
    deployHook: 'after:deploy:deploy'          # Specifies serverless lifecycle event plugin use to deploy templates (default 'before:deploy:deploy')
    disableAutoDeploy: true                    # Specifies whether to sync templates while sls deploy and remove (default false)
    region: 'us-west-2'                        # Specifies AWS region for SES templates (not required)
    removeMissed: false                        # Set this flag in order to remove templates those are not present in your configuration file. (not required, default false)

Template configuration file

Template configuration file should be an async function that returns array of objects (all keys are required):

/**
 * @param {Object} serverless - Serverless instance
 * @param {Object} options - runtime options
 * @returns {Promise<{name: string, subject: string, html: string, text: string}[]>}
 */
const templateConfiguration = async (serverless, options) => [{
    name: 'example_name',
    subject: 'Your subject',
    html: '<h1>Hello world!</h1>',
    text: 'Hello world!',
}];

export default templateConfiguration

Real world example see here.

Plugin resolves region in the following order:

  • CLI argument named sesTemplatesRegion - top priority
  • serverless.yml plugin configuration param named region
  • CLI argument named region
  • fallback to default region resolving (first region in first stage defined in serverless.yml)

Plugin resolves template configuration file path in the following order:

  • CLI argument named sesTemplateConfig - top priority
  • serverless.yml plugin configuration param named configFile
  • fallback to default ./ses-email-templates/index.js

Usage and command line options

Deploy

Run sls ses-template deploy in order to sync your email templates.

Optional CLI options:

--sesTemplatesRegion The region used to populate your templates. Default: see "Region fallback sequence" in readme.md. [OPTIONAL]
--sesTemplateConfig  Template configuration file path. Default: see "Template configuration file sequence" in readme.md. [OPTIONAL]
--stage        The stage used to populate your templates. Default: the first stage found in your project. [OPTIONAL]
--removeMissed Set this flag in order to remove templates those are not present in your configuration file. [OPTIONAL]

List templates

Run sls ses-template list in order to list your email templates.

CLI options:

--sesTemplatesRegion The region used to list your templates. Default: see "Region fallback sequence" in readme.md. [OPTIONAL]
--filter <string>    Display templates that contain <string>. [OPTIONAL]

Delete template

Run sls ses-template delete --template template_name_goes_here in order to delete your email template.

CLI options:

--template    The template name you are going to delete [REQUIRED]
--sesTemplatesRegion The region used to populate your templates. Default: see "Region fallback sequence" in readme.md. [OPTIONAL]
--stage       The stage used to populate your templates. Default: the first stage found in your project. [OPTIONAL]

License

MIT

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[6.2.0] - 2025-04-29

Added

  • Compatibility with Serverless v4.0.0
  • Serverless v4.0.0 implementation example added

Changed

  • eslint updated to v9
  • Dependencies updated

[6.1.0] - 2024-01-10

Breaking Changes

  • Modified Autodeploy Behavior: The behavior of auto-deploy has been updated. Starting now, when the disableAutoDeploy configuration value is set to false, the plugin will automatically remove templates during the before:remove:remove serverless internal event. This change enhances stack management and helps prevent unintended template retention when executing the sls remove command to remove the AWS CloudFormation stack. #147

Changed

  • Dependencies updated

[6.0.0] - 2023-09-26

Breaking Changes

  • Migration to TypeScript: The project has been refactored using TypeScript. Learn about our motivation and the detailed changes.
  • Pure ESM Package: Plugin transitioned to a pure ESM module. If you're unfamiliar with this, please consult this guide to understand the implications.
  • Serverless Version Requirement: Ensure you are using serverless version v3.2.0 or above, as this is now the minimum supported version.

[5.1.0] - 2024-01-10

Breaking Changes

  • Modified Autodeploy Behavior: The behavior of auto-deploy has been updated. Starting now, when the disableAutoDeploy configuration value is set to false, the plugin will automatically remove templates during the before:remove:remove serverless internal event. This change enhances stack management and helps prevent unintended template retention when executing the sls remove command to remove the AWS CloudFormation stack. #147

Changed

  • Dependencies updated

[5.0.2] - 2023-09-26

Breaking Changes

[4.0.7] - 2023-06-27

Fixed

  • Resolved serverless configuration issue for plugin usage without custom node

Changed

  • Dependencies updated

Added

  • dependabot configuration

[4.0.6] - 2023-04-06

Added

  • removeMissed configuration flag

Changed

  • Dependencies updated

[4.0.5] - 2022-05-18

Fixed

[4.0.4] - 2022-04-08

Fixed

  • Display falsy values in red for cli SES

Changed

  • Dependencies updated (security vulnerabilities)

[4.0.3] - 2022-02-08

Fixed

  • Serverless ver 2 support

[4.0.2] - 2022-02-08

Fixed

  • Wrong chalk version

[4.0.1] - 2022-02-07

Added

  • Serverless SES service changes and status info added to "Service information"
  • sls info command support

Changed

  • SES API version updated to SESV2
  • Logs and messages improved

[4.0.0] - 2022-02-01

Added

  • Serverless Framework v3 support

[3.0.3] - 2021-04-15

Added

Changed

  • Dependencies updated (security vulnerabilities)

[3.0.2] - 2020-12-17

Fixed

  • Default plugin options are not initialized. Fixes #20

[3.0.1] - 2020-12-03

Improvement

  • Unnecessary files are not included in release anymore. Added files section in package.json.

Docs

[3.0.0] - 2020-12-03

Breaking Changes

  • Config definition updated
  • Dropped serverless-aws-alias plugin support

Added

  • Ability to set deploy hook
  • Config validation

Changed

  • Region verification removed

[2.0.0] - 2020-07-15

Breaking Changes

  • Drop Node.js 8 support

Changed

  • List of supported regions updated according to AWS RPS

[1.3.3] - 2020-06-10

Changed

  • List of supported regions updated according to AWS RPS

[1.3.2] - 2020-03-12

Changed

  • SES template deploy process moved to "before deploy" stage.

[1.3.1] - 2020-03-12

Added

  • Ability to disable auto deploy with sesTemplatesDisableAutoDeploy configuration flag.

Changed

  • SES template deploy process moved from "packaging" to "after deploy" stage.

[1.3.0] - 2020-02-26

Breaking Changes

Added

  • List of supported regions updated according to AWS RPS

[1.2.6] - 2019-12-16

Added

  • List of supported regions updated according to AWS RPS
  • Ability to pass template configuration file path as CLI argument named sesTemplateConfig.

[1.2.5] - 2019-10-15

Changed

[1.2.4] - 2019-09-20

Changed

  • Dependencies updated (security vulnerabilities)

[1.2.3] - 2019-07-30

Changed

  • Dependencies updated (security vulnerabilities)

[1.2.2] - 2019-06-05

Changed

  • Readme.md link fixed

[1.2.1] - 2019-06-05

Changed

  • Dependencies updated in order to get rid of npm security vulnerability warning
  • License added + readme updated

[1.2.0] - 2019-02-27

Changed

[1.1.0] - 2019-02-22

Added

[1.0.7] - 2019-02-16

Added

[1.0.6] - 2019-01-17

Changed

[1.0.5] - 2018-09-24

Changed

[1.0.4] - 2018-09-24

Changed