# Buggy code
def get_launch_id(self, asg):
    lid = asg.get("LaunchConfigurationName")
    if lid is not None:
        # We've noticed trailing white space allowed in some asgs
        return lid.strip()

    lid = asg.get("LaunchTemplate")
    if lid is not None:
        return (lid["LaunchTemplateId"], lid["Version"])

    if "MixedInstancesPolicy" in asg:
        mip_spec = asg["MixedInstancesPolicy"]["LaunchTemplate"][
            "LaunchTemplateSpecification"
        ]
        return (mip_spec["LaunchTemplateId"], mip_spec["Version"])

    # we've noticed some corner cases where the asg name is the lc name, but not
    # explicitly specified as launchconfiguration attribute.
    lid = asg["AutoScalingGroupName"]
    return lid


# Traceback (KeyError)
Traceback (most recent call last):
File "/home/cloudcustodian/custodian/bin/c7n-org", line 11, in <module>
sys.exit(cli())
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n_org/cli.py", line 649, in run
debug)] = (a, r)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/executor.py", line 63, in submit
return MainThreadFuture(func(*args, **kw))
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n_org/cli.py", line 560, in run_account
resources = p.run()
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/policy.py", line 1045, in __call__
resources = PullMode(self).run()
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/policy.py", line 288, in run
resources = self.policy.resource_manager.resources()
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/query.py", line 467, in resources
resources = self.filter_resources(resources)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/manager.py", line 108, in filter_resources
resources = f.process(resources, event)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/resources/asg.py", line 832, in process
launch_info = LaunchInfo(self.manager).initialize(asgs)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/resources/asg.py", line 85, in initialize
self.templates = self.get_launch_templates(asgs)
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/resources/asg.py", line 92, in get_launch_templates
template_ids = list(tmpl_mgr.get_asg_templates(asgs))
File "/home/cloudcustodian/custodian/lib/python3.6/site-packages/c7n/resources/ec2.py", line 1956, in get_asg_templates
t['Version']), []).append(a['AutoScalingGroupName'])
KeyError: 'Version'

# Fixed code
def get_launch_id(self, asg):
    lid = asg.get("LaunchConfigurationName")
    if lid is not None:
        # We've noticed trailing white space allowed in some asgs
        return lid.strip()

    lid = asg.get("LaunchTemplate")
    if lid is not None:
        return (lid["LaunchTemplateId"], lid.get("Version", "$Default"))

    if "MixedInstancesPolicy" in asg:
        mip_spec = asg["MixedInstancesPolicy"]["LaunchTemplate"][
            "LaunchTemplateSpecification"
        ]
        return (mip_spec["LaunchTemplateId"], mip_spec.get("Version", "$Default"))

    # we've noticed some corner cases where the asg name is the lc name, but not
    # explicitly specified as launchconfiguration attribute.
    lid = asg["AutoScalingGroupName"]
    return lid