Skip to content

feat(ses): add fromEmailIdentityArn #33984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/aws-cdk-lib/aws-ses/lib/email-identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CfnEmailIdentity } from './ses.generated';
import { Grant, IGrantable } from '../../aws-iam';
import { IPublicHostedZone } from '../../aws-route53';
import * as route53 from '../../aws-route53';
import { IResource, Lazy, Resource, SecretValue, Stack } from '../../core';
import { ArnFormat, IResource, Lazy, Resource, SecretValue, Stack } from '../../core';
import { addConstructMetadata } from '../../core/lib/metadata-resource';

/**
Expand Down Expand Up @@ -399,6 +399,27 @@ export class EmailIdentity extends EmailIdentityBase {
return new Import(scope, id);
}

/**
* Import an email identity by ARN
*/
public static fromEmailIdentityArn(scope: Construct, id: string, emailIdentityArn: string): IEmailIdentity {
// emailIdentityArn is in the format 'arn:aws:ses:{region}:{account}:identity/{name}'
const stack = Stack.of(scope);
const parsedArn = stack.splitArn(emailIdentityArn, ArnFormat.SLASH_RESOURCE_NAME);

if (parsedArn.service !== 'ses' || parsedArn.resource !== 'identity' || !parsedArn.resourceName) {
throw new Error(`Invalid email identity ARN: ${emailIdentityArn}`);
}

const emailIdentityName = parsedArn.resourceName;

class Import extends EmailIdentityBase {
public readonly emailIdentityName = emailIdentityName;
public readonly emailIdentityArn = emailIdentityArn;
}
return new Import(scope, id);
}

public readonly emailIdentityName: string;

public readonly emailIdentityArn: string;
Expand Down
12 changes: 12 additions & 0 deletions packages/aws-cdk-lib/aws-ses/test/email-identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ test('with mail from and hosted zone', () => {
});
});

describe('import', () => {
test('import email identity by ARN works correctly', () => {
const emailIdentity = EmailIdentity.fromEmailIdentityArn(stack, 'Identity', 'arn:aws:ses:us-west-2:123456789012:identity/cdk.dev');
expect(emailIdentity.emailIdentityName).toEqual('cdk.dev');
expect(emailIdentity.emailIdentityArn).toEqual('arn:aws:ses:us-west-2:123456789012:identity/cdk.dev');
});

test('import email identity by ARN fails with invalid ARN', () => {
expect(() => EmailIdentity.fromEmailIdentityArn(stack, 'Identity', 'arn:aws:s3:us-west-2:123456789012:bucket/cdk.dev')).toThrow();
});
});

describe('grants', () => {
test('grant on a domain identity', () => {
// GIVEN
Expand Down
Loading