7

After migrating a CloudFormation template to AWS SAM approach, when deploying template created with aws cloudformation package, in CloudFormation I get error

Encountered unsupported property CodeUri

on all Lambda functions that are included in the template.

After investigation, it's clear that CodeUri property is not removed from the packaged template and AWS::Lambda::Function type doesn't support CodeUri property, although proper resources are uploaded to S3 as part of the package process (so package as such works).

Lech Migdal
  • 3,828
  • 5
  • 36
  • 63

2 Answers2

12

The reason for AWS SAM not removing CodeUri is incorrect resource type - it should be AWS::Serverless::Function and not AWS::Lambda::Function.

After this change, CodeUri is removed from the packaged template.

Lech Migdal
  • 3,828
  • 5
  • 36
  • 63
  • 1
    Which in turn requires `Transform: 'AWS::Serverless-2016-10-31'` as per https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-cli-package.html – Grzegorz Oledzki Jan 31 '19 at 22:51
0

You just should set the path to your function file in a proper format with Code, S3Bucket and S3Key keys:

Function:
  Type: 'AWS::Lambda::Function'
  Properties
    //other properties
    Code:
      S3Bucket: bucketName
      S3Key: myFunction.jar

Docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-code

In my case, I was creating a stack with existing resources (import resources), and there AWS::Serverless::Function type with its CodeUri isn't supported.

nikiforovpizza
  • 487
  • 1
  • 7
  • 13