jeudi 2 janvier 2020

moto not mocking ec2.describe_security_groups function call

import boto3
....
@mock_ec2
def test_mocking_getting_security_groups(self):
    region = 'us-east-2'
    vpc_security_group_id = 'default'


    session = boto3.Session(profile_name=profile)
    ec2_client = session.client('ec2', region)
    print(ec2_client.describe_security_groups())
    print(ec2_client.describe_security_groups(GroupIds=['sg-3e2bcf04']))

I have this test case and the first prints

{'SecurityGroups': [{'Description': 'default group', 'GroupName': 'default', 'IpPermissions': [], 'OwnerId': '123456789012', 'GroupId': 'sg-0b13b4ba', 'IpPermissionsEgress': [{'IpProtocol': '-1', 'IpRanges': [{'CidrIp': '0.0.0.0/0'}], 'UserIdGroupPairs': []}], 'Tags': []}, {'Description': 'default VPC security group', 'GroupName': 'default', 'IpPermissions': [], 'OwnerId': '123456789012', 'GroupId': 'sg-df20018b', 'IpPermissionsEgress': [{'IpProtocol': '-1', 'IpRanges': [{'CidrIp': '0.0.0.0/0'}], 'UserIdGroupPairs': []}], 'Tags': [], 'VpcId': 'vpc-1940c2c1'}], 'ResponseMetadata': {'RequestId': '59dbff89-35bd-4eac-99ed-be587EXAMPLE', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'amazon.com'}, 'RetryAttempts': 0}}

which seems fine, seems like it's the properly mocked response. But then: ec2_client.describe_security_groups(GroupIds=['sg-3e2bcf04']) fails

E           botocore.exceptions.ClientError: An error occurred (InvalidGroup.NotFound) when calling the DescribeSecurityGroups operation: The security group '{'sg-3e2bcf04'}' does not exist

Is there something else I need to mock out?

Aucun commentaire:

Enregistrer un commentaire