You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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
@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.
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.
@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
@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).
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.
Reacted by Philipp Muens, Kazuya Takahashi, Frank Schmid and Sublated47
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: myServiceprovider:
# ...custom:
stage: ${opt:stage, self:provider.stage}region: ${opt:region, self:provider.region}functions:
createUser:
handler: handler.createUsername: ${self:service}-myFunc # Overwrite the default Lambda name to NOT include the stage anymorealias: ${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: myServiceprovider:
name: awsruntime: nodejs4.3stage: devregion: us-east-1apig:
name: ${self:service} # custom API namestage: ${opt:stage, self:provider.stage} # enable stage support by setting a specific stage name
Any thoughts?
Reacted by Kirill Potekhin, Sublated47, mickeybr and Deluan Quintão
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.
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.
Reacted by Philipp Muens, Andre Rabold, Justin Hamade and Mike Staub
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 😄
Activity
kfloz commentedon Oct 17, 2016
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!
flomotlik commentedon Oct 17, 2016
@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.
flomotlik commentedon Oct 31, 2016
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.
mikeplavsky commentedon Nov 25, 2016
@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_arnSo it helps with multi-tenancy a little.
Though probably aliases used in such a way should be managed separately - not by
slsarabold commentedon Dec 15, 2016
@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).
pmuens commentedon Dec 16, 2016
@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 👍
arabold commentedon Dec 16, 2016
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.$LATESTis always pointing to the latest version - that's okay, nobody is using it. Versionxandycan 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 taggedtest.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.
arabold commentedon Dec 30, 2016
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
.yamlconfig. Here's what I have in mind:The
nameproperty would control the Lambda function name. Instead ofmyService-dev-myFuncit would becomemyService-myFuncper configuration above.The
aliasproperty 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.v1vsv2if 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
aliasproperty 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):Any thoughts?
seanohollaren commentedon Jan 6, 2017
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.
HyperBrain commentedon Mar 1, 2017
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:
@pmuens I'll keep you updated too about my progress.
pmuens commentedon Mar 2, 2017
Wow! Nice job @HyperBrain 🎉
Thanks for the plugin and thanks for keeping us posted! 👍
HyperBrain commentedon Mar 2, 2017
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 😄
HyperBrain commentedon Mar 23, 2017
In the meantime 0.3.4-alpha1 supports resources and much more. We tested it internally with some more complex projects.
pmuens commentedon May 19, 2017
Closing since @HyperBrain provided the
aliasplugin which solves the problem.