aws-cdk-lib.aws_lambda.Alias

class Alias (construct)

LanguageType name
.NETAmazon.CDK.AWS.Lambda.Alias
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awslambda#Alias
Javasoftware.amazon.awscdk.services.lambda.Alias
Pythonaws_cdk.aws_lambda.Alias
TypeScript (source)aws-cdk-lib » aws_lambda » Alias

Implements IConstruct, IDependable, IResource, IFunction, IConnectable, IGrantable, IClientVpnConnectionHandler, IAlias

A new alias to a particular version of a Lambda function.

Example

const lambdaCode = lambda.Code.fromCfnParameters();
const func = new lambda.Function(this, 'Lambda', {
  code: lambdaCode,
  handler: 'index.handler',
  runtime: lambda.Runtime.NODEJS_14_X,
});
// used to make sure each CDK synthesis produces a different Version
const version = func.currentVersion;
const alias = new lambda.Alias(this, 'LambdaAlias', {
  aliasName: 'Prod',
  version,
});

new codedeploy.LambdaDeploymentGroup(this, 'DeploymentGroup', {
  alias,
  deploymentConfig: codedeploy.LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE,
});

Initializer

new Alias(scope: Construct, id: string, props: AliasProps)

Parameters

  • scope Construct
  • id string
  • props AliasProps

Construct Props

NameTypeDescription
aliasNamestringName of this alias.
versionIVersionFunction version this alias refers to.
additionalVersions?VersionWeight[]Additional versions with individual weights this alias points to.
description?stringDescription for the alias.
maxEventAge?DurationThe maximum age of a request that Lambda sends to a function for processing.
onFailure?IDestinationThe destination for failed invocations.
onSuccess?IDestinationThe destination for successful invocations.
provisionedConcurrentExecutions?numberSpecifies a provisioned concurrency configuration for a function's alias.
retryAttempts?numberThe maximum number of times to retry when the function returns an error.

aliasName

Type: string

Name of this alias.


version

Type: IVersion

Function version this alias refers to.

Use lambda.currentVersion to reference a version with your latest changes.


additionalVersions?

Type: VersionWeight[] (optional, default: No additional versions)

Additional versions with individual weights this alias points to.

Individual additional version weights specified here should add up to (less than) one. All remaining weight is routed to the default version.

For example, the config is

version: "1" additionalVersions: [{ version: "2", weight: 0.05 }]

Then 5% of traffic will be routed to function version 2, while the remaining 95% of traffic will be routed to function version 1.


description?

Type: string (optional, default: No description)

Description for the alias.


maxEventAge?

Type: Duration (optional, default: Duration.hours(6))

The maximum age of a request that Lambda sends to a function for processing.

Minimum: 60 seconds Maximum: 6 hours


onFailure?

Type: IDestination (optional, default: no destination)

The destination for failed invocations.


onSuccess?

Type: IDestination (optional, default: no destination)

The destination for successful invocations.


provisionedConcurrentExecutions?

Type: number (optional, default: No provisioned concurrency)

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


retryAttempts?

Type: number (optional, default: 2)

The maximum number of times to retry when the function returns an error.

Minimum: 0 Maximum: 2

Properties

NameTypeDescription
aliasNamestringName of this alias.
architectureArchitectureThe architecture of this Lambda Function.
canCreatePermissionsbooleanWhether the addPermission() call adds any permissions.
connectionsConnectionsAccess the Connections object.
envResourceEnvironmentThe environment this resource belongs to.
functionArnstringARN of this alias.
functionNamestringARN of this alias.
grantPrincipalIPrincipalThe principal this Lambda Function is running as.
isBoundToVpcbooleanWhether or not this Lambda function was bound to a VPC.
lambdaIFunctionThe underlying IFunction.
latestVersionIVersionThe $LATEST version of this function.
nodeNodeThe tree node.
permissionsNodeNodeThe construct node where permissions are attached.
qualifierstringThe qualifier of the version or alias of this function.
resourceArnsForGrantInvokestring[]The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().
stackStackThe stack in which this resource is defined.
versionIVersionThe underlying Lambda function version.
role?IRoleThe IAM role associated with this function.

aliasName

Type: string

Name of this alias.


architecture

Type: Architecture

The architecture of this Lambda Function.


canCreatePermissions

Type: boolean

Whether the addPermission() call adds any permissions.

True for new Lambdas, false for version $LATEST and imported Lambdas from different accounts.


connections

Type: Connections

Access the Connections object.

Will fail if not a VPC-enabled Lambda Function


env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


functionArn

Type: string

ARN of this alias.

Used to be able to use Alias in place of a regular Lambda. Lambda accepts ARNs everywhere it accepts function names.


functionName

Type: string

ARN of this alias.

Used to be able to use Alias in place of a regular Lambda. Lambda accepts ARNs everywhere it accepts function names.


grantPrincipal

Type: IPrincipal

The principal this Lambda Function is running as.


isBoundToVpc

Type: boolean

Whether or not this Lambda function was bound to a VPC.

If this is is false, trying to access the connections object will fail.


lambda

Type: IFunction

The underlying IFunction.


latestVersion

Type: IVersion

The $LATEST version of this function.

Note that this is reference to a non-specific AWS Lambda version, which means the function this version refers to can return different results in different invocations.

To obtain a reference to an explicit version which references the current function configuration, use lambdaFunction.currentVersion instead.


node

Type: Node

The tree node.


permissionsNode

Type: Node

The construct node where permissions are attached.


qualifier

Type: string

The qualifier of the version or alias of this function.

A qualifier is the identifier that's appended to a version or alias ARN.


resourceArnsForGrantInvoke

Type: string[]

The ARN(s) to put into the resource field of the generated IAM policy for grantInvoke().


stack

Type: Stack

The stack in which this resource is defined.


version

Type: IVersion

The underlying Lambda function version.


role?

Type: IRole (optional)

The IAM role associated with this function.

Undefined if the function was imported without a role.

Methods

NameDescription
addAutoScaling(options)Configure provisioned concurrency autoscaling on a function alias.
addEventSource(source)Adds an event source to this function.
addEventSourceMapping(id, options)Adds an event source that maps to this AWS Lambda function.
addFunctionUrl(options?)Adds a url to this lambda function.
addPermission(id, permission)Adds a permission to the Lambda resource policy.
addToRolePolicy(statement)Adds a statement to the IAM role assumed by the instance.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
configureAsyncInvoke(options)Configures options for asynchronous invocation.
considerWarningOnInvokeFunctionPermissions(_scope, _action)A warning will be added to functions under the following conditions: - permissions that include lambda:InvokeFunction are added to the unqualified function.
grantInvoke(grantee)Grant the given identity permissions to invoke this Lambda.
grantInvokeUrl(grantee)Grant the given identity permissions to invoke this Lambda Function URL.
metric(metricName, props?)Return the given named metric for this Function.
metricDuration(props?)How long execution of this Lambda takes.
metricErrors(props?)How many invocations of this Lambda fail.
metricInvocations(props?)How often this Lambda is invoked.
metricThrottles(props?)How often this Lambda is throttled.
toString()Returns a string representation of this construct.
static fromAliasAttributes(scope, id, attrs)

addAutoScaling(options)

public addAutoScaling(options: AutoScalingOptions): IScalableFunctionAttribute

Parameters

  • options AutoScalingOptions — Autoscaling options.

Returns

  • IScalableFunctionAttribute

Configure provisioned concurrency autoscaling on a function alias.

Returns a scalable attribute that can call scaleOnUtilization() and scaleOnSchedule().


addEventSource(source)

public addEventSource(source: IEventSource): void

Parameters

  • source IEventSource

Adds an event source to this function.

Event sources are implemented in the @aws-cdk/aws-lambda-event-sources module.

The following example adds an SQS Queue as an event source:

import { SqsEventSource } from '@aws-cdk/aws-lambda-event-sources';
myFunction.addEventSource(new SqsEventSource(myQueue));

addEventSourceMapping(id, options)

public addEventSourceMapping(id: string, options: EventSourceMappingOptions): EventSourceMapping

Parameters

  • id string
  • options EventSourceMappingOptions

Returns

  • EventSourceMapping

Adds an event source that maps to this AWS Lambda function.


addFunctionUrl(options?)

public addFunctionUrl(options?: FunctionUrlOptions): FunctionUrl

Parameters

  • options FunctionUrlOptions

Returns

  • FunctionUrl

Adds a url to this lambda function.


addPermission(id, permission)

public addPermission(id: string, permission: Permission): void

Parameters

  • id string — The id for the permission construct.
  • permission Permission — The permission to grant to this Lambda function.

Adds a permission to the Lambda resource policy.

See also: [Permission for details.](Permission for details.)


addToRolePolicy(statement)

public addToRolePolicy(statement: PolicyStatement): void

Parameters

  • statement PolicyStatement

Adds a statement to the IAM role assumed by the instance.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


configureAsyncInvoke(options)

public configureAsyncInvoke(options: EventInvokeConfigOptions): void

Parameters

  • options EventInvokeConfigOptions

Configures options for asynchronous invocation.


considerWarningOnInvokeFunctionPermissions(_scope, _action)

public considerWarningOnInvokeFunctionPermissions(_scope: Construct, _action: string): void

Parameters

  • _scope Construct
  • _action string

A warning will be added to functions under the following conditions: - permissions that include lambda:InvokeFunction are added to the unqualified function.

  • function.currentVersion is invoked before or after the permission is created.

This applies only to permissions on Lambda functions, not versions or aliases. This function is overridden as a noOp for QualifiedFunctionBase.


grantInvoke(grantee)

public grantInvoke(grantee: IGrantable): Grant

Parameters

  • grantee IGrantable

Returns

  • Grant

Grant the given identity permissions to invoke this Lambda.


grantInvokeUrl(grantee)

public grantInvokeUrl(grantee: IGrantable): Grant

Parameters

  • grantee IGrantable

Returns

  • Grant

Grant the given identity permissions to invoke this Lambda Function URL.


metric(metricName, props?)

public metric(metricName: string, props?: MetricOptions): Metric

Parameters

  • metricName string
  • props MetricOptions

Returns

  • Metric

Return the given named metric for this Function.


metricDuration(props?)

public metricDuration(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

How long execution of this Lambda takes.

Average over 5 minutes


metricErrors(props?)

public metricErrors(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

How many invocations of this Lambda fail.

Sum over 5 minutes


metricInvocations(props?)

public metricInvocations(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

How often this Lambda is invoked.

Sum over 5 minutes


metricThrottles(props?)

public metricThrottles(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

How often this Lambda is throttled.

Sum over 5 minutes


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromAliasAttributes(scope, id, attrs)

public static fromAliasAttributes(scope: Construct, id: string, attrs: AliasAttributes): IAlias

Parameters

  • scope Construct
  • id string
  • attrs AliasAttributes

Returns

  • IAlias