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(ec2): Prefixlist Constructs #24714

Closed
wants to merge 0 commits into from
Closed

Conversation

watany-dev
Copy link
Contributor

@watany-dev watany-dev commented Mar 21, 2023

I created this Construct so that I can use AWS::EC2::PrefixList quickly.

The differences from L1 are as follows:

  • If AddressFamily is not specified, ipv4 is used by default.
  • If maxEntries is not specified, the number of entries is automatically calculated from the entries array and set as maxEntries.

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

@github-actions github-actions bot added p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK labels Mar 21, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team March 21, 2023 07:14
Copy link
Contributor

@WinterYukky WinterYukky 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 opening the PR. I am commenting on this as needed to brush up on a few things.

Please note that it is currently recommended to go through the RFC to create new L2 constructs in aws-cdk, and this PR may be closed to go through the recommended flow. For more information, please see the following document
https://github.com/aws/aws-cdk/blob/main/docs/NEW_CONSTRUCTS_GUIDE.md

Comment on lines 48 to 56
/**
* The name of the prefix list.
*
* @default None
*
* @remarks
* It is not recommended to use an explicit name.
*/
readonly prefixListName?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid the customer having to specify the physical name, generate the physical name in CloudFormation or CDK (if not generated by CloudFormation) if the physical name is not passed.

example that generate in CDK:

constructor(scope: Construct, id: string, props?: PrefixListProps) {
  super(scope, id, {
    physicalName: props.prefixListName ?? Lazy.string({
      produce: () => Names.uniqueResourceName(this, { maxLength: 255, allowedSpecialCharacters: '.-_' }),     
    }),
  });
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thankyou! fixed.

Comment on lines 100 to 104
/**
* The Name of the Prefix List
*
*/
public readonly name: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

prefixListName

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

* The ARN of the Prefix List
*
*/
public readonly arn: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

prefixListArn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment on lines 150 to 163
const prefixList = new CfnPrefixList(this, 'PrefixList', {
addressFamily: props.addressFamily || AddressFamily.IP_V4,
maxEntries: props.maxEntries || props.entries!.length,
prefixListName: this.name,
entries: props.entries || [],
});

this.prefixListId = prefixList.attrPrefixListId;
this.arn = prefixList.attrArn;
this.ownerId = prefixList.attrOwnerId;
this.version = prefixList.attrVersion;
this.addressFamily = prefixList.addressFamily;

this.node.defaultChild = prefixList;
Copy link
Contributor

Choose a reason for hiding this comment

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

The ID of the resource that will be the defaultChild should be 'Resource' and do not set the defaultChild directly as in this.node.defaultChild = prefixList;.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

};
};

this.name = props?.prefixListName || id;
Copy link
Contributor

Choose a reason for hiding this comment

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

this.prefixListName = this.physicalName;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment on lines 146 to 148
if (!props?.maxEntries && !props?.entries) {
throw new Error('Set maxEntries or enrties.');
}
Copy link
Contributor

@WinterYukky WinterYukky Mar 24, 2023

Choose a reason for hiding this comment

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

What about setting maxEntry to 1 if neither is provided, I expected to be able to create it without setting anything as props is optional, but an error was thrown and I felt sad :(.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

expect(() => {
new PrefixList(stack, 'prefix-list', {
maxEntries: 100,
prefixListName: 'ThesupercalifragilisticexpialidociouswordisusedtodescribesomethingthatisextraordinarilygoodItwaspopularizedinthemovieMaryPoppinswhichwasreleasedin1964ThewordismadeupofacombinationofLatinandGreekrootsandithassincebecomeapartofpopularcultureWhileitmaybe difficulttospellitisafunwordtosayandcanbeusedtoimpressyourfriendsSothenexttimeyouwanttodescribesomethingasamazingtryusingthewordsupercalifragilisticexpialidocious',
Copy link
Contributor

Choose a reason for hiding this comment

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

It is difficult to see that the given prefixListName is more than 256 characters, so try the following.

new PrefixList(stack, 'prefix-list', {
        maxEntries: 100,
        prefixListName: 'x'.repeat(256),
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.


## Managed prefix lists

The following demonstrates how to enable [Detailed Monitoring](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html) for an EC2 instance. Keep in mind that Detailed Monitoring results in [additional charges](http://aws.amazon.com/cloudwatch/pricing/).
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is a description of detailed monitoring included?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry. This is the "original description". :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically, only capitalise the first letter of the sentence within the comment to ensure consistency in naming.

Examples:
The Id of the Prefix List => The ID of the prefix list
The OwnerId of the Prefix List => The owner ID of the prefix list
Prefix List, prefixlist => prefix list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I have fixed it as much as I could.

The following demonstrates how to enable [Detailed Monitoring](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html) for an EC2 instance. Keep in mind that Detailed Monitoring results in [additional charges](http://aws.amazon.com/cloudwatch/pricing/).

```ts
new ec2.PrefixList(stack, 'empty-prefix-list', {
Copy link
Contributor

Choose a reason for hiding this comment

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

ID should use the Pascal case (at least in this document).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@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.

@watany-dev
Copy link
Contributor Author

Thank you for the great comments that helped to resolve the issue. I have made some minor corrections. I will address the remaining comments later.

@watany-dev watany-dev requested a review from WinterYukky March 31, 2023 01:58
@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.

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.

@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to a test file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

mergify bot pushed a commit that referenced this pull request Apr 27, 2023
I accidentally broke the branch while trying to resolve conflicts #24714 . I have addressed all of the comments made by @WinterYukky who reviewed my code.

---
I created this Construct so that I can use AWS::EC2::PrefixList quickly.

The differences from L1 are as follows:

- If AddressFamily is not specified, ipv4 is used by default.
- If maxEntries is not specified, the number of entries is automatically calculated from the entries array and set as maxEntries.

----

*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
p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants