首页 > 解决方案 > AWS Java SDK Cloudformation 无法按名称或 Id 描述堆栈

问题描述

尝试通过 SDK 发出简单请求会抛出 404 Stack not found,但是使用完全相同的堆栈名称进行调用会按预期返回堆栈信息。

我正在使用的代码:

  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();
  }

尝试用堆栈 ID 替换名称,我得到无效的正则表达式错误。

和等价的 CLI 命令

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

使用最新版本的 SDK

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

标签: amazon-web-servicesamazon-cloudformationaws-java-sdk

解决方案


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.


推荐阅读