Picci
Picci

Reputation: 17752

Deploy the same function to different endpoint on ASW Lambda

I have a function which I successfully deploy to AWS Lambda using the Serverless framework.

This function relies on some environment variables which I set in the serverless.yml file like this

    provider:
        name: aws
        runtime: nodejs8.10
        stage: ${opt:stage,'dev'}
        region: ${opt:region,'eu-west-1'}
        deploymentBucket:
            name: my-bucket
        environment:
            MY_ENV_VAR: 'the value of my var'

functions:
    myFunction:
        handler: handler.myHandler
        events:
            - http:
                  path: executeFunction
                  method: post

Now I want to deploy the same logic, just with a different value of MY_ENV_VAR to a different endpoint. If I change simply the value of MY_ENV_VAR and then deploy, the endpoint does not change. But even if I change the deploymentBucket and the name of the function, i.e. myFunction, the deployment generates always the same endpoint.

Is it possible to deploy the same function to a different endpoint?

Upvotes: 0

Views: 212

Answers (2)

Jasper Thayer
Jasper Thayer

Reputation: 111

Changing the service name is not a very scalable solution. You should retain the same service name and deploy using a different --stage to get a different endpoint depending on the stage it's deployed to. You can use the stage to manage environment variables so that it can be set to one value on one stage and another value on another stage. See an example in this SO Question. Also, nodejs8.10 is EOL on AWS. Use nodejs10.x instead.

Upvotes: 1

Picci
Picci

Reputation: 17752

Well, after a while I figure out the solution.

The first parameter of the serverless.yml file is service: myService.

Changing that parameter actually generates a deployment which creates different endpoint.

Upvotes: 0

Related Questions