AWS::Lambda::Alias - AWS CloudFormation

AWS::Lambda::Alias

The AWS::Lambda::Alias resource creates an alias for a Lambda function version. Use aliases to provide clients with a function identifier that you can update to invoke a different version.

You can also map an alias to split invocation requests between two versions. Use the RoutingConfig parameter to specify a second version and the percentage of invocation requests that it receives.

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, "ProvisionedConcurrencyConfig" : ProvisionedConcurrencyConfiguration, "RoutingConfig" : AliasRoutingConfiguration } }

Properties

Description

A description of the alias.

Required: No

Type: String

Minimum: 0

Maximum: 256

Update requires: No interruption

FunctionName

The name or ARN of the Lambda function.

Name formats
  • Function name - MyFunction.

  • Function ARN - arn:aws:lambda:us-west-2:123456789012:function:MyFunction.

  • Partial ARN - 123456789012:function:MyFunction.

The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.

Required: Yes

Type: String

Pattern: (arn:(aws[a-zA-Z-]*)?:lambda:)?([a-z]{2}(-gov)?-[a-z]+-\d{1}:)?(\d{12}:)?(function:)?([a-zA-Z0-9-_]+)(:(\$LATEST|[a-zA-Z0-9-_]+))?

Minimum: 1

Maximum: 140

Update requires: Replacement

FunctionVersion

The function version that the alias invokes.

Required: Yes

Type: String

Pattern: (\$LATEST|[0-9]+)

Minimum: 1

Maximum: 1024

Update requires: No interruption

Name

The name of the alias.

Required: Yes

Type: String

Pattern: (?!^[0-9]+$)([a-zA-Z0-9-_]+)

Minimum: 1

Maximum: 128

Update requires: Replacement

ProvisionedConcurrencyConfig

Specifies a provisioned concurrency configuration for a function's alias.

Required: No

Type: ProvisionedConcurrencyConfiguration

Update requires: No interruption

RoutingConfig

The routing configuration of the alias.

Required: No

Type: AliasRoutingConfiguration

Update requires: No interruption

Return values

Ref

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the resource ARN.

For more information about using the Ref function, see Ref.

Fn::GetAtt

The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.

AliasArn

The Amazon Resource Name (ARN) of the alias.

Examples

Alias

A Node.js function with a version and alias.

YAML

Resources: function: Type: AWS::Lambda::Function Properties: Handler: index.handler Role: arn:aws:iam::123456789012:role/lambda-role Code: ZipFile: | exports.handler = function(event){ console.log(JSON.stringify(event, null, 2)) const response = { statusCode: 200, body: JSON.stringify('Hello from Lambda!') } return response }; Runtime: nodejs18.x TracingConfig: Mode: Active version: Type: AWS::Lambda::Version Properties: FunctionName: !Ref function Description: v1 alias: Type: AWS::Lambda::Alias Properties: FunctionName: !Ref function FunctionVersion: !GetAtt version.Version Name: BLUE

Weighted Alias

An alias that routes requests to two versions.

YAML

Resources: function: Type: AWS::Lambda::Function Properties: Handler: index.handler Role: arn:aws:iam::123456789012:role/lambda-role Code: ZipFile: | exports.handler = function(event){ console.log(JSON.stringify(event, null, 2)) const response = { statusCode: 200, body: JSON.stringify('Hello again from Lambda!') } return response } Runtime: nodejs18.x TracingConfig: Mode: Active version: Type: AWS::Lambda::Version Properties: FunctionName: !Ref function Description: v1 newVersion: Type: AWS::Lambda::Version Properties: FunctionName: !Ref function Description: v2 alias: Type: AWS::Lambda::Alias Properties: FunctionName: !Ref function FunctionVersion: !GetAtt newVersion.Version Name: BLUE RoutingConfig: AdditionalVersionWeights: - FunctionVersion: !GetAtt version.Version FunctionWeight: 0.5