Skip to content

Alias support #2411

Closed
Closed

Description

@flomotlik

This is a Feature Proposal

Description

Aliasing functions can help users with including functions deployed through serverless into systems that are not deployed through serverless. To that end we should have a simple configuration option to deploy aliases

functions:
  hello:
    handler: handler.hello
    alias: somealias
functions:
  hello:
    handler: handler.hello
    aliases:
      - somealias
      - anotheralias

Aliases will always point to the latest deployed version. As we don't have versioning support in our Lambda support Aliases are simply a nicer way to name your Lambda Function ARN than using $LATEST.

Similar or dependent issues:

Additional Data

  • _Serverless Framework Version you're using_:
  • _Operating System_:
  • _Stack Trace_:
  • _Provider Error messages_:

Activity

  1. added this to the 1.1 milestone on Oct 17, 2016
  2. kfloz commented on Oct 17, 2016

    @kfloz

    This is great and much needed thanks! If an alias is defined for a function, serverless should use the alias in the relevant provisioned event source mappings instead of the actual ARN

    e.g APIG Integration Requests Lambda config

    Great stuff!

  3. flomotlik commented on Oct 17, 2016

    @flomotlik
    ContributorAuthor

    @kfloz we're not going to use the alias as its not exposed inside of CF. We could not rely solely on built-in CF functions like Ref or GetAtt which would make the code more brittle. Alias support is at this point purely for users to make it easier to set up their infrastructure and point to functions, we're not relying on it internally.

  4. flomotlik commented on Oct 31, 2016

    @flomotlik
    ContributorAuthor

    I had some great conversations about this at SLSConf and the main issue with Aliases here is that because we deploy through Cloudformation there is only one version available, so aliasing doesn't really make a lot of sense here as the LATEST will always point to any alias we can set here. Its even going to be an issue because users might think the alias sticks around or points somewhere else, when in reality it doesn't.

    So I'm going to close this for now and we're not going to implement alias support for now.

  5. removed this from the 1.1 milestone on Oct 31, 2016
  6. mikeplavsky commented on Nov 25, 2016

    @mikeplavsky

    @flomotlik There can be several aliases pointing to the same versions. If there is an alias per Customer, then it allows such things as: 1) Monitoring per Customer 2) Triggering of Lambda function per Customer 3) And finally Lambda knows which Customer called by using context.invoked_function_arn

    So it helps with multi-tenancy a little.

    Though probably aliases used in such a way should be managed separately - not by sls

  7. arabold commented on Dec 15, 2016

    @arabold

    @flomotlik Currently there is no open feature/ticket for alias support in Serverless. Does that mean this is completely off the table for good or is aliasing support still planned?

    We're using Lambda aliases to distinguish dev and prod stages (using sls 0.5.6).

  8. pmuens commented on Dec 16, 2016

    @pmuens
    Contributor

    @mikeplavsky @arabold reopening this one as Lambda versioning was merged recently (see #2676) and aliases might be a good addition here.

    However we need to investigate the comment above about the usefulness when deploying through CloudFormation: #2411 (comment)

    Any feedback or comments about that are appreciated 👍

  9. reopened this on Dec 16, 2016
  10. arabold commented on Dec 16, 2016

    @arabold

    To elaborate on our use case for aliases a bit and keep the discussion going: We have a set of 150 distinct Lambda functions for various modules. Basically our whole backend is server-less and designed around AWS Lambda. With that number of functions it's not practical for us to have different function names for every stage (e.g. append a "-dev", "-user1", "-user2", "-test", etc.). Due to the number of different stages/environments, having dedicated AWS accounts isn't a solution either. We certainly prefer aliases instead. So if "user1" deploys something to his stage "user1", we create a new Lambda version and tag it with "user1". Through API Gateway this stage can be mapped and directly accessed via something like https://api.example.com/user1/function-name. $LATEST is always pointing to the latest version - that's okay, nobody is using it. Version x and y can be completely different branches with different environment variables and configuration. It doesn't matter as we're always accessing Lambdas via their alias, never via a version number. Aliases are also a great solution if we want to create end-user facing versions for our API Gateway. We can label a version "v1" and another one "v2" and distinguish different API versions this way and even update them independently using a single AWS Lambda function.

    SLS 0.5.6 did offer this functionality and it's working nicely for us. For every environment we want to support we have a dedicated stage. AWS Lambda has perfect support for this, too, as it shows the stats for every alias independently. So if you check the stats for alias "test" you can see all invocations, latencies and error rates independently from which version number it was and is. It shows the stats of all versions past and present ever tagged test.

    My request is to bring this functionality back to SLS 1.x. I want to be able to directly map stages/environments to AWS Lambda aliases.

  11. arabold commented on Dec 30, 2016

    @arabold

    I've finally found time to dive deeper into Serverless 1.4. Up to this point we're still on 0.5 and have our own fork that addresses some of the issues left open in the old version.

    From the structure of 1.x it seems the cleanest solution would be to give the user more granular control over the naming of Lambda functions and API Gateway endpoints via two new options in the .yaml config. Here's what I have in mind:

    service: myService
    
    provider:
      # ...
    
    custom:
      stage: ${opt:stage, self:provider.stage}
      region: ${opt:region, self:provider.region}
    
    functions:
      createUser:
        handler: handler.createUser
        name: ${self:service}-myFunc # Overwrite the default Lambda name to NOT include the stage anymore
        alias: ${self:custom.stage} # Instead create an alias that points to the latest deployed version

    The name property would control the Lambda function name. Instead of myService-dev-myFunc it would become myService-myFunc per configuration above.
    The alias property automatically tags the latest deployed version number with the alias name defined, in this case the stage name. But this could be anything the user might want, e.g. v1 vs v2 if a new generation of an API is released, etc.

    To me this seems like a clean solution that fits into the framework without breaking core principles. The events would have to be updated to respect the new name and alias (if an alias is defined the event must trigger the Lambda function with that alias as qualifier instead of $LATEST).

    The final piece would be support for stages in API Gateway (see #2445). This could work implicitly via the alias property but I think we would do better with a separate configuration option that controls the API Gateway API name. This would probably have to go somewhere in the main properties like this (not sure which syntax would make sense here due to CloudFormation):

    service: myService
    
    provider: 
      name: aws
      runtime: nodejs4.3
      stage: dev
      region: us-east-1
      apig:
        name: ${self:service} # custom API name
        stage: ${opt:stage, self:provider.stage} # enable stage support by setting a specific stage name

    Any thoughts?

  12. seanohollaren commented on Jan 6, 2017

    @seanohollaren

    I'll add that my team is very interested in this feature, too. If it's possible to have easy alias support in serverless, that'd be really useful.

  13. HyperBrain commented on Mar 1, 2017

    @HyperBrain
    Contributor

    I'll put an end to this endless discussion now 😜

    I have spent some time on a plugin that solves the alias/stage, and whatever problems. Currently alias deployment of functions and APIG works. Resource management will follow soon. The tests I did so far are quite promising, that the solution is stable. The aliases are now implemented in a similar way that @arabold proposed. They are orthogonal to the stages and can be seen like branches within an environment/stage.

    https://github.com/HyperBrain/serverless-aws-alias

    Please check in the README how this works. The version is currently only available on GitHub until I finished the resources part. Then I will publish a beta version to NPM. But nevertheless, if you have time, you can check it out and tell me if my understanding of aliases hits the spot.

    Known issues in 0.1.0-alpha1:

    • Aliased functions are not yet called from APIG aliased APIs (APIG stages) - will be fixed next
    • Custom resources are not yet managed and should be the same for the deployed aliases - functions and API methods on the other hand can be completely different per stage already, even function configuration like VPC, environment and much more....

    @pmuens I'll keep you updated too about my progress.

  14. pmuens commented on Mar 2, 2017

    @pmuens
    Contributor

    Wow! Nice job @HyperBrain 🎉

    Thanks for the plugin and thanks for keeping us posted! 👍

  15. HyperBrain commented on Mar 2, 2017

    @HyperBrain
    Contributor

    Plugin: Version 0.1.1-alpha1 now features full APIG support. The API resources and deployments as well as the associated lambda permissions are now owned by the aliases. The main stack exports the API Id and the API root resource id. Tested with different source branches with different API endpoints (simulating feature development in a branch) and deployed them to different aliases into a stage. Everything worked as expected.
    Next upcoming feature is the handling of custom user resources, that should be handled in a way that multiple developers can deploy "their" version of a service into an alias without breaking the master alias and other developer's deployments.
    @nicka @erikerikson Would be great to have you as testers too 😄

  16. HyperBrain commented on Mar 23, 2017

    @HyperBrain
    Contributor

    In the meantime 0.3.4-alpha1 supports resources and much more. We tested it internally with some more complex projects.

  17. pmuens commented on May 19, 2017

    @pmuens
    Contributor

    Closing since @HyperBrain provided the alias plugin which solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions