aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(aws_ec2.VpcEndpointService): Add a way to import existing VpcEndpointService

Open ronnypmuliawan opened this issue 3 years ago • 3 comments

Describe the feature

Currently, there's no way to import an existing VpcEndpointService into CDK Project. There's a lack of From* method for VpcEndpointService

Use Case

I have created NLB into my application's private subnet and exposed this NLB to a Private REST API Gateway via VPC Link.

It seems like adding VPC Link automatically creates a VPC Endpoint Service. However, the problem is I cannot get a reference to the VpcEndpointService to use in CDK nor import VpcEndpointService.

I would like to modify the VpcEndpointService to expose the same NLB to an VpcEndpoint on another AWS Account.

I am intending to implement a Global API Gateway as written here: https://aws.amazon.com/blogs/compute/building-private-cross-account-apis-using-amazon-api-gateway-and-aws-privatelink/

Proposed Solution

  1. Expose VpcEndpointService when creating a VPC Link
  2. Allow a way to import existing VpcEndpointService into CDK.

Workaround:

  1. Create new NLB and new VpcEndpointService, but this is redundant and isn't cost-efficient.
  2. Manually or use AWS CLI to modify the existing VpcEndpointService (change the AllowPrincipal and AcceptanceRequired to false)

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

CDK version used

2.56.0

Environment details (OS name and version, etc.)

Windows 10

ronnypmuliawan avatar Mar 14 '23 02:03 ronnypmuliawan

Yes we should add from* method in the VpcEndpointService class.

https://github.com/aws/aws-cdk/blob/1105514fc88ae4637a5d187a48ff1a37a4932579/packages/%40aws-cdk/aws-ec2/lib/vpc-endpoint-service.ts#L47

pahud avatar Mar 14 '23 15:03 pahud

Can workaround this in the meantime with custom resource I suppose, but from method would be better...

gagipro avatar Apr 08 '23 06:04 gagipro

Workaround in the meantime the PR #36661 gets merged

export class ImportedVpcEndpointService extends Construct implements IVpcEndpointService {
  vpcEndpointServiceName: string;
  vpcEndpointServiceId: string;
  stack: Stack;
  env: ResourceEnvironment;

  constructor(parent: Construct, name: string, vpcEndpointServiceId: string) {
    super(parent, name);

    this.stack = Stack.of(this);
    this.env = { account: this.stack.account, region: this.stack.region };

    this.vpcEndpointServiceId = vpcEndpointServiceId;
    this.vpcEndpointServiceName = Fn.join('.', [
      VpcEndpointService.DEFAULT_PREFIX,
      this.stack.region,
      this.vpcEndpointServiceId,
    ]);
  }

  applyRemovalPolicy(policy: RemovalPolicy): void {
    throw new Error('Method not implemented.');
  }
}

ayush987goyal avatar Jan 18 '26 06:01 ayush987goyal