i’m trying to alter the tags on the subnets made b...
# getting-started
i’m trying to alter the tags on the subnets made by the awsx.ec2.Vpc class, but struggling to figure out how that’s done in python, and haven’t had any luck in finding anything that isn’t in typescript. Can anyone give any pointers on how that’s done ? It doesn’t seem to form part of the SubnetSpecArgs class so i guess it’s done in some other way. The typescript seems to access a ‘subnets’ attribute of the class, but that doesn’t seem to be a thing in python unless i’m misreading the source.
AWSX, and all other convenience wrappers, will necessarily expose a smaller number of configuration options than the resources they're built on. If setting subnet tags via the Vpc constructor isn't possible (and it likely isn't), then you can use a transformation to achieve the same thing.
hmm, thanks for that. Apparently that’s going to be beyond my brain power to pull off, but thanks for the pointer 👍
It's not hard, I'm happy to help.
You define a function that adds tags to subnets: it'll be very like the one in the example code on that page, but only checking for
args.type_ == "aws:ec2/subnet:Subnet"
, and setting
instead of
Then you pass that function as a transformation to your awsx.ec2.Vpc constructor, just like in the last line of the example code.
i’ll give that a shot. uno momento.
i think the things that tripped me up was 1) what myvpccomponent was meant to be (possibly because i dont know what a component is in the first place, if thats a thing), and 2) i’m going to need to set the tags on the subnets differently based on which type of subnet it is, and this seems to be returning a single value which would include the tags. So somewhere in there i’m going to need to lookup what type of subnet it is.
If the logic is too complex, this suggests to be that you shouldn't be using awsx.ec2.Vpc. You'd be better off with the additional control you get from aws.ec2.Vpc.
yeah ok. makes sense. 👍
It's the old convention-over-configuration thing 🙂 Once you're configuring your conventionally-created resources... yeah, nah! (As we say here in New Zealand)