How to rename deployed lambda function

I deployed the lambda named as sample_function with below template

service: sample_service

frameworkVersion: '3'

provider:
  name: aws
  runtime: python3.10
  memorySize: 1024
  timeout: 900
  stage: prod 
  region: us-east-1
  iam:
    role: arn:aws:iam::accountId:role/RoleName

functions:
  sample_function:
    handler: dir1/handler.function_name
    name: sample_function
    description: sample function desc
    environment:
      VAR_NAME: ""
    events:
      - schedule: ""
      - cloudwatchLog:
          ""

plugins:
  - serverless-pydeps
package:
  patterns:
    - '!node_modules/**'
    - '!package*.json'
    - '!serverless.yml'
    - '!requirements.txt'

So on next deployment if i want to change the function name from sample_function to test_function how to do it ?

I don’t think you can rename it in the traditional sense. You might not even be able to change the name attribute. If you rename the resource you could probably also change the name but that will deploy a new function then remove the existing one.

@buggy Yes its happening the same, its creating new function with renamed name.