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

fix: (aws-ec2): fix vpc endpoint incorrect issue in China region #16139

Merged
merged 15 commits into from Aug 24, 2021

Conversation

readybuilderone
Copy link
Contributor

@readybuilderone readybuilderone commented Aug 20, 2021

fix:(aws-ec2): fix vpc endpoint incorrect issue in China region

This PR fix the issue that can't create interface vpc endpoint for 40+ services like ecr, ec2, athena etc

Closes: #9864


Considerations

  1. In cn-north-1 region, there are:
  1. in cn-northwest-1 region, there are:

So, In cn-north-1 and cn-northwest-1, the vpc endpoint prefix is both region and service related.

At first, I found the vpc endpoint prefix could be fetched via AWS API , however the javascript sdk supports only asynchronous call, currently I didn't find any pattern in CDK to make live calls in object construction. Since the exception rules won't ever change ( only be added to), and the rate of change should be small in the grand scheme, I just kept the exception prefix lists in a map as fact data.

Known Issues

Since the interface vpc endpoints prefixs are not region agnostic, it requires to set the {region} in the environment to create stacks in cn-north-1, and cn-northwest-1. The methods could be found in the offical guide.

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 Aug 20, 2021

@mergify
Copy link
Contributor

mergify bot commented Aug 20, 2021

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@readybuilderone readybuilderone changed the title fix:(aws-ec2): fix vpc endpoint incorrect issue in China region fix: (aws-ec2): fix vpc endpoint incorrect issue in China region Aug 20, 2021
@@ -326,9 +326,32 @@ export class InterfaceVpcEndpointAwsService implements IInterfaceVpcEndpointServ
const region = Lazy.uncachedString({
produce: (context) => Stack.of(context.scope).region,
});
this.name = `${prefix || 'com.amazonaws'}.${region}.${name}`;
const regionPrefix =Lazy.uncachedString({
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const regionPrefix =Lazy.uncachedString({
const defaultEndpointPrefix =Lazy.uncachedString({

How about just call it defaultEndpointPrefix ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @pahud, that's a good suggestion, I'll update it.

Comment on lines 346 to 347
'cn-north-1': ['application-autoscaling', 'athena', 'autoscaling', 'awsconnector', 'cassandra', 'cloudformation', 'codedeploy-commands-secure', 'databrew', 'dms', 'ebs', 'ec2', 'ecr.api', 'ecr.dkr', 'elasticbeanstalk', 'elasticfilesystem', 'elasticfilesystem-fips', 'execute-api', 'imagebuilder', 'iotsitewise.api', 'iotsitewise.data', 'kinesis-streams', 'lambda', 'license-manager', 'monitoring', 'rds', 'redshift', 'redshift-data', 's3', 'sagemaker.api', 'sagemaker.featurestore-runtime', 'sagemaker.runtime', 'servicecatalog', 'sms', 'sqs', 'states', 'sts', 'synthetics', 'transcribe.cn', 'transcribestreaming', 'transfer', 'xray'],
'cn-northwest-1': ['application-autoscaling', 'athena', 'autoscaling', 'awsconnector', 'cassandra', 'cloudformation', 'codedeploy-commands-secure', 'databrew', 'dms', 'ebs', 'ec2', 'ecr.api', 'ecr.dkr', 'elasticbeanstalk', 'elasticfilesystem', 'elasticfilesystem-fips', 'execute-api', 'imagebuilder', 'kinesis-streams', 'lambda', 'license-manager', 'monitoring', 'rds', 'redshift', 'redshift-data', 's3', 'sagemaker.api', 'sagemaker.featurestore-runtime', 'sagemaker.runtime', 'servicecatalog', 'sms', 'sqs', 'states', 'sts', 'synthetics', 'transcribe.cn', 'transcribestreaming', 'transfer', 'workspaces', 'xray'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's wrap the lines to make it more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good suggestions, thanks Pahud

Comment on lines 340 to 343
/**
* Get the endpoint prefix for the service in the specified region
* because the prefix for some of the services in cn-north-1 and cn-northwest-1 are different
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add an AWS CLI sample in the doc comments showing how to get all endpoints from a region. That would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll add the AWS CLI sample to the comments

'cn-north-1': ['application-autoscaling', 'athena', 'autoscaling', 'awsconnector', 'cassandra', 'cloudformation', 'codedeploy-commands-secure', 'databrew', 'dms', 'ebs', 'ec2', 'ecr.api', 'ecr.dkr', 'elasticbeanstalk', 'elasticfilesystem', 'elasticfilesystem-fips', 'execute-api', 'imagebuilder', 'iotsitewise.api', 'iotsitewise.data', 'kinesis-streams', 'lambda', 'license-manager', 'monitoring', 'rds', 'redshift', 'redshift-data', 's3', 'sagemaker.api', 'sagemaker.featurestore-runtime', 'sagemaker.runtime', 'servicecatalog', 'sms', 'sqs', 'states', 'sts', 'synthetics', 'transcribe.cn', 'transcribestreaming', 'transfer', 'xray'],
'cn-northwest-1': ['application-autoscaling', 'athena', 'autoscaling', 'awsconnector', 'cassandra', 'cloudformation', 'codedeploy-commands-secure', 'databrew', 'dms', 'ebs', 'ec2', 'ecr.api', 'ecr.dkr', 'elasticbeanstalk', 'elasticfilesystem', 'elasticfilesystem-fips', 'execute-api', 'imagebuilder', 'kinesis-streams', 'lambda', 'license-manager', 'monitoring', 'rds', 'redshift', 'redshift-data', 's3', 'sagemaker.api', 'sagemaker.featurestore-runtime', 'sagemaker.runtime', 'servicecatalog', 'sms', 'sqs', 'states', 'sts', 'synthetics', 'transcribe.cn', 'transcribestreaming', 'transfer', 'workspaces', 'xray'],
};
if (VPC_ENDPOINT_SERVICE_EXCEPTIONS.hasOwnProperty(region) && VPC_ENDPOINT_SERVICE_EXCEPTIONS[region].includes(name)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (VPC_ENDPOINT_SERVICE_EXCEPTIONS.hasOwnProperty(region) && VPC_ENDPOINT_SERVICE_EXCEPTIONS[region].includes(name)) {
if (VPC_ENDPOINT_SERVICE_EXCEPTIONS[region] && VPC_ENDPOINT_SERVICE_EXCEPTIONS[region].includes(name)) {

I believe this should be working.

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 will be more concise, thanks Pahud for your suggestion, I'll update it

Copy link
Contributor

@pahud pahud left a comment

Choose a reason for hiding this comment

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

just some minor suggested changes.

@readybuilderone
Copy link
Contributor Author

Thanks @pahud for review my PR, I have updated my code according to your suggestions.
@njlynch can you help to assign a SDE to review my PR? Thanks.

Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

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

Thanks @readybuilderone , and thanks @pahud for the first-round review!

I think it's worth getting the transcribe edge case right before we merge this; otherwise it looks great.

packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts Outdated Show resolved Hide resolved
'elasticbeanstalk', 'elasticfilesystem', 'elasticfilesystem-fips', 'execute-api', 'imagebuilder',
'iotsitewise.api', 'iotsitewise.data', 'kinesis-streams', 'lambda', 'license-manager', 'monitoring',
'rds', 'redshift', 'redshift-data', 's3', 'sagemaker.api', 'sagemaker.featurestore-runtime',
'sagemaker.runtime', 'servicecatalog', 'sms', 'sqs', 'states', 'sts', 'synthetics', 'transcribe.cn',
Copy link
Contributor

Choose a reason for hiding this comment

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

! I think transcribe.cn is an additional edge case. Based on the data here, it looks like it's the single case of a region-specific suffix. As-is, the name input to this function will never be transcribe.cn, so the exception will never be properly picked up. I guess we could create a corresponding getDefaultEndpointSuffix with just transcribe as the exception? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, the .cn suffix should be handled for transcribe in China region.

this.name = `${prefix || defaultEndpointPrefix}.${region}.${name}${defaultEndpointSuffix}`;

I'll implement the getDefaultEndpointSuffix function and add the relative unit tests.

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 have updated my implementation and added the unit tests. Am I doing the right way? @njlynch

Co-authored-by: Nick Lynch <nlynch@amazon.com>
@mergify mergify bot dismissed njlynch’s stale review August 23, 2021 11:41

Pull request has been modified.

readybuilderone and others added 2 commits August 23, 2021 19:50
It's really a great way to use "?.includes" to check the property exist, I have learned it, thanks @njlynch!

Co-authored-by: Nick Lynch <nlynch@amazon.com>
njlynch
njlynch previously approved these changes Aug 23, 2021
Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@mergify mergify bot dismissed njlynch’s stale review August 23, 2021 14:24

Pull request has been modified.

@pahud
Copy link
Contributor

pahud commented Aug 24, 2021

Looks like there is a validate-pr waiting for approval for first-time contributor and probably need @njlynch kick it off.

@readybuilderone
Copy link
Contributor Author

Looks like there is a validate-pr waiting for approval for first-time contributor and probably need @njlynch kick it off.

Yes, this is my first PR to CDK, thanks @pahud and @njlynch so much!
I'm not quite clear about the process, so just want to confirm with @njlynch , is there anything I should do before the approval?

@mergify
Copy link
Contributor

mergify bot commented Aug 24, 2021

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

@njlynch
Copy link
Contributor

njlynch commented Aug 24, 2021

is there anything I should do before the approval?

Nope, you're good. I just had to re-click the approve button, as the review was dismissed after the merge. It's in the queue to be automatically merged now, and should be merged shortly.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 105846d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 0d0db38 into aws:master Aug 24, 2021
@mergify
Copy link
Contributor

mergify bot commented Aug 24, 2021

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

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…#16139)

fix:(aws-ec2): fix vpc endpoint incorrect issue in China region

This PR fix the issue that can't create interface vpc endpoint for 40+ services like ecr, ec2, athena etc

Closes: aws#9864


----

# Considerations 
1. In cn-north-1 region, there are:
  - 2 services whose endpoint service begin with "aws.sagemaker" prefix;
  - 41 services whose endpoint service begin with "cn.com.amazonaws" prefix;
  - 21 services whose endpoint service begin with "com.amazonaws" prefix;
    Details: https://gist.github.com/readybuilderone/d355f9f8f0f2b66379a10742b3c67cc7
2. in cn-northwest-1 region, there are:
  - 2 services whose endpoint service begin with "aws.sagemaker" prefix;
  - 44 services whose endpoint service begin with "cn.com.amazonaws" prefix;
  - 21 services whose endpoint service begin with "com.amazonaws" prefix;
    Details: https://gist.github.com/readybuilderone/a79f2c5e6fa02aae1699bf674b08be7c

So, In cn-north-1 and cn-northwest-1, the vpc endpoint prefix is both region and service related.

At first, I found the vpc endpoint prefix could be fetched via [AWS API](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpoints.html) , however  the javascript sdk supports only asynchronous call, currently I didn't find any pattern in CDK to make live calls in object construction.  Since the exception rules won't ever change ( only be added to), and the rate of change should be small in the grand scheme, I just kept the exception prefix lists  in a map as fact data. 

# Known Issues
Since the interface vpc endpoints prefixs are not region agnostic, it requires to set the {region} in the environment to create stacks in cn-north-1, and cn-northwest-1. The methods could be found in the [offical guide](https://docs.aws.amazon.com/cdk/latest/guide/environments.html).

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Sep 6, 2021
…#16139)

fix:(aws-ec2): fix vpc endpoint incorrect issue in China region

This PR fix the issue that can't create interface vpc endpoint for 40+ services like ecr, ec2, athena etc

Closes: aws#9864


----

# Considerations 
1. In cn-north-1 region, there are:
  - 2 services whose endpoint service begin with "aws.sagemaker" prefix;
  - 41 services whose endpoint service begin with "cn.com.amazonaws" prefix;
  - 21 services whose endpoint service begin with "com.amazonaws" prefix;
    Details: https://gist.github.com/readybuilderone/d355f9f8f0f2b66379a10742b3c67cc7
2. in cn-northwest-1 region, there are:
  - 2 services whose endpoint service begin with "aws.sagemaker" prefix;
  - 44 services whose endpoint service begin with "cn.com.amazonaws" prefix;
  - 21 services whose endpoint service begin with "com.amazonaws" prefix;
    Details: https://gist.github.com/readybuilderone/a79f2c5e6fa02aae1699bf674b08be7c

So, In cn-north-1 and cn-northwest-1, the vpc endpoint prefix is both region and service related.

At first, I found the vpc endpoint prefix could be fetched via [AWS API](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpoints.html) , however  the javascript sdk supports only asynchronous call, currently I didn't find any pattern in CDK to make live calls in object construction.  Since the exception rules won't ever change ( only be added to), and the rate of change should be small in the grand scheme, I just kept the exception prefix lists  in a map as fact data. 

# Known Issues
Since the interface vpc endpoints prefixs are not region agnostic, it requires to set the {region} in the environment to create stacks in cn-north-1, and cn-northwest-1. The methods could be found in the [offical guide](https://docs.aws.amazon.com/cdk/latest/guide/environments.html).

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
david-doyle-as24 pushed a commit to david-doyle-as24/aws-cdk that referenced this pull request Sep 7, 2021
…#16139)

fix:(aws-ec2): fix vpc endpoint incorrect issue in China region

This PR fix the issue that can't create interface vpc endpoint for 40+ services like ecr, ec2, athena etc

Closes: aws#9864


----

# Considerations 
1. In cn-north-1 region, there are:
  - 2 services whose endpoint service begin with "aws.sagemaker" prefix;
  - 41 services whose endpoint service begin with "cn.com.amazonaws" prefix;
  - 21 services whose endpoint service begin with "com.amazonaws" prefix;
    Details: https://gist.github.com/readybuilderone/d355f9f8f0f2b66379a10742b3c67cc7
2. in cn-northwest-1 region, there are:
  - 2 services whose endpoint service begin with "aws.sagemaker" prefix;
  - 44 services whose endpoint service begin with "cn.com.amazonaws" prefix;
  - 21 services whose endpoint service begin with "com.amazonaws" prefix;
    Details: https://gist.github.com/readybuilderone/a79f2c5e6fa02aae1699bf674b08be7c

So, In cn-north-1 and cn-northwest-1, the vpc endpoint prefix is both region and service related.

At first, I found the vpc endpoint prefix could be fetched via [AWS API](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpoints.html) , however  the javascript sdk supports only asynchronous call, currently I didn't find any pattern in CDK to make live calls in object construction.  Since the exception rules won't ever change ( only be added to), and the rate of change should be small in the grand scheme, I just kept the exception prefix lists  in a map as fact data. 

# Known Issues
Since the interface vpc endpoints prefixs are not region agnostic, it requires to set the {region} in the environment to create stacks in cn-north-1, and cn-northwest-1. The methods could be found in the [offical guide](https://docs.aws.amazon.com/cdk/latest/guide/environments.html).

*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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-ec2] Interface endpoints are incorrect in China
4 participants