Search code examples
amazon-web-servicesaws-cloudformationaws-java-sdk

AWS Java SDK Cloudformation unable to describe stacks by name or Id


Attempting to make a simple request via the SDK is throwing a 404 Stack not found, however making the call with the exact same stack name returns the stack information as expected.

The code I'm using:

  public String getStatus() {

    final DescribeStackInstanceRequest describeStackInstanceRequest =
        new DescribeStackInstanceRequest();

    describeStackInstanceRequest
        .withStackSetName("a-1593589243-example-com")
        .withStackInstanceAccount("6**********") // My AWS account ID
        .withStackInstanceRegion(Regions.US_EAST_1.getName());

    return amazonCloudFormation
        .describeStackInstance(describeStackInstanceRequest)
        .getStackInstance()
        .getStatus();
  }

Attempting to replace the name with the stack ID and I get back invalid regex error.

And the equvilant CLI command

aws cloudformation describe-stacks --stack-name a-1593589243-example-com

Using the latest version of the SDK

implementation 'com.amazonaws:aws-java-sdk-cloudformation:1.11.812'

Solution

  • The describeStackInstanceRequest call is for Stack Sets not Stacks. These are two different things in CloudFormation.

    I think the following should be used DescribeStacksRequest or an equivalent.