2019-08-14 21:11:05 +00:00
import boto3
2021-10-18 19:44:29 +00:00
import sure # noqa # pylint: disable=unused-import
2019-08-14 21:11:05 +00:00
2020-10-06 05:54:49 +00:00
import pytest
2019-08-14 21:11:05 +00:00
from botocore . client import ClientError
2021-10-05 17:11:07 +00:00
from moto import mock_ec2 , settings
from uuid import uuid4
2019-08-14 21:11:05 +00:00
2019-08-19 23:01:44 +00:00
2019-08-14 21:11:05 +00:00
@mock_ec2
def test_launch_template_create ( ) :
2019-08-14 21:32:01 +00:00
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
resp = cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-08-14 21:11:05 +00:00
# the absolute minimum needed to create a template without other resources
LaunchTemplateData = {
2019-10-31 15:44:26 +00:00
" TagSpecifications " : [
{
" ResourceType " : " instance " ,
" Tags " : [ { " Key " : " test " , " Value " : " value " } ] ,
}
]
2019-08-14 21:11:05 +00:00
} ,
)
resp . should . have . key ( " LaunchTemplate " )
lt = resp [ " LaunchTemplate " ]
2021-10-05 17:11:07 +00:00
lt [ " LaunchTemplateName " ] . should . equal ( template_name )
2019-08-14 21:11:05 +00:00
lt [ " DefaultVersionNumber " ] . should . equal ( 1 )
lt [ " LatestVersionNumber " ] . should . equal ( 1 )
2020-10-06 05:54:49 +00:00
with pytest . raises ( ClientError ) as ex :
2019-08-14 21:11:05 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-08-14 21:11:05 +00:00
LaunchTemplateData = {
2019-10-31 15:44:26 +00:00
" TagSpecifications " : [
{
" ResourceType " : " instance " ,
" Tags " : [ { " Key " : " test " , " Value " : " value " } ] ,
}
]
2019-08-14 21:11:05 +00:00
} ,
)
2020-10-06 06:04:09 +00:00
str ( ex . value ) . should . equal (
2019-10-31 15:44:26 +00:00
" An error occurred (InvalidLaunchTemplateName.AlreadyExistsException) when calling the CreateLaunchTemplate operation: Launch template name already in use. "
)
2019-08-14 21:11:05 +00:00
2019-08-19 22:57:39 +00:00
2019-08-14 21:11:05 +00:00
@mock_ec2
def test_describe_launch_template_versions ( ) :
template_data = {
" ImageId " : " ami-abc123 " ,
" DisableApiTermination " : False ,
2019-10-31 15:44:26 +00:00
" TagSpecifications " : [
{ " ResourceType " : " instance " , " Tags " : [ { " Key " : " test " , " Value " : " value " } ] }
2019-08-14 21:11:05 +00:00
] ,
2019-10-31 15:44:26 +00:00
" SecurityGroupIds " : [ " sg-1234 " , " sg-ab5678 " ] ,
2019-08-14 21:11:05 +00:00
}
2019-08-14 21:32:01 +00:00
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
create_resp = cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = template_data
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
# test using name
resp = cli . describe_launch_template_versions (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , Versions = [ " 1 " ]
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
templ = resp [ " LaunchTemplateVersions " ] [ 0 ] [ " LaunchTemplateData " ]
templ . should . equal ( template_data )
# test using id
resp = cli . describe_launch_template_versions (
LaunchTemplateId = create_resp [ " LaunchTemplate " ] [ " LaunchTemplateId " ] ,
2019-10-31 15:44:26 +00:00
Versions = [ " 1 " ] ,
)
2019-08-14 21:11:05 +00:00
templ = resp [ " LaunchTemplateVersions " ] [ 0 ] [ " LaunchTemplateData " ]
templ . should . equal ( template_data )
2019-08-19 23:01:44 +00:00
2019-08-14 21:11:05 +00:00
@mock_ec2
def test_create_launch_template_version ( ) :
2019-08-14 21:32:01 +00:00
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
create_resp = cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
version_resp = cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-def456 " } ,
VersionDescription = " new ami " ,
)
2019-08-14 21:11:05 +00:00
version_resp . should . have . key ( " LaunchTemplateVersion " )
version = version_resp [ " LaunchTemplateVersion " ]
version [ " DefaultVersion " ] . should . equal ( False )
2019-10-31 15:44:26 +00:00
version [ " LaunchTemplateId " ] . should . equal (
create_resp [ " LaunchTemplate " ] [ " LaunchTemplateId " ]
)
2019-08-14 21:11:05 +00:00
version [ " VersionDescription " ] . should . equal ( " new ami " )
version [ " VersionNumber " ] . should . equal ( 2 )
2019-08-19 23:01:44 +00:00
2019-08-14 21:11:05 +00:00
@mock_ec2
2019-08-19 22:58:48 +00:00
def test_create_launch_template_version_by_id ( ) :
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-19 22:58:48 +00:00
create_resp = cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:58:48 +00:00
version_resp = cli . create_launch_template_version (
LaunchTemplateId = create_resp [ " LaunchTemplate " ] [ " LaunchTemplateId " ] ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-def456 " } ,
VersionDescription = " new ami " ,
)
2019-08-19 22:58:48 +00:00
version_resp . should . have . key ( " LaunchTemplateVersion " )
version = version_resp [ " LaunchTemplateVersion " ]
version [ " DefaultVersion " ] . should . equal ( False )
2019-10-31 15:44:26 +00:00
version [ " LaunchTemplateId " ] . should . equal (
create_resp [ " LaunchTemplate " ] [ " LaunchTemplateId " ]
)
2019-08-19 22:58:48 +00:00
version [ " VersionDescription " ] . should . equal ( " new ami " )
version [ " VersionNumber " ] . should . equal ( 2 )
@mock_ec2
def test_describe_launch_template_versions_with_multiple_versions ( ) :
2019-08-14 21:32:01 +00:00
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-def456 " } ,
VersionDescription = " new ami " ,
)
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
resp = cli . describe_launch_template_versions ( LaunchTemplateName = template_name )
2019-08-14 21:11:05 +00:00
resp [ " LaunchTemplateVersions " ] . should . have . length_of ( 2 )
2019-10-31 15:44:26 +00:00
resp [ " LaunchTemplateVersions " ] [ 0 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-abc123 "
)
resp [ " LaunchTemplateVersions " ] [ 1 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-def456 "
)
2019-08-14 21:11:05 +00:00
2019-08-19 22:57:39 +00:00
@mock_ec2
def test_describe_launch_template_versions_with_versions_option ( ) :
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-19 22:57:39 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-def456 " } ,
VersionDescription = " new ami " ,
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-hij789 " } ,
VersionDescription = " new ami, again " ,
)
2019-08-19 22:57:39 +00:00
resp = cli . describe_launch_template_versions (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , Versions = [ " 2 " , " 3 " ]
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
resp [ " LaunchTemplateVersions " ] . should . have . length_of ( 2 )
2019-10-31 15:44:26 +00:00
resp [ " LaunchTemplateVersions " ] [ 0 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-def456 "
)
resp [ " LaunchTemplateVersions " ] [ 1 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-hij789 "
)
2019-08-19 22:57:39 +00:00
@mock_ec2
def test_describe_launch_template_versions_with_min ( ) :
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-19 22:57:39 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-def456 " } ,
VersionDescription = " new ami " ,
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-hij789 " } ,
VersionDescription = " new ami, again " ,
)
2019-08-19 22:57:39 +00:00
resp = cli . describe_launch_template_versions (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , MinVersion = " 2 "
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
resp [ " LaunchTemplateVersions " ] . should . have . length_of ( 2 )
2019-10-31 15:44:26 +00:00
resp [ " LaunchTemplateVersions " ] [ 0 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-def456 "
)
resp [ " LaunchTemplateVersions " ] [ 1 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-hij789 "
)
2019-08-19 22:57:39 +00:00
@mock_ec2
def test_describe_launch_template_versions_with_max ( ) :
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-19 22:57:39 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-def456 " } ,
VersionDescription = " new ami " ,
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-hij789 " } ,
VersionDescription = " new ami, again " ,
)
2019-08-19 22:57:39 +00:00
resp = cli . describe_launch_template_versions (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , MaxVersion = " 2 "
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
resp [ " LaunchTemplateVersions " ] . should . have . length_of ( 2 )
2019-10-31 15:44:26 +00:00
resp [ " LaunchTemplateVersions " ] [ 0 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-abc123 "
)
resp [ " LaunchTemplateVersions " ] [ 1 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-def456 "
)
2019-08-19 22:57:39 +00:00
@mock_ec2
def test_describe_launch_template_versions_with_min_and_max ( ) :
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-19 22:57:39 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-def456 " } ,
VersionDescription = " new ami " ,
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-hij789 " } ,
VersionDescription = " new ami, again " ,
)
2019-08-19 22:57:39 +00:00
cli . create_launch_template_version (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-10-31 15:44:26 +00:00
LaunchTemplateData = { " ImageId " : " ami-345abc " } ,
VersionDescription = " new ami, because why not " ,
)
2019-08-19 22:57:39 +00:00
resp = cli . describe_launch_template_versions (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , MinVersion = " 2 " , MaxVersion = " 3 "
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:57:39 +00:00
resp [ " LaunchTemplateVersions " ] . should . have . length_of ( 2 )
2019-10-31 15:44:26 +00:00
resp [ " LaunchTemplateVersions " ] [ 0 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-def456 "
)
resp [ " LaunchTemplateVersions " ] [ 1 ] [ " LaunchTemplateData " ] [ " ImageId " ] . should . equal (
" ami-hij789 "
)
2019-08-19 22:57:39 +00:00
2019-08-14 21:11:05 +00:00
@mock_ec2
def test_describe_launch_templates ( ) :
2019-08-14 21:32:01 +00:00
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2019-08-14 21:11:05 +00:00
lt_ids = [ ]
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
r = cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
lt_ids . append ( r [ " LaunchTemplate " ] [ " LaunchTemplateId " ] )
2021-10-05 17:11:07 +00:00
template_name2 = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
r = cli . create_launch_template (
2022-03-10 14:39:59 +00:00
LaunchTemplateName = template_name2 , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
lt_ids . append ( r [ " LaunchTemplate " ] [ " LaunchTemplateId " ] )
# general call, all templates
2021-10-05 17:11:07 +00:00
if not settings . TEST_SERVER_MODE :
# Bug: Only 15 launch templates are returned, ever
# ServerMode may have many more templates, created in parallel
all_templates = retrieve_all_templates ( cli )
my_templates = [ t for t in all_templates if t [ " LaunchTemplateId " ] in lt_ids ]
my_templates [ 0 ] [ " LaunchTemplateName " ] . should . equal ( template_name )
my_templates [ 1 ] [ " LaunchTemplateName " ] . should . equal ( template_name2 )
2019-08-14 21:11:05 +00:00
# filter by names
resp = cli . describe_launch_templates (
2021-10-05 17:11:07 +00:00
LaunchTemplateNames = [ template_name2 , template_name ]
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
resp . should . have . key ( " LaunchTemplates " )
resp [ " LaunchTemplates " ] . should . have . length_of ( 2 )
2021-10-05 17:11:07 +00:00
resp [ " LaunchTemplates " ] [ 0 ] [ " LaunchTemplateName " ] . should . equal ( template_name2 )
resp [ " LaunchTemplates " ] [ 1 ] [ " LaunchTemplateName " ] . should . equal ( template_name )
2019-08-14 21:11:05 +00:00
# filter by ids
resp = cli . describe_launch_templates ( LaunchTemplateIds = lt_ids )
resp . should . have . key ( " LaunchTemplates " )
resp [ " LaunchTemplates " ] . should . have . length_of ( 2 )
2021-10-05 17:11:07 +00:00
resp [ " LaunchTemplates " ] [ 0 ] [ " LaunchTemplateName " ] . should . equal ( template_name )
resp [ " LaunchTemplates " ] [ 1 ] [ " LaunchTemplateName " ] . should . equal ( template_name2 )
2019-08-14 21:11:05 +00:00
2019-08-19 23:01:44 +00:00
2019-08-14 21:11:05 +00:00
@mock_ec2
def test_describe_launch_templates_with_filters ( ) :
2019-08-14 21:32:01 +00:00
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
r = cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , LaunchTemplateData = { " ImageId " : " ami-abc123 " }
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
tag_value = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
cli . create_tags (
Resources = [ r [ " LaunchTemplate " ] [ " LaunchTemplateId " ] ] ,
Tags = [
2021-10-05 17:11:07 +00:00
{ " Key " : " tag1 " , " Value " : tag_value } ,
2019-08-14 21:11:05 +00:00
{ " Key " : " another-key " , " Value " : " this value " } ,
2019-10-31 15:44:26 +00:00
] ,
)
2019-08-14 21:11:05 +00:00
2021-10-05 17:11:07 +00:00
template_name_no_tags = str ( uuid4 ( ) )
2019-08-14 21:11:05 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name_no_tags ,
LaunchTemplateData = { " ImageId " : " ami-abc123 " } ,
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
2019-10-31 15:44:26 +00:00
resp = cli . describe_launch_templates (
2021-10-05 17:11:07 +00:00
Filters = [ { " Name " : " tag:tag1 " , " Values " : [ tag_value ] } ]
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
resp [ " LaunchTemplates " ] . should . have . length_of ( 1 )
2021-10-05 17:11:07 +00:00
resp [ " LaunchTemplates " ] [ 0 ] [ " LaunchTemplateName " ] . should . equal ( template_name )
2019-08-14 21:11:05 +00:00
2019-10-31 15:44:26 +00:00
resp = cli . describe_launch_templates (
2021-10-05 17:11:07 +00:00
Filters = [ { " Name " : " launch-template-name " , " Values " : [ template_name_no_tags ] } ]
2019-10-31 15:44:26 +00:00
)
2019-08-14 21:11:05 +00:00
resp [ " LaunchTemplates " ] . should . have . length_of ( 1 )
2021-10-05 17:11:07 +00:00
resp [ " LaunchTemplates " ] [ 0 ] [ " LaunchTemplateName " ] . should . equal ( template_name_no_tags )
2019-08-14 21:11:05 +00:00
2019-08-19 22:58:19 +00:00
@mock_ec2
def test_create_launch_template_with_tag_spec ( ) :
cli = boto3 . client ( " ec2 " , region_name = " us-east-1 " )
2021-10-05 17:11:07 +00:00
template_name = str ( uuid4 ( ) )
2019-08-19 22:58:19 +00:00
cli . create_launch_template (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name ,
2019-08-19 23:01:44 +00:00
LaunchTemplateData = { " ImageId " : " ami-abc123 " } ,
2019-10-31 15:44:26 +00:00
TagSpecifications = [
{ " ResourceType " : " instance " , " Tags " : [ { " Key " : " key " , " Value " : " value " } ] }
] ,
2019-08-19 22:58:19 +00:00
)
resp = cli . describe_launch_template_versions (
2021-10-05 17:11:07 +00:00
LaunchTemplateName = template_name , Versions = [ " 1 " ]
2019-10-31 15:44:26 +00:00
)
2019-08-19 22:58:19 +00:00
version = resp [ " LaunchTemplateVersions " ] [ 0 ]
version [ " LaunchTemplateData " ] . should . have . key ( " TagSpecifications " )
version [ " LaunchTemplateData " ] [ " TagSpecifications " ] . should . have . length_of ( 1 )
2019-10-31 15:44:26 +00:00
version [ " LaunchTemplateData " ] [ " TagSpecifications " ] [ 0 ] . should . equal (
{ " ResourceType " : " instance " , " Tags " : [ { " Key " : " key " , " Value " : " value " } ] }
)
2021-10-05 17:11:07 +00:00
2021-10-18 19:44:29 +00:00
def retrieve_all_templates ( client , filters = [ ] ) : # pylint: disable=W0102
2021-10-05 17:11:07 +00:00
resp = client . describe_launch_templates ( Filters = filters )
all_templates = resp [ " LaunchTemplates " ]
next_token = resp . get ( " NextToken " )
while next_token :
resp = client . describe_launch_templates ( Filters = filters , NextToken = next_token )
all_templates . extend ( resp [ " LaunchTemplates " ] )
next_token = resp . get ( " NextToken " )
return all_templates