@haftahave/serverless-ses-template

中文文档
6.2.0发布于 2025/04/30MITTypeScriptES Module近 30 天下载 1.1万

Serverless template sync plugin for Amazon Simple Email Service

原始使用文档
文档目录9 节
  1. Template configuration file
  2. Plugin resolves region in the following order:
  3. Plugin resolves template configuration file path in the fol…
  4. Usage and command line options
  5. Deploy
  6. List templates
  7. Delete template
  8. Links
  9. License

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

版本与发布记录

@haftahave/serverless-ses-template 共发布 40 个版本,首次发布于 2018/09/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.2.0latest2025/04/301.5 年前
6.1.02024/01/112 年前
5.1.02024/01/112 年前
6.0.02023/09/263 年前
5.0.22023/09/263 年前
5.0.12023/09/263 年前

关于 @haftahave/serverless-ses-template 的常见问题

@haftahave/serverless-ses-template 是什么?

Serverless template sync plugin for Amazon Simple Email Service

如何安装 @haftahave/serverless-ses-template?

在项目目录运行 npm install @haftahave/serverless-ses-template,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:serverless(>=3.2.0 || >=4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@haftahave/serverless-ses-template 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@haftahave/serverless-ses-template 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@haftahave/serverless-ses-template 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.18.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@haftahave/serverless-ses-template 可以商用吗?

@haftahave/serverless-ses-template 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@haftahave/serverless-ses-template 的下载量有多少?

根据 npm 官方下载统计,@haftahave/serverless-ses-template 在 2026/10/17 – 2026/11/15 这 30 天内被下载 10,742 次,日均约 358 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@haftahave/serverless-ses-template 还在维护吗?

最新版本 6.2.0 发布于 2025/04/30(1.5 年前);至今共发布 40 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。