-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
aws-cdk-lib: exporting a class that implements IVpc but only looks up a vpc by Id #27615
Comments
Given we already have LookedUpVpc, it's unclear to me why we need a new class in aws-ec2 ? Can you elaborate more on it? |
Thank you for your prompt reply! We don't need a new class, but consider the following: import { LookedUpVpc } from "aws-cdk-lib/aws-ec2" Second issue (or more like improvement) is the arguments in constructor of LookedUpVpc, it would be rather nice to have it the same as Vpc.fromLookup. Maybe extending the use case would clarity of my intended use, class MyVpc extends LookedUpVpc {
constructor(scope: Construct, id: string, props: VpcLookupOptions) { // VpcLookup as in arguments of Vpc.fromLookup
super(scope, id, props); // this is cunrrently wrong, but it's the desired functionality
}
get someSubnetGroup() {
return this.selectSubnets({
...
})
}
} then In my stack I can do something like: class MyStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const exampleVpc = new MyVpc(this, "my-vpc", { vpcId: "exampleVpc" });
new NodejsFunction(this, "my-function", {
vpc: exampleVpc,
vpcSubnets: exampleVpc.someSubnetGroup,
})
}
} I can exand further the utility in creating sharable constructs with intended default properties like: class MyNodejsFunction extends NodejsFunction {
constructor(scope: Construct, id: string, props: NodejsFunctionProps ){
const vpcSubnets = props.vpc instanceof MyVpc ? props.vpc.someSubnetGroup : undefined
super(scope, id, { vpcSubnets, ...props });
}
} As there is no class exported with a looked up vpc, the best approach so far would be something of sorts: class MyVpc extends Construct {
private vpc: IVpc;
constructor(scope: Construct, id: string, vpcId: string) {
super(scope, id);
this.vpc = Vpc.fromLookup(this, "vpc-lookup", { vpcId });
}
} But as |
Why not just have your class implement |
@quaverBit Please confirm if this feature request is still valid and if you are unblocked. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Describe the feature
Having a class that is able to lookup a Vpc by it's Id and implementing
IVpc
so it can be extended with own methods and properties.Use Case
Doing
class MyVpc extends Vpc
will try to deploy a new Vpc to aws and that is not intended. I want to be able to extend a class that looks up Vpc by it's id in something like:Proposed Solution
Maybe it's possible to move
Vpc.fromLookup
code/logic to inside of a seperated class constructor?Other Information
Alternative solution would be export LookedUpVpc?
Acknowledgements
CDK version used
2
Environment details (OS name and version, etc.)
linux
The text was updated successfully, but these errors were encountered: