4

I have some lambda functions that have been created before moving to AWS SAM. I would like to update my existing lambda function using AWS SAM. What would be the process of referencing the lambda function in AWS SAM. I have a lambda function already created called: hello.

How would I update the lambda function using AWS SAM? below is my sam template.yaml file

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: CD Demo Lambda
Resources:
  hello:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.7
      CodeUri: ./s3lambda
      FunctionName: hello
      MemorySize: 128
      Timeout: 03       

Bilal Yousaf
  • 414
  • 6
  • 19

3 Answers3

1

As AWS SAM uses Cloudformation for deploying resources.

You need to import the lambdas Importing existing resources into a stack in the cloudformation stack.

samtoddler
  • 8,463
  • 2
  • 26
  • 21
  • thank you for your response. just one question: how would I reference the stack in the template.yaml file? – Bilal Yousaf Jan 27 '21 at 20:51
  • as per the documentation, you start with the template. >During this import, you need to provide a template that describes the entire stack, including the target resources. If existing stack resources are modified in the prepared template, the import fails. – samtoddler Jan 27 '21 at 20:59
0

The documentation states that you cannot import resources to AWS SAM Templates.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
0

The answers here are not so useful for beginners.

If you want to update your AWS Lambda function using SAM-CLI, I guess that you already deployed a function with sam deploy --guided command. SAM helped you to deploy your app with CloudFormation and saved the configuration in the samconfig.toml file.

Next time you can deploy your app just by giving the stack-name and (at least in my case) the S3 Bucket where your Lambda Function is placed.

sam deploy --stack-name YOUR-APP-NAME --s3-bucket YOUR-BUCKET-NAME