Amazon web services AWS&x2B;serverless-(InvalidPermission.NotFound)指定的规则在此安全组中不存在

Amazon web services AWS&x2B;serverless-(InvalidPermission.NotFound)指定的规则在此安全组中不存在,amazon-web-services,boto3,serverless-framework,Amazon Web Services,Boto3,Serverless Framework,我创建了一个小脚本来与AWS交互,更新安全组和EC2实例。该脚本在我的机器上运行良好,但在AWS lambda控制台上测试时遇到问题 我正在使用serverless将lambda函数部署到AmazonWeb服务。我还为这个新的lambda函数创建了一个IAM角色 我遇到的错误是(InvalidPermission.NotFound)错误。完整的错误堆栈如下所示 错误: An error occurred (InvalidPermission.NotFound) when calling the

我创建了一个小脚本来与AWS交互,更新安全组和EC2实例。该脚本在我的机器上运行良好,但在AWS lambda控制台上测试时遇到问题

我正在使用serverless将lambda函数部署到AmazonWeb服务。我还为这个新的lambda函数创建了一个IAM角色

我遇到的错误是(InvalidPermission.NotFound)错误。完整的错误堆栈如下所示

错误:

 An error occurred (InvalidPermission.NotFound) when calling the RevokeSecurityGroupIngress operation: The specified rule does not exist in this security group.: ClientError
Traceback (most recent call last):
  File "/var/task/ipm.py", line 205, in handler
    main()
  File "/var/task/ipm.py", line 197, in main
    sg_ips_remove(to_remove, state_sg, state_ping)
  File "/var/task/ipm.py", line 140, in sg_ips_remove
    update_security_group("revoke", sg_id, sg_ips, state_ping)      # run script to authorize/revoke ip access
  File "/var/task/ipm.py", line 53, in update_security_group
    sg.update_sg_traffic(sg_rules=obj, sg_id=group_id, update_type=update_type)
  File "/var/task/sg.py", line 77, in update_sg_traffic
    ec2.revoke_security_group_ingress(GroupId=sg_id, IpPermissions=sg_rules)
  File "/var/task/botocore/client.py", line 320, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/var/task/botocore/client.py", line 623, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidPermission.NotFound) when calling the RevokeSecurityGroupIngress operation: The specified rule does not exist in this security group.
此错误发生在以下代码段上。同样,这段代码在我的机器上运行良好,但在lambda函数测试期间引发了错误

def update\u sg\u流量(sg\u id,sg\u规则,update\u type=“authorize”):
“”“更新与SG关联的入站流量。可以从SG添加或删除IP。”。
"""
在[“授权”、“撤销”]中断言更新类型
ec2=boto3.client('ec2')
如果更新类型=“授权”:
ec2.授权安全组入口(组id=sg\U id,IpPermissions=sg\U规则)
其他:

ec2.撤销\u安全\u组\u入口(GroupId=sg\u id,IpPermissions=sg\u规则)
您将IAM角色与专有网络安全组混淆了

您收到的错误意味着指定的安全组不存在安全组规则。这与IAM角色无关


如果您的目标是添加/删除IAM角色的权限,则需要重写代码以处理IAM策略。

您是对的。我得到这个错误是因为,在选择SG规则时,我传递了SG id及其描述。不幸的是,描述不匹配,这导致了此错误。因此,我只是删除了描述,只按ID过滤,效果很好。谢谢你的帮助。