AWS SAM - 'Encountered unsupported property CodeUri' error when deploying packaged template
Asked Answered
N

2

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).

Nag answered 29/8, 2018 at 10:7 Comment(0)
N
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.

Nag answered 29/8, 2018 at 10:7 Comment(1)
Which in turn requires Transform: 'AWS::Serverless-2016-10-31' as per docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…Rudderhead
C
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.

Cnut answered 2/9, 2020 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.