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
This construct creates an access key for the given user and stores the generated SMTP credentials inside a secret.
Attaches an inline policy to the user allowing to send emails
const user = User.fromUserName("ses-user-example");
const credentials = new SesSmtpCredentials(this, 'SmtpCredentials', {
user: user,
});
// smtpCredentials.secret contains json value {username: "<the generated access key id>", password: "<the calculated ses smtp password>"}
import { SesSmtpCredentials } from '@pepperize/cdk-ses-smtp-credentials'
new SesSmtpCredentials(scope: Construct, id: string, props: SesSmtpCredentialsProps)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
SesSmtpCredentialsProps |
No description. |
- Type: constructs.Construct
- Type: string
- Type: SesSmtpCredentialsProps
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
public toString(): string
Returns a string representation of this construct.
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
import { SesSmtpCredentials } from '@pepperize/cdk-ses-smtp-credentials'
SesSmtpCredentials.isConstruct(x: any)
Checks if x
is a construct.
- Type: any
Any object.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
secret |
aws-cdk-lib.aws_secretsmanager.ISecret |
The secret that contains the calculated AWS SES Smtp Credentials. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly secret: ISecret;
- Type: aws-cdk-lib.aws_secretsmanager.ISecret
The secret that contains the calculated AWS SES Smtp Credentials.
import { aws_ecs } from "aws-cdk-lib";
const containerDefinitionOptions: aws_ecs.ContainerDefinitionOptions = {
// ...
secrets: {
MAIL_USERNAME: aws_ecs.Secret.fromSecretsManager(smtpCredentials.secret, "username"),
MAIL_PASSWORD: aws_ecs.Secret.fromSecretsManager(smtpCredentials.secret, "password"),
}
}
import { SesSmtpCredentialsProps } from '@pepperize/cdk-ses-smtp-credentials'
const sesSmtpCredentialsProps: SesSmtpCredentialsProps = { ... }
Name | Type | Description |
---|---|---|
secret |
aws-cdk-lib.aws_secretsmanager.ISecret |
Optional, an SecretsManager secret to write the AWS SES Smtp credentials to. |
user |
aws-cdk-lib.aws_iam.IUser |
The user for which to create an AWS Access Key and to generate the smtp password. |
userName |
string |
Optional, a username to create a new user if no existing user is given. |
public readonly secret: ISecret;
- Type: aws-cdk-lib.aws_secretsmanager.ISecret
Optional, an SecretsManager secret to write the AWS SES Smtp credentials to.
public readonly user: IUser;
- Type: aws-cdk-lib.aws_iam.IUser
The user for which to create an AWS Access Key and to generate the smtp password.
If omitted a user will be created.
public readonly userName: string;
- Type: string
Optional, a username to create a new user if no existing user is given.
Name | Description |
---|---|
USERNAME |
The key of the username stored in the secretsmanager key/value json. |
PASSWORD |
The key of the password stored in the secretsmanager key/value json. |
The key of the username stored in the secretsmanager key/value json.
The key of the password stored in the secretsmanager key/value json.