amazon web services - Best way to check whether a cloud formation stack exists using AWS Java SDK? -




what best way check whether stack exists using aws java sdk, given stack name?

i've tried below code based on - https://github.com/aws/aws-sdk-java/blob/master/src/samples/awscloudformation/cloudformationsample.java

    describestacksrequest wait = new describestacksrequest();     wait.setstackname(stackname);             list<stack> stacks = awscftclient.describestacks(wait).getstacks();     if (stacks.isempty()) {         logger.log("no_such_stack");         return true;     } 

however, getting:

amazonserviceexception:com.amazonaws.services.cloudformation.model.amazoncloudformationexception: stack id "stackname" not exist.

thanks in advance!

in case else looking quick , dirty solution, works,

//returns true if stack exists public boolean stackexists(amazoncloudformation awscftclient, string stackname) throws exception{     describestacksrequest describe = new describestacksrequest();     describe.setstackname(stackname);     //if stack not exist exception describe stack     try {         awscftclient.describestacks(describe).getstacks();     } catch (exception e) {         logger.log("error message: " + e.getmessage());         if (e.getmessage().matches("(.*)" + stackname + "(.*)does not exist(.*)")) {             return false;         } else {             throw e;         }     }     return true; } 

if there better way doing this, please let me know.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -