Skip to content

Deploy via CDK

  • Node.js and npm installed
  • AWS CDK Toolkit: npm install -g aws-cdk
  • Install the required packages:
Terminal window
npm install aws-cdk-lib @serverlessinbox/mailbox @serverlessinbox/mailbox-cognito constructs
import * as cdk from 'aws-cdk-lib';
import { MailboxStack } from '../lib/stack';
const app = new cdk.App();
new MailboxStack(app, 'MailboxStack', {
env: { region: 'eu-west-1' },
});
import * as cdk from 'aws-cdk-lib';
import * as route53 from 'aws-cdk-lib/aws-route53';
import { Construct } from 'constructs';
import { MailboxUserPool } from '@serverlessinbox/mailbox-cognito';
import { Mailbox } from '@serverlessinbox/mailbox';
export class MailboxStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const domainName = 'mail.example.com';
const hostedZoneId = 'Z1D633PJN98FT9';
const hostedZone = route53.HostedZone.fromHostedZoneId(
this,
'HostedZone',
hostedZoneId,
);
const userPool = new MailboxUserPool(this, 'MailboxUserPool', {
domainName,
cognitoDomainPrefix: 'my-mailbox',
});
new Mailbox(this, 'Mailbox', {
domainName,
hostedZone,
userPool,
});
}
}

Replace domainName, hostedZoneId, and cognitoDomainPrefix with values appropriate for your deployment.

Terminal window
cdk deploy

CDK will display a summary of the IAM and security changes to be applied and prompt for confirmation before creating any resources.

After deploying, follow the post-deploy steps in Deploy via CloudFormation.