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(cloudfront): add grantCreateInvalidation to Distribution #22575

Closed
wants to merge 3 commits into from

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Oct 20, 2022

This PR adds distributionArn attribute and grantCreateInvalidation() method to IDistribution.

  • distributionArn - returns the ARN of the distribution.
  • grantCreateInvalidation() - grants cloudfront:CreateInvalidation on the distribution.

Fixes #13159


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Oct 20, 2022

@github-actions github-actions bot added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2 labels Oct 20, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team October 20, 2022 05:35
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Oct 20, 2022
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.

@aws-cdk-automation aws-cdk-automation dismissed their stale review October 20, 2022 06:15

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

@TheRealAmazonKendra TheRealAmazonKendra changed the title feat(aws-cloudfront): add grantCreateInvalidation to Distribution feat(cloudfront): add grantCreateInvalidation to Distribution Oct 21, 2022
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! Please see my inline comments.

/**
* Format distribution ARN from stack and distribution ID.
*/
export function formatDistributionArn(scope: Construct, distributionId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing the benefit of creating this file instead of just putting these in the distribution file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These functions are shared by distribution.ts and web-distribution.ts.

*
* @attribute
*/
readonly distributionArn: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I get why this is being added in this context. It's not included in Fn::GetAtt in the resource per https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html. How is this being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's useful when grant other than CreateInvalidation:

declare const role: iam.Role;

// before
role.addToPrincipalPolicy(new iam.PolicyStatement({
  actions: ['cloudfront:ListInvalidations'],
  // region is needed here
  resources: [this.formatArn({ service: 'cloudfront', region: '', resource: 'distribution', resourceName: dist.distributionId })],
}));

// after
role.addToPrincipalPolicy(new iam.PolicyStatement({
  actions: ['cloudfront:ListInvalidations'],
  resources: [dist.distributionArn],
}));

Can be removed if it's excessive.

@Tietew
Copy link
Contributor Author

Tietew commented Oct 31, 2022

@TheRealAmazonKendra I created an alternative PR #22709. Would you please choose which PR is approvable?
Thank you.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

2 similar comments
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@corymhall corymhall closed this Nov 29, 2022
@Tietew Tietew deleted the cf-grant-methods branch November 30, 2022 03:15
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 effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-cloudfront): Add convenience grant methods
4 participants