(aws_ec2.VpcEndpointService): Add a way to import existing VpcEndpointService
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
- Expose VpcEndpointService when creating a VPC Link
- Allow a way to import existing VpcEndpointService into CDK.
Workaround:
- Create new NLB and new VpcEndpointService, but this is redundant and isn't cost-efficient.
- 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
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
Can workaround this in the meantime with custom resource I suppose, but from method would be better...
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.');
}
}