Skip to content
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

feat(ses): grant methods to IEmailIdentity #29084

Merged
merged 9 commits into from
Feb 13, 2024

Conversation

karaken12
Copy link
Contributor

Issue

Closes #29083

Reason for this change

When granting send email access to a lambda the grant needs to be constructed manually, including constructing the ARN for the identity. e.g.

  Grant.addToPrincipal({
    grantee,
    actions: ["ses:SendEmail"],
    resourceArns: [
      this.stack.formatArn({
        service: 'ses',
        resource: 'identity',
        resourceName: 'test@example.com',
      }),
    ],
    scope: this
  })

This is dissimilar to other constructs, which generally expose a grant method and one or more convenience methods for particularly relevant groups of actions.

Description of changes

Added grant and grantSendEmail to IEmailIdentity, and added a common abstract class, BaseEmailIdentity with the relevant grant code. This is to avoid code duplication between the full EmailIdentity and the Import class.

Description of how you validated changes

Tests added for grants on both new and imported email identities, and a test to validate the grantSendEmail method.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Also introduce an abstract base class to avoid duplication between
imported email identities.
@github-actions github-actions bot added feature-request A feature should be added or improved. p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Feb 12, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team February 12, 2024 16:06
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@kaizencc kaizencc changed the title feat(ses): add grant methods to IEmailIdentity feat(ses): grant methods to IEmailIdentity Feb 12, 2024
@kaizencc kaizencc added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Feb 12, 2024
kaizencc
kaizencc previously approved these changes Feb 12, 2024
Copy link
Contributor

@kaizencc kaizencc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @karaken12, this looks good!

@aws-cdk-automation aws-cdk-automation dismissed their stale review February 12, 2024 22:31

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@karaken12
Copy link
Contributor Author

Thanks @karaken12, this looks good!

Great, thanks! I can still add an integration test if you want?

It made sense to do so, and adding the `@attribute` fixes a lint error.
@mergify mergify bot dismissed kaizencc’s stale review February 13, 2024 10:14

Pull request has been modified.

This matches built in AWS policies, such as
AmazonCognitoIdpEmailServiceRolePolicy.
@karaken12
Copy link
Contributor Author

Updated an integration test (as the bot requested!), corrected a documentation error, and updated the list of actions in the grantSendEmail convenience method.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 9162ae7
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented Feb 13, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit c3c771c into aws:main Feb 13, 2024
10 checks passed
@karaken12 karaken12 deleted the email-identity-grants branch February 13, 2024 16:28
GavinZZ pushed a commit that referenced this pull request Feb 22, 2024
### Issue

Closes #29083

### Reason for this change

When granting send email access to a lambda the grant needs to be constructed manually, including constructing the ARN for the identity. e.g.

```
  Grant.addToPrincipal({
    grantee,
    actions: ["ses:SendEmail"],
    resourceArns: [
      this.stack.formatArn({
        service: 'ses',
        resource: 'identity',
        resourceName: 'test@example.com',
      }),
    ],
    scope: this
  })
```

This is dissimilar to other constructs, which generally expose a grant method and one or more convenience methods for particularly relevant groups of actions.

### Description of changes

Added `grant` and `grantSendEmail` to `IEmailIdentity`, and added a common abstract class, `BaseEmailIdentity` with the relevant grant code. This is to avoid code duplication between the full `EmailIdentity` and the `Import` class.

### Description of how you validated changes

Tests added for grants on both new and imported email identities, and a test to validate the `grantSendEmail` method.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK feature-request A feature should be added or improved. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-ses: add grant methods to EmailIdentity
3 participants