如何在java中处理aws cdk cfnsecuritygroup

zbdgwd5y  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(444)

以下代码在代码“cfnsecuritygroupingres sgi=(cfnsecuritygroupingres)obj”行生成“software.amazon.jsii.jsiobject cannot be cast to software.amazon.awscdk.services.ec2.cfnsecuritygroupingres”错误

CfnSecurityGroup cfnSecurityGroup = (CfnSecurityGroup) resource_SecurityGroup.getCfnresource();

    if (cfnSecurityGroup.getSecurityGroupIngress() != null) {

      List<CfnSecurityGroupIngress> cfnSecurityGroupIngress = (List<CfnSecurityGroupIngress>) cfnSecurityGroup.getSecurityGroupIngress();

      ListIterator<CfnSecurityGroupIngress> it = cfnSecurityGroupIngress.listIterator();
      while (it.hasNext()) {
        Object obj = it.next();
        LOG.debug("obj: " + obj.toString());
        CfnSecurityGroupIngress sgi = (CfnSecurityGroupIngress)obj;
        LOG.debug("getFromPort" + sgi.getFromPort());
      }

如何访问securitygroupingress属性?
注意,我已经确定cfnsecuritygroup.ingresproperty是cfnsecuritygroupingres.lisiterator()中存在的接口类型。不过,我不知道该怎么办。
Maven

<dependency>
        <groupId>software.amazon.awscdk</groupId>
        <artifactId>cdk-cloudformation-include</artifactId>
        <version>1.79.0</version>
    </dependency>

敬孔戴

bbuxkriu

bbuxkriu1#

我注意到访问参数的一种方法是

LOG.debug(this.resolve(obj).toString());

返回json字符串

{cidrIp={Ref=SSHLocation}, fromPort=22, ipProtocol=tcp, toPort={Ref=ToPort}}

相关问题