0
votes

I am new to serverless framework. I was trying to deploy my code to lambda using serverless.

service:
  name: store-consumer

provider: 
  name: aws
  runtime: nodejs8.10
  stage: dev
  region: ap-XXXXXX-1

functions:
  lambda:
    handler: index.handler

The content of the serverless.yml file is as given above. But when I hit 'sls deploy' in terminal my code is zipped and uploaded to an s3 bucket. How do I deploy my code to the corresponding lambda using serverless?

I assume I 'll have to give some credentials for the lambda, but how do I do that in the .yml file?! What am I not getting correctly?

1
According to the given, serverless config, a lambda function would be created by default with name as "store-consumer-lambda" which includes the service name and the function name that you have passed. let me know if you could not find this function in aws console in the region that you have created. - Siddharth Yadav
Yes! There is a lambda named 'store-consumer-dev-lambda'(I assume the 'stage' and functions->lamda in the .yml file is used to create the lambda function name). Is there a way that we can specify this lambda name? Because we already have a lambda that is linked to a Kinesis stream and I do not want to create a new one. @SiddharthYadav - codename_47
I don't get your question very well. Your lambda's name is a concatenation of serviceName(store-consumer)-functionName(lambda) and the environment(dev). So it should be something like store-consumer-lambda-dev (not necessarily in this order, need to double check on that). What exactly do you want to achieve? - Thales Minussi
I want to set the lambda name explicitly, without depending on the functionName and environment. Say I want to set the lambda name to 'store-consumer', is this possible? @SiddharthYadav - codename_47
Nope, that's not possible - Thales Minussi

1 Answers

0
votes

You can specify the Lambda function name explicitly using the name field. Example:

service:
  name: store-consumer

provider: 
  name: aws
  runtime: nodejs8.10
  stage: dev
  region: ap-XXXXXX-1

functions:
  lambda:
    handler: index.handler
    name: myfunc

With this config file your deployed Lambda function will have the name myfunc.

See line 129 in https://serverless.com/framework/docs/providers/aws/guide/serverless.yml/.

Using the name of an already existing Lambda function will not work, you still have to delete old the Lambda function beforehand.