运行以下代码时,我收到错误消息InvalidGroup.NotFound The security group 'OddName' does not exist in default VPC 'vpc-2468'这是正确的 VPC 名称,但不是查看 sg-1357 时会看到的 VPC ID。这是一个请求错误,而不是一个 aws 错误,所以它至少有那么远。从命令行这有效:aws ec2 authorize-security-group-ingress --group-id sg-1357 --cidr 127.0.0.1/32 --protocol tcp --port 443我可以确认已经添加了 ip。从github 上的sdk修改示例代码,以下会产生默认的 VPC 错误:func ExampleEC2_AuthorizeSecurityGroupIngress() {svc := ec2.New(nil)params := &ec2.AuthorizeSecurityGroupIngressInput{ CIDRIP: aws.String("127.0.0.1"), DryRun: aws.Boolean(true), FromPort: aws.Long(443), GroupID: aws.String("sg-1357"), GroupName: aws.String("OddName"), IPPermissions: []*ec2.IPPermission{ { // Required FromPort: aws.Long(1), IPProtocol: aws.String("String"), IPRanges: []*ec2.IPRange{ { // Required CIDRIP: aws.String("String"), }, // More values... }, PrefixListIDs: []*ec2.PrefixListID{ { // Required PrefixListID: aws.String("String"), }, // More values... }, ToPort: aws.Long(1), UserIDGroupPairs: []*ec2.UserIDGroupPair{ { // Required GroupID: aws.String("String"), GroupName: aws.String("String"), UserID: aws.String("String"), }, // More values... }, }, // More values... }, IPProtocol: aws.String("String"), SourceSecurityGroupName: aws.String("String"), SourceSecurityGroupOwnerID: aws.String("String"), ToPort: aws.Long(443),}
1 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
如果您注释掉该GroupName行,它将解决DryRun错误。
params 最终看起来像这样:
params := &ec2.AuthorizeSecurityGroupIngressInput{
CIDRIP: aws.String("127.0.0.1/32"),
DryRun: aws.Boolean(true),
FromPort: aws.Long(443),
GroupID: aws.String("sg-1357"),
IPProtocol: aws.String("tcp"),
SourceSecurityGroupName: aws.String(""),
SourceSecurityGroupOwnerID: aws.String(""),
ToPort: aws.Long(443),
}
- 1 回答
- 0 关注
- 249 浏览
添加回答
举报
0/150
提交
取消