vpc ID'vpc-xxxxxxxxxxxxx'不存在

时间:2019-08-25 20:46:26

标签: amazon-web-services amazon-ec2 aws-security-group

我需要为正在运行的AWS EC2实例创建一个新的SecurityGroup。 但是,代码始终会引发错误The vpc ID 'vpc-0ea1b3726c73125e2' does not exist。我提供的vpc ID是指实例在其中部署的vpc

这是代码段:

    CreateSecurityGroupRequest create_request = new
            CreateSecurityGroupRequest()
            .withGroupName(group_name)
            .withDescription(group_desc)
            .withVpcId(vpc_id);

    CreateSecurityGroupResult create_response =
            ec2.createSecurityGroup(create_request);


    IpRange ip_range = new IpRange()
            .withCidrIp(maliciousIpAddress+"/24");

    IpPermission ip_perm = new IpPermission()
            .withIpProtocol("tcp")
            .withToPort(0)
            .withFromPort(0)
            .withIpv4Ranges(ip_range);

    AuthorizeSecurityGroupIngressRequest auth_request = new
            AuthorizeSecurityGroupIngressRequest()
            .withGroupName(group_name)
            .withIpPermissions(ip_perm);


    AuthorizeSecurityGroupIngressResult auth_response =
            ec2.authorizeSecurityGroupIngress(auth_request);

0 个答案:

没有答案