working on typescript , how can i validate if reso...
# general
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 '
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
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.
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.