How to get a function's name from another function

Hi,
I would like to invoke a lambda function from another lambda function. I am using the following code:

def list(event, context):
    #function code

def dispatcher(event, context):
    client = boto3.client('lambda')
    response = client.invoke(
        FunctionName='list'
    )
   return {
    "response": response
   }

But I am getting the following error:

An error occurred (ResourceNotFoundException) when calling the Invoke operation: Function not found: arn:aws:lambda:eu-west-1:xxxxxxxxx:function:list

I have checked and when I deploy the server, the arn for the function is
arn:aws:lambda:eu-west-1:0xxxxxxxxx:function:name-of-service-dev-list

Is there a way to get either the arn or the full name ([service_name]-[env]-[function_name]) from another function?

Thanks.

I’m also super keen to know the answer to this?

I don’t have my experience with python, but it should be a similar process. I use a serverless.yml like below:

service: my-service
provider:
  name: aws
  runtime: nodejs4.3
custom:
  writeEnvVars:
    LAMBDA_NAME: ${self:service}-${opt:stage}-myLambda

plugins:
  - serverless-plugin-write-env-vars

The serverless-plugin-write-env-vars plugin then creates a .env file and includes it in your code package. You can then load the .env file with something like python-dotenv. Once you’ve done this you can get the name like this LAMBDA_NAME = os.environ.get("LAMBDA_NAME")

2 Likes