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(ec2): VpcEndpoint AZ lookup fails for AWS services #8386

Merged
merged 8 commits into from
Jul 8, 2020

Conversation

flemjame-at-amazon
Copy link
Contributor

fix(ec2): VpcEndpoint AZ lookup fails for AWS services

This closes #8372

InterfaceVpcEndpointAwsService objects currently use the AWS.Region token to define the service name. This results in an unresolved string, which cannot be resolved until CloudFormation deployment time.

When using the lookupSupportedAzs functionality, a ContextProvider makes AWS calls (DescribeVpcEndpointServices) in which it passes the service name, to look up the AZs. ContextProviders cannot be given tokens. Hence, passing in an InterfaceVpcEndpointAwsService results in a synthesis-time failure.

This ticket switches InterfaceVpcEndpointAwsService from using AWS.Region to a Lazy string which resolves to the stack's region. For region-agnostic stacks, the behavior is unchanged. For stacks with a specified region, the region is resolved.

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

@flemjame-at-amazon
Copy link
Contributor Author

Any update on this?

@@ -315,7 +315,11 @@ export class InterfaceVpcEndpointAwsService implements IInterfaceVpcEndpointServ
public readonly privateDnsDefault?: boolean = true;

constructor(name: string, prefix?: string, port?: number) {
this.name = `${prefix || 'com.amazonaws'}.${Aws.REGION}.${name}`;
// this.name = `${prefix || 'com.amazonaws'}.${Aws.REGION}.${name}`;
const region = Lazy.stringValue({
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't need to be lazy. Could just be Stack.of(context.scope).region, has the same behavior.

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 not sure what the code should be here. Here's what I've tried, all without success:

    const region = Stack.of(context.scope).region;

Yields "cannot find name 'context'"

    const region = {
      produce: (context: any) => Stack.of(context.scope).region,
    };

Results in a test failure because Stack.of(context.scope).region resolves to an Object:

Field ServiceName mismatch: com.amazonaws.[object Object].execute-api !== com.amazonaws.us-east-1.execute-api,Field SubnetIds mismatch: element 1: Ref: VPCPrivateSubnet2SubnetCFCDAA7A !== VPCPrivateSubnet3Subnet3EDCD457 in:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InterfaceVpcEndpointAwsService isn't a construct you don't have any context/scope/stack to use to get the region from. Using Lazy lets you get that context from wherever the InterfaceVpcEndpointAwsService is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. You are correct good sir, my apologies.

@mergify mergify bot dismissed rix0rrr’s stale review June 24, 2020 15:18

Pull request has been modified.

@flemjame-at-amazon
Copy link
Contributor Author

Updated to use the Jest unit tests.

@flemjame-at-amazon
Copy link
Contributor Author

Any update on this?

@@ -315,7 +315,11 @@ export class InterfaceVpcEndpointAwsService implements IInterfaceVpcEndpointServ
public readonly privateDnsDefault?: boolean = true;

constructor(name: string, prefix?: string, port?: number) {
this.name = `${prefix || 'com.amazonaws'}.${Aws.REGION}.${name}`;
// this.name = `${prefix || 'com.amazonaws'}.${Aws.REGION}.${name}`;
const region = Lazy.stringValue({
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. You are correct good sir, my apologies.

@mergify
Copy link
Contributor

mergify bot commented Jul 8, 2020

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: ff85d39
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Jul 8, 2020

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

@mergify mergify bot merged commit 54e5c36 into aws:master Jul 8, 2020
@flemjame-at-amazon flemjame-at-amazon deleted the fix-endpoint-az-lookup branch September 2, 2020 17:55
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.

bug(ec2): Endpoint service AZ lookup fails for InterfaceVpcEndpointAwsService
3 participants