Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specfiy existing FunctionName on SAM Template

I'm trying to deploy AWS Lambda function by using SAM. What I want to do is to update exsiting lambda function by deploying local source code.

In order to do that, I specified the existing lambda function name as 'FunctionName' in template.yaml like below. However, 'FunctionName' does only support for creating new function, not updating to existing function. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-functionname

Are there any ways to specify Function Name in SAM in order to update lambda function?

[template.yaml]

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloWorld:
    Type: 'AWS::Serverless::Function'
    Properties:
      FunctionName: 'hello_world'
      Description: ''
      Handler: index.handler
      MemorySize: 256
      Role: 'arn:aws:iam::368834739507:role/lambda_basic_execution'
      Runtime: nodejs6.10
      Timeout: 120
like image 518
Tamajin Avatar asked Feb 11 '18 15:02

Tamajin


1 Answers

Using SAM (and/or CloudFormation), you cannot update existing resources.

SAM (and CloudFormation) create and manage their own resources. All resources specified in the template are going to be created when the stack is created. They cannot be "taken over".

Instead, you should allow SAM (or CloudFormation) to create the Lambda function for you, then update users to reference the new function. After that, you can update your code using SAM.

like image 75
Matt Houser Avatar answered Sep 28 '22 09:09

Matt Houser