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.

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

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.

Review your AWS Lambda settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

template-v2.yml#L55
    Type: AWS::Lambda::Alias
    Properties:
      FunctionName: !Ref HelloFunction
      FunctionVersion: !GetAtt HelloVersion2.Version
      Name: PROD
      RoutingConfig:
template-v0.yml#L47
    Type: AWS::Lambda::Alias
    Properties:
      FunctionName: !Ref HelloFunction
      FunctionVersion: !GetAtt HelloVersion1.Version
      Name: PROD
sam-prod.yml#L26
    Type: AWS::Lambda::Alias
    DeletionPolicy: Retain
    DependsOn: CheckStatusVersion2
    Properties:
      FunctionName: myapi-CheckStatus
      FunctionVersion: !GetAtt CheckStatusVersion2.Version
version.yml#L22
    Type: AWS::Lambda::Alias
    Properties:
      FunctionName: !Ref MacroFunctionArn
      FunctionVersion: !GetAtt Version.Version
      Name: !Ref MacroVersion

gateway-stage.cf.yml#L14
    Type: AWS::Lambda::Alias
    Properties:
      FunctionName:
        Fn::ImportValue:
                !Sub "${LambdaStack}-lambdaArn"
      FunctionVersion:
cloudformation.json#L48
            "Type" : "AWS::Lambda::Alias",
            "DependsOn" : "FindGameLambda",
            "Properties" : {
                "Name"              : "dev",
                "FunctionName"      : "FindGame",
                "FunctionVersion"   : "$LATEST"
sam-template.json#L45
            "Type": "AWS::Lambda::Alias",
            "Properties": {
                "FunctionName": { "Ref": "GetNotesFunction" },
                "FunctionVersion": { "Fn::GetAtt": ["GetNotesVersion", "Version"] },
                "Name": "live"
            }
function_with_custom_codedeploy_deployment_preference.json#L36
      "Type": "AWS::Lambda::Alias",
      "UpdatePolicy": {
        "CodeDeployLambdaAliasUpdate": {
          "ApplicationName": {
            "Ref": "ServerlessDeploymentApplication"
          },
function_with_custom_codedeploy_deployment_preference.json#L36
      "Type": "AWS::Lambda::Alias",
      "UpdatePolicy": {
        "CodeDeployLambdaAliasUpdate": {
          "ApplicationName": {
            "Ref": "ServerlessDeploymentApplication"
          },
function_with_custom_codedeploy_deployment_preference.json#L36
      "Type": "AWS::Lambda::Alias",
      "UpdatePolicy": {
        "CodeDeployLambdaAliasUpdate": {
          "ApplicationName": {
            "Ref": "ServerlessDeploymentApplication"
          },

Parameters

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.