Repository: aws-cloudformation/cfn-lint

Issue:
Support for the docker lambda runtime
cfn-lint 0.43.0

This is a feature request for supporting docker lambda sam templates.

Please provide as much information as possible:
* SAM templates produced by aws-sam-cli with the docker deploy option don't pass validation

Running on the template.yaml in the base directory outputs the following:
```
% cfn-lint template.yaml                  
E0001 Error transforming template: Resource with id [HelloWorldFunction] is invalid. 'ImageUri' must be set.
template.yaml:1:1

```

Running on the packaged template at `.aws-sam/build/template.yaml` produces the following:
```
E3002 Invalid Property Resources/HelloWorldFunction/Properties/Code/ImageUri
.aws-sam/build/template.yaml:12:3

E3002 Invalid Property Resources/HelloWorldFunction/Properties/PackageType
.aws-sam/build/template.yaml:12:3

E3003 Property Handler missing at Resources/HelloWorldFunction/Properties
.aws-sam/build/template.yaml:12:3

E3003 Property Runtime missing at Resources/HelloWorldFunction/Properties
.aws-sam/build/template.yaml:12:3

```


Discussion:
could you include your template?

The second half likely involves https://github.com/aws-cloudformation/cfn-python-lint/issues/1219 since no [Resource Specfications](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-resource-specification.html) have been released for weeks

The first half may be fixed by upgrading SAM:
`pip3 install aws-sam-translator --upgrade`
[fixes for the second half just merged in yesterday](https://github.com/aws-cloudformation/cfn-python-lint/pull/1831), so the second half will be fixed in the next release
This template is working with the newest version of the sam translator.  If you leave that value out you will get the error that you have specified but that error is coming from https://github.com/aws/serverless-application-model if you believe it shouldn't exist we may need to create an issue there.

```
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: 123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest
      ImageConfig:
        Command:
          - "app.lambda_handler"
        EntryPoint:
          - "entrypoint1"
        WorkingDirectory: "workDir"
```

v0.44.2 is out and includes the 2nd half fixes that @PatMyron mentioned.
@kddejong - I think this needs to be re-opened. The original issue is still present. It was fixed in `sam validate` [here](https://github.com/aws/aws-sam-cli/pull/2892). From that fix, [here ](https://github.com/aws/aws-sam-cli/blob/develop/tests/functional/commands/validate/lib/models/function_with_image_in_metadata.yaml) is a test that will fail cfn-lint.

The problem is that cfn-lint passes the template as-is to the transalator, but sam will deploy an image to ECR then add an `ImageUri` before translating.

Resolving patch:
diff --git a/src/cfnlint/transform.py b/src/cfnlint/transform.py
--- a/src/cfnlint/transform.py
+++ b/src/cfnlint/transform.py
@@ -76,7 +76,10 @@ def _replace_local_codeuri(self):
 
             if resource_type == 'AWS::Serverless::Function':
 
-                Transform._update_to_s3_uri('CodeUri', resource_dict)
+                if resource_dict.get('PackageType') == 'Image':
+                    Transform._update_to_s3_uri('ImageUri', resource_dict)
+                else:
+                    Transform._update_to_s3_uri('CodeUri', resource_dict)
                 auto_publish_alias = resource_dict.get('AutoPublishAlias')
                 if isinstance(auto_publish_alias, dict):
                     if len(auto_publish_alias) == 1:


Test patch:
diff --git a/test/fixtures/templates/good/transform/function_using_image.yaml b/test/fixtures/templates/good/transform/function_using_image.yaml
new file mode 100644
--- /dev/null
+++ b/test/fixtures/templates/good/transform/function_using_image.yaml
@@ -0,0 +1,11 @@
+AWSTemplateFormatVersion: '2010-09-09'
+Transform: AWS::Serverless-2016-10-31
+Resources:
+  HelloWorldFunction:
+    Type: AWS::Serverless::Function
+    Properties:
+      PackageType: Image
+    Metadata:
+      DockerTag: nodejs14.x-v1
+      DockerContext: ./hello-world
+      Dockerfile: Dockerfile
\ No newline at end of file
diff --git a/test/unit/module/transform/test_transform.py b/test/unit/module/transform/test_transform.py
--- a/test/unit/module/transform/test_transform.py
+++ b/test/unit/module/transform/test_transform.py
@@ -51,3 +51,12 @@ def test_parameter_for_autopublish_version_bad(self):
         transformed_template = Transform(filename, template, region)
         transformed_template.transform_template()
         self.assertDictEqual(transformed_template._parameters, {})
+
+    def test_test_function_using_image_good(self):
+        """Test Parameter is created for autopublish version run"""
+        filename = 'test/fixtures/templates/good/transform/function_using_image.yaml'
+        region = 'us-east-1'
+        template = cfn_yaml.load(filename)
+        transformed_template = Transform(filename, template, region)
+        transformed_template.transform_template()
+        self.assertDictEqual(transformed_template._parameters, {})