I’m creating an `awsx.ec2.Vpc` with 4 different su...
# aws
b
I’m creating an
awsx.ec2.Vpc
with 4 different subnet groups (private, public, db, redis). In order for them to show in the console as sensible name you can include
tags: { Name: "db" }
for each subnet, however unfortunately that results in a subnet group’s subnets having the same name regardless of what az they are in. Instead I’d like to have their names follow the format
example-name-az
or
example-name-number
, eg
example-db-us-west-2
or
example-db-2
. How can I achieve this without needing to specify each az subnet one at a time?
f
I am also interested in this, sorry I can’t help you here but if you figure it out please do share!
g
Here's an example that creates a subnet in each available zone:
Copy code
const zones = aws.getAvailabilityZones().zoneIds;
const subnets = zones.map((zoneId, i) => {
    return new aws.ec2.Subnet(`demo-${i}`, {
        vpcId: vpc.id,
        availabilityZoneId: zoneId,
        cidrBlock: `10.0.${i}.0/22`,
        tags: {
            Name: `demo-${i}`,
        },
    }, { parent: vpc, })
});