AWS::Lambda::Alias
The AWS::Lambda::Alias resource creates an alias that points to the version of an AWS Lambda (Lambda) function
that you specify. Use aliases when you want to control which version of your function
other services or applications invoke. Those services or applications can use your
function's alias so that they don't need to be updated whenever you release a new
version of your function. For more information, see Introduction to
AWS Lambda Aliases in the AWS Lambda Developer Guide.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::Lambda::Alias", "Properties" : { "Description" :String, "FunctionName" :String, "FunctionVersion" :String, "Name" :String, "RoutingConfig" : AliasRoutingConfiguration } }
YAML
Type: AWS::Lambda::Alias Properties: Description:StringFunctionName:StringFunctionVersion:StringName:StringRoutingConfig:AliasRoutingConfiguration
Properties
Description-
Information about the alias, such as its purpose or the Lambda function that is associated with it.
Required: No
Type: String
Update requires: No interruption
FunctionName-
The Lambda function that you want to associate with this alias. You can specify the function's name or its Amazon Resource Name (ARN).
Required: Yes
Type: String
Update requires: Replacement
FunctionVersion-
The version of the Lambda function that you want to associate with this alias.
Required: Yes
Type: String
Update requires: No interruption
Name-
A name for the alias.
Required: Yes
Type: String
Update requires: Replacement
RoutingConfig-
Use this parameter to point your alias to two different function versions, allowing you to dictate what percentage of traffic will invoke each version. For more information, see Routing Traffic to Different Function Versions Using Aliases in the AWS Lambda Developer Guide.
Required: No
Type: AliasRoutingConfiguration
Update requires: No interruption
Return Value
Ref
When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the ARN of the Lambda alias.
For more information about using the Ref function, see Ref.
Examples
Lambda Alias
The following example creates an alias named TestingForMyApp. The alias points to the TestingNewFeature version of the MyFunction Lambda function.
JSON
"AliasForMyApp" : { "Type" : "AWS::Lambda::Alias", "Properties" : { "FunctionName" : { "Ref" : "MyFunction" }, "FunctionVersion" : { "Fn::GetAtt" : [ "TestingNewFeature", "Version" ] }, "Name" : "TestingForMyApp" } }
YAML
AliasForMyApp: Type: AWS::Lambda::Alias Properties: FunctionName: Ref: "MyFunction" FunctionVersion: Fn::GetAtt: - "TestingNewFeature" - "Version" Name: "TestingForMyApp"
Lambda Alias Update Policy
The following example defines an update policy for an alias.
JSON
"Alias": { "Type": "AWS::Lambda::Alias", "Properties": { "FunctionName": { "Ref": "LambdaFunction" }, "FunctionVersion": { "Fn::GetAtt": [ "FunctionVersionTwo", "Version" ] }, "Name": "MyAlias" }, "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "CodeDeployApplication" }, "DeploymentGroupName": { "Ref": "CodeDeployDeploymentGroup" }, "BeforeAllowTrafficHook": { "Ref": "PreHookLambdaFunction" }, "AfterAllowTrafficHook": { "Ref": "PreHookLambdaFunction" } } } }
YAML
Alias: Type: AWS::Lambda::Alias Properties: FunctionName: !Ref LambdaFunction FunctionVersion: !GetAtt FunctionVersionTwo.Version Name: MyAlias UpdatePolicy: CodeDeployLambdaAliasUpdate: ApplicationName: !Ref CodeDeployApplication DeploymentGroupName: !Ref CodeDeployDeploymentGroup BeforeAllowTrafficHook: !Ref PreHookLambdaFunction AfterAllowTrafficHook: !Ref PreHookLambdaFunction
