From b7624e10b1ec1e351c30b7f8dce76d4f33efcc69 Mon Sep 17 00:00:00 2001 From: Alex Chesters <10558792+AlexChesters@users.noreply.github.com> Date: Thu, 25 May 2023 21:55:41 +0100 Subject: [PATCH] Add CreateTime property to EC2 key pair response (#6341) --- moto/ec2/models/key_pairs.py | 7 +++++++ moto/ec2/responses/key_pairs.py | 1 + tests/test_ec2/test_key_pairs.py | 2 ++ 3 files changed, 10 insertions(+) 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 = """