Generate SES smtp credentials for a user and store the credentials in a SecretsManager Secret.
npm install @pepperize/cdk-ses-smtp-credentials
or
yarn add @pepperize/cdk-ses-smtp-credentials
pip install pepperize.cdk-ses-smtp-credentials
dotnet add package Pepperize.CDK.SesSmtpCredentials
<dependency>
<groupId>com.pepperize</groupId>
<artifactId>cdk-ses-smtp-credentials</artifactId>
<version>${cdkSesSmtpCredentials.version}</version>
</dependency>
npm install @pepperize/cdk-ses-smtp-credentials
See API.md.
Attaches an inline policy to the user allowing to send emails
import { User } from "@aws-cdk/aws-iam";
import { SesSmtpCredentials } from "@pepperize/cdk-ses-smtp-credentials";
const user = new User(stack, "SesUser", {
userName: "ses-user",
});
const smtpCredentials = new SesSmtpCredentials(this, "SmtpCredentials", {
user: user,
});
// smtpCredentials.secret contains json value {username: "<the generated access key id>", password: "<the calculated ses smtp password>"}
See API Reference - SesSmtpCredentials
Attaches an inline policy to the user allowing to send emails
import { User } from "@aws-cdk/aws-iam";
import { SesSmtpCredentials } from "@pepperize/cdk-ses-smtp-credentials";
const smtpCredentials = new SesSmtpCredentials(this, "SmtpCredentials", {
userName: "ses-user",
});
// smtpCredentials.secret contains json value {username: "<the generated access key id>", password: "<the calculated ses smtp password>"}
See API Reference - SesSmtpCredentials
import * as AWS from "aws-sdk";
import { calculateSesSmtpPassword } from "@pepperize/cdk-ses-smtp-credentials";
const iam = new AWS.IAM();
const accessKey = await iam
.createAccessKey({
UserName: username,
})
.promise();
const accessKeyId = accessKey.AccessKey.AccessKeyId;
const secretAccessKey = accessKey.AccessKey.SecretAccessKey;
const password = calculateSesSmtpPassword(secretAccessKey, "us-east-1");
console.log({
username: accessKeyId,
password: password,
});
See Obtaining Amazon SES SMTP credentials by converting existing AWS credentials