diff --git a/moto/ec2/models/key_pairs.py b/moto/ec2/models/key_pairs.py index b2dab1235..b480b037d 100644 --- a/moto/ec2/models/key_pairs.py +++ b/moto/ec2/models/key_pairs.py @@ -1,4 +1,5 @@ from typing import Any, Dict, List +from datetime import datetime from moto.core import BaseModel from ..exceptions import ( @@ -14,6 +15,7 @@ from ..utils import ( generic_filter, random_key_pair_id, ) +from moto.core.utils import iso_8601_datetime_with_milliseconds class KeyPair(BaseModel): @@ -22,6 +24,11 @@ class KeyPair(BaseModel): self.name = name self.fingerprint = fingerprint self.material = material + self.create_time = datetime.utcnow() + + @property + def created_iso_8601(self) -> str: + return iso_8601_datetime_with_milliseconds(self.create_time) def get_filter_value(self, filter_name: str) -> str: if filter_name == "key-name": diff --git a/moto/ec2/responses/key_pairs.py b/moto/ec2/responses/key_pairs.py index 343f20bde..65f6d2842 100644 --- a/moto/ec2/responses/key_pairs.py +++ b/moto/ec2/responses/key_pairs.py @@ -37,6 +37,7 @@ DESCRIBE_KEY_PAIRS_RESPONSE = """