2023-09-03 14:59:09 +00:00
|
|
|
import os
|
2023-11-30 15:55:51 +00:00
|
|
|
from unittest import SkipTest, mock
|
2022-08-28 22:30:11 +00:00
|
|
|
|
2023-11-30 15:55:51 +00:00
|
|
|
import boto3
|
2022-08-28 22:30:11 +00:00
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws, settings
|
2022-08-28 22:30:11 +00:00
|
|
|
|
2023-07-04 09:33:26 +00:00
|
|
|
test_ami = "/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64"
|
2022-08-28 22:30:11 +00:00
|
|
|
|
|
|
|
|
2023-09-03 14:59:09 +00:00
|
|
|
# The default AMIs are not loaded for our test case, to speed things up
|
|
|
|
# But we do need it for this specific test
|
|
|
|
@mock.patch.dict(os.environ, {"MOTO_EC2_LOAD_DEFAULT_AMIS": "true"})
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2022-08-28 22:30:11 +00:00
|
|
|
def test_ssm_get_latest_ami_by_path():
|
2023-09-03 14:59:09 +00:00
|
|
|
if settings.TEST_SERVER_MODE:
|
|
|
|
raise SkipTest("Can't set environment variables in ServerMode")
|
2022-08-28 22:30:11 +00:00
|
|
|
ssm = boto3.client("ssm", region_name="us-east-1")
|
|
|
|
ami = ssm.get_parameter(Name=test_ami)["Parameter"]["Value"]
|
|
|
|
|
|
|
|
ec2 = boto3.client("ec2", region_name="us-east-1")
|
2023-08-13 20:42:50 +00:00
|
|
|
assert len(ec2.describe_images(ImageIds=[ami])["Images"]) == 1
|