| 
									
										
										
										
											2023-03-04 11:36:00 -01:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2023-09-03 14:59:09 +00:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2023-03-04 11:36:00 -01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 14:59:09 +00:00
										 |  |  | from moto import mock_ec2, mock_ssm, settings | 
					
						
							|  |  |  | from unittest import mock, SkipTest | 
					
						
							| 
									
										
										
										
											2023-03-04 11:36:00 -01: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"}) | 
					
						
							| 
									
										
										
										
											2023-03-04 11:36:00 -01:00
										 |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_ssm | 
					
						
							|  |  |  | 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") | 
					
						
							| 
									
										
										
										
											2023-03-04 11:36:00 -01:00
										 |  |  |     ssm = boto3.client("ssm", region_name="us-east-1") | 
					
						
							|  |  |  |     path = "/aws/service/ecs/optimized-ami" | 
					
						
							|  |  |  |     params = ssm.get_parameters_by_path(Path=path, Recursive=True)["Parameters"] | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |     assert len(params) == 10 | 
					
						
							| 
									
										
										
										
											2023-03-04 11:36:00 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ec2 = boto3.client("ec2", region_name="us-east-1") | 
					
						
							|  |  |  |     for param in params: | 
					
						
							|  |  |  |         if "Value" in param and isinstance(param["Value"], dict): | 
					
						
							|  |  |  |             ami = param["Value"]["image_id"] | 
					
						
							| 
									
										
										
										
											2023-08-13 16:42:50 -04:00
										 |  |  |             assert len(ec2.describe_images(ImageIds=[ami])["Images"]) == 1 |