aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.4k stars 576 forks source link

v1: E1040 that does not match 'AWS::EC2::Image.Id' #3318

Closed egut closed 2 weeks ago

egut commented 2 weeks ago

CloudFormation Lint Version

v1.3.0

What operating system are you using?

Ubuntu

Describe the bug

The full error is: E1040 {'Fn::GetAtt': ['SelectAMI', 'AMI']} that does not match 'AWS::EC2::Image.Id'

LaunchTemplate:
    Type: 'AWS::EC2::LaunchTemplate'
    Properties:
      LaunchTemplateName: !Sub '${ShortName}-Template'
      LaunchTemplateData:
        ImageId: !GetAtt 'SelectAMI.AMI'
        :

  SelectAMI:
    Type: 'Custom::SelectAMI'
    Properties:
      ServiceToken: !GetAtt 'SelectAMICustomLambda.Arn'
      :

The custom lambda use some more information to select right image to the LaunchTemplate and then return it as:

    import cfnresponse
     :      

     def lambda_handler(event, context):

            : 
            # ami is a string
            response_data = {"AMI": ami}
            cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data)

Expected behavior

Expected is that the type check do accept string too as it say in the documentation https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata.html

Reproduction template

---
AWSTemplateFormatVersion: 2010-09-09
Description: 'Bug E1040 and E3014'

Parameters:

  BuildId:
    Type: 'AWS::SSM::Parameter::Value<String>'

  ShortName:
    Type: 'String'

Resources:

  LaunchTemplate:
    Type: 'AWS::EC2::LaunchTemplate'
    Properties:
      LaunchTemplateName: !Sub '${ShortName}-Template'
      # E3014 - bug in cfn-lint 1.3.0 ?
      LaunchTemplateData:
        # E1040 - bug in cfn-lint 1.3.0 ?
        ImageId: !GetAtt 'SelectAMI.AMI'

  SelectAMI:
    Type: 'Custom::SelectAMI'
    Properties:
      # expected: E1010 - due to missing lambda function in this test
      ServiceToken: !GetAtt 'SelectAMICustomLambda.Arn'
      RandomNumber: !Ref 'BuildId'