working on typescript , how can i validate if resouces exists before try to create it. ?
[11:50 AM] for example i want to create vpc only where it's not exists:) const vpc = new awsx.ec2.Vpc(vpcName, { numberOfAvailabilityZones: 2 });
[11:50 AM] error: Duplicate resource URN '
f
few-postman-20852
11/28/2023, 2:10 PM
do a try catch and use the get function:
Copy code
awsx.ec2.Vpc.get("name", "urn")
then on the catch you return the created resource
l
little-cartoon-10569
11/28/2023, 9:37 PM
This solution results in your project permanently having to maintain a code path for an unmanaged resource and one for a managed resource. A more sustainable option is to manually import the resource, and omit the get code and exception handling. That way, the only code path is for the managed resource.
f
few-postman-20852
11/29/2023, 8:29 AM
I agree. The best practice would be to import the resource. But sometimes resources gets created automatically based on parent resources. So I contained myself to only answer the question.