AWS Lambda Alias
This page shows how to write Terraform and CloudFormation for Lambda Alias and write them securely.
aws_lambda_alias (Terraform)
The Alias in Lambda can be configured in Terraform with the resource name aws_lambda_alias
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
-
arn
optional computed - string -
description
optional - string -
function_name
required - string -
function_version
required - string -
id
optional computed - string -
invoke_arn
optional computed - string -
name
required - string -
routing_config
list block-
additional_version_weights
optional - map from string to number
-
Explanation in Terraform Registry
Creates a Lambda function alias. Creates an alias that points to the specified Lambda function version. For information about Lambda and how to use it, see [What is AWS Lambda?][1] For information about function aliases, see [CreateAlias][2] and [AliasRoutingConfiguration][3] in the API docs.
Tips: Best Practices for The Other AWS Lambda Resources
In addition to the aws_lambda_permission, AWS Lambda has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_lambda_permission
Ensure to limit your Lambda function permission as much as possible
It is better for limiting the Lambda function permission to set `source_arn` if the ARN can be specified to grant permissions.
AWS::Lambda::Alias (CloudFormation)
The Alias in Lambda can be configured in CloudFormation with the resource name AWS::Lambda::Alias
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::Lambda::Alias
Properties:
FunctionName: !Ref HelloFunction
FunctionVersion: !GetAtt HelloVersion2.Version
Name: PROD
RoutingConfig:
Type: AWS::Lambda::Alias
Properties:
FunctionName: !Ref HelloFunction
FunctionVersion: !GetAtt HelloVersion1.Version
Name: PROD
Type: AWS::Lambda::Alias
DeletionPolicy: Retain
DependsOn: CheckStatusVersion2
Properties:
FunctionName: myapi-CheckStatus
FunctionVersion: !GetAtt CheckStatusVersion2.Version
Type: AWS::Lambda::Alias
Properties:
FunctionName: !Ref MacroFunctionArn
FunctionVersion: !GetAtt Version.Version
Name: !Ref MacroVersion
Type: AWS::Lambda::Alias
Properties:
FunctionName:
Fn::ImportValue:
!Sub "${LambdaStack}-lambdaArn"
FunctionVersion:
"Type" : "AWS::Lambda::Alias",
"DependsOn" : "FindGameLambda",
"Properties" : {
"Name" : "dev",
"FunctionName" : "FindGame",
"FunctionVersion" : "$LATEST"
"Type": "AWS::Lambda::Alias",
"Properties": {
"FunctionName": { "Ref": "GetNotesFunction" },
"FunctionVersion": { "Fn::GetAtt": ["GetNotesVersion", "Version"] },
"Name": "live"
}
"Type": "AWS::Lambda::Alias",
"UpdatePolicy": {
"CodeDeployLambdaAliasUpdate": {
"ApplicationName": {
"Ref": "ServerlessDeploymentApplication"
},
"Type": "AWS::Lambda::Alias",
"UpdatePolicy": {
"CodeDeployLambdaAliasUpdate": {
"ApplicationName": {
"Ref": "ServerlessDeploymentApplication"
},
"Type": "AWS::Lambda::Alias",
"UpdatePolicy": {
"CodeDeployLambdaAliasUpdate": {
"ApplicationName": {
"Ref": "ServerlessDeploymentApplication"
},
Parameters
-
Description
optional - String -
FunctionName
required - String -
FunctionVersion
required - String -
Name
required - String -
ProvisionedConcurrencyConfig
optional - ProvisionedConcurrencyConfiguration -
RoutingConfig
optional - AliasRoutingConfiguration
Explanation in CloudFormation Registry
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.
Frequently asked questions
What is AWS Lambda Alias?
AWS Lambda Alias is a resource for Lambda of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Lambda Alias?
For CloudFormation, the mcnamarabrian/native-cf-lambda-aliasing, mcnamarabrian/native-cf-lambda-aliasing and NachoColl/dotnet-cf4dotnet source code examples are useful. See the CloudFormation Example section for further details.