Alias L2 construct
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_LATEST,
});
// 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,
});
lambda_code = lambda_.Code.from_cfn_parameters()
func = lambda_.Function(self, "Lambda",
code=lambda_code,
handler="index.handler",
runtime=lambda_.Runtime.NODEJS_LATEST
)
# used to make sure each CDK synthesis produces a different Version
version = func.current_version
alias = lambda_.Alias(self, "LambdaAlias",
alias_name="Prod",
version=version
)
codedeploy.LambdaDeploymentGroup(self, "DeploymentGroup",
alias=alias,
deployment_config=codedeploy.LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE
)
CfnParametersCode lambdaCode = Code.fromCfnParameters();
Function func = Function.Builder.create(this, "Lambda")
.code(lambdaCode)
.handler("index.handler")
.runtime(Runtime.NODEJS_LATEST)
.build();
// used to make sure each CDK synthesis produces a different Version
Version version = func.getCurrentVersion();
Alias alias = Alias.Builder.create(this, "LambdaAlias")
.aliasName("Prod")
.version(version)
.build();
LambdaDeploymentGroup.Builder.create(this, "DeploymentGroup")
.alias(alias)
.deploymentConfig(LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE)
.build();
// Install: dotnet add package Amazon.CDK.Lib
var lambdaCode = Code.FromCfnParameters();
var func = new Function(this, "Lambda", new FunctionProps {
Code = lambdaCode,
Handler = "index.handler",
Runtime = Runtime.NODEJS_LATEST
});
// used to make sure each CDK synthesis produces a different Version
var version = func.CurrentVersion;
var alias = new Alias(this, "LambdaAlias", new AliasProps {
AliasName = "Prod",
Version = version
});
new LambdaDeploymentGroup(this, "DeploymentGroup", new LambdaDeploymentGroupProps {
Alias = alias,
DeploymentConfig = LambdaDeploymentConfig.LINEAR_10PERCENT_EVERY_1MINUTE
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
lambdaCode := lambda.Code_FromCfnParameters()
func := lambda.NewFunction(this, jsii.String("Lambda"), &FunctionProps{
Code: lambdaCode,
Handler: jsii.String("index.handler"),
Runtime: lambda.Runtime_NODEJS_LATEST(),
})
// used to make sure each CDK synthesis produces a different Version
version := func.currentVersion
alias := lambda.NewAlias(this, jsii.String("LambdaAlias"), &AliasProps{
AliasName: jsii.String("Prod"),
Version: Version,
})
codedeploy.NewLambdaDeploymentGroup(this, jsii.String("DeploymentGroup"), &LambdaDeploymentGroupProps{
Alias: Alias,
DeploymentConfig: codedeploy.LambdaDeploymentConfig_LINEAR_10PERCENT_EVERY_1MINUTE(),
})
Initializer
new Alias(scope: Construct, id: string, props: AliasProps)
Alias(scope: Construct, id: str, props: AliasProps)
new Alias(Construct scope, String id, AliasProps props)
new Alias(Construct scope, string id, AliasProps props)
NewAlias(Scope Construct, Id *string, Props AliasProps)
Construct Props
additionalVersionsVersionWeight[]additional_versionstyping.List[VersionWeight]additionalVersionsList<VersionWeight>AdditionalVersionsVersionWeight[]AdditionalVersions*[]VersionWeight= No additional versions#notes
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.
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description#maxEventAgeDurationmax_event_ageDurationmaxEventAgeDurationMaxEventAgeDurationMaxEventAgeDuration= Duration.hours(6)#Minimum: 60 seconds Maximum: 6 hours
onFailureIDestinationon_failureIDestinationonFailureIDestinationOnFailureIDestinationOnFailureIDestination= no destination#onSuccessIDestinationon_successIDestinationonSuccessIDestinationOnSuccessIDestinationOnSuccessIDestination= no destination#provisionedConcurrentExecutionsnumberprovisioned_concurrent_executionsint | floatprovisionedConcurrentExecutionsNumberProvisionedConcurrentExecutionsdoubleProvisionedConcurrentExecutions*float64= No provisioned concurrency#retryAttemptsnumberretry_attemptsint | floatretryAttemptsNumberRetryAttemptsdoubleRetryAttempts*float64= 2#Minimum: 0 Maximum: 2
Properties
aliasRefAliasReferencealias_refAliasReferencealiasRefAliasReferenceAliasRefAliasReferenceAliasRefAliasReferencerequired#architectureArchitecturearchitectureArchitecturearchitectureArchitectureArchitectureArchitectureArchitectureArchitecturerequired#connectionsConnectionsconnectionsConnectionsconnectionsConnectionsConnectionsConnectionsConnectionsConnectionsrequired#Will fail if not a VPC-enabled Lambda Function
envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
Used to be able to use Alias in place of a regular Lambda. Lambda accepts ARNs everywhere it accepts function names.
Used to be able to use Alias in place of a regular Lambda. Lambda accepts ARNs everywhere it accepts function names.
functionRefFunctionReferencefunction_refFunctionReferencefunctionRefFunctionReferenceFunctionRefFunctionReferenceFunctionRefFunctionReferencerequired#grantPrincipalIPrincipalgrant_principalIPrincipalgrantPrincipalIPrincipalGrantPrincipalIPrincipalGrantPrincipalIPrincipalrequired#If this is false, trying to access the connections object will fail.
latestVersionIVersionlatest_versionIVersionlatestVersionIVersionLatestVersionIVersionLatestVersionIVersionrequired#notes
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.
permissionsNodeNodepermissions_nodeNodepermissionsNodeNodePermissionsNodeNodePermissionsNodeNoderequired#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#resourceArnsForGrantInvokestring[]resource_arns_for_grant_invoketyping.List[str]resourceArnsForGrantInvokeList<String>ResourceArnsForGrantInvokestring[]ResourceArnsForGrantInvoke*[]*stringrequired#Undefined if the function was imported without a role.
tenancyConfigTenancyConfigtenancy_configTenancyConfigtenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfig#Methods
addAutoScaling(options: AutoScalingOptions): IScalableFunctionAttributedef add_auto_scaling(self, options: AutoScalingOptions) -> IScalableFunctionAttributepublic IScalableFunctionAttribute addAutoScaling(AutoScalingOptions options)public IScalableFunctionAttribute AddAutoScaling(AutoScalingOptions options)func AddAutoScaling(Options AutoScalingOptions) IScalableFunctionAttribute#Returns a scalable attribute that can call scaleOnUtilization() and scaleOnSchedule().
1 parameter
Parameters
optionsoptionsoptionsoptionsOptions— Autoscaling options.
addEventSource(source: IEventSource): voiddef add_event_source(self, source: IEventSource) -> Nonepublic void addEventSource(IEventSource source)public void AddEventSource(IEventSource source)func AddEventSource(Source IEventSource)#notes
Event sources are implemented in the aws-cdk-lib/aws-lambda-event-sources module.
The following example adds an SQS Queue as an event source:
import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
myFunction.addEventSource(new SqsEventSource(myQueue));
addEventSourceMapping(id: string, options: EventSourceMappingOptions): EventSourceMappingdef add_event_source_mapping(self, id: str, options: EventSourceMappingOptions) -> EventSourceMappingpublic EventSourceMapping addEventSourceMapping(String id, EventSourceMappingOptions options)public EventSourceMapping AddEventSourceMapping(string id, EventSourceMappingOptions options)func AddEventSourceMapping(Id *string, Options EventSourceMappingOptions) EventSourceMapping#addFunctionUrl(options?: FunctionUrlOptions): FunctionUrldef add_function_url(self, options: typing.Optional[FunctionUrlOptions] = None) -> FunctionUrlpublic FunctionUrl addFunctionUrl(FunctionUrlOptions options)public FunctionUrl AddFunctionUrl(FunctionUrlOptions? options = null)func AddFunctionUrl(Options FunctionUrlOptions) FunctionUrl#addPermission(id: string, permission: Permission): voiddef add_permission(self, id: str, permission: Permission) -> Nonepublic void addPermission(String id, Permission permission)public void AddPermission(string id, Permission permission)func AddPermission(Id *string, Permission Permission)#2 parameters
Parameters
ididididId— The id for the permission construct.permissionpermissionpermissionpermissionPermission— The permission to grant to this Lambda function.
addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
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: EventInvokeConfigOptions): voiddef configure_async_invoke(self, options: EventInvokeConfigOptions) -> Nonepublic void configureAsyncInvoke(EventInvokeConfigOptions options)public void ConfigureAsyncInvoke(EventInvokeConfigOptions options)func ConfigureAsyncInvoke(Options EventInvokeConfigOptions)#considerWarningOnInvokeFunctionPermissions(_scope: Construct, _action: string): voiddef consider_warning_on_invoke_function_permissions(self, _scope: Construct, _action: str) -> Nonepublic void considerWarningOnInvokeFunctionPermissions(Construct _scope, String _action)public void ConsiderWarningOnInvokeFunctionPermissions(Construct _scope, string _action)func ConsiderWarningOnInvokeFunctionPermissions(_scope Construct, _action *string)#- 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.
fromAliasAttributes(scope: Construct, id: string, attrs: AliasAttributes): IAlias@staticmethod def from_alias_attributes(scope: Construct, id: str, attrs: AliasAttributes) -> IAliaspublic static IAlias fromAliasAttributes(Construct scope, String id, AliasAttributes attrs)public static IAlias FromAliasAttributes(Construct scope, string id, AliasAttributes attrs)func FromAliasAttributes(Scope Construct, Id *string, Attrs AliasAttributes) IAliasstatic#grantInvoke(grantee: IGrantable): Grantdef grant_invoke(self, grantee: IGrantable) -> Grantpublic Grant grantInvoke(IGrantable grantee)public Grant GrantInvoke(IGrantable grantee)func GrantInvoke(Grantee IGrantable) Grant#[disable-awslint:no-grants]
grantInvokeCompositePrincipal(compositePrincipal: CompositePrincipal): Grant[]def grant_invoke_composite_principal(self, composite_principal: CompositePrincipal) -> typing.List[Grant]public List<Grant> grantInvokeCompositePrincipal(CompositePrincipal compositePrincipal)public Grant[] GrantInvokeCompositePrincipal(CompositePrincipal compositePrincipal)func GrantInvokeCompositePrincipal(CompositePrincipal CompositePrincipal) *[]Grant#[disable-awslint:no-grants]
grantInvokeLatestVersion(grantee: IGrantable): Grantdef grant_invoke_latest_version(self, grantee: IGrantable) -> Grantpublic Grant grantInvokeLatestVersion(IGrantable grantee)public Grant GrantInvokeLatestVersion(IGrantable grantee)func GrantInvokeLatestVersion(Grantee IGrantable) Grant#[disable-awslint:no-grants]
grantInvokeUrl(grantee: IGrantable): Grantdef grant_invoke_url(self, grantee: IGrantable) -> Grantpublic Grant grantInvokeUrl(IGrantable grantee)public Grant GrantInvokeUrl(IGrantable grantee)func GrantInvokeUrl(Grantee IGrantable) Grant#[disable-awslint:no-grants]
grantInvokeVersion(grantee: IGrantable, version: IVersion): Grantdef grant_invoke_version(self, grantee: IGrantable, version: IVersion) -> Grantpublic Grant grantInvokeVersion(IGrantable grantee, IVersion version)public Grant GrantInvokeVersion(IGrantable grantee, IVersion version)func GrantInvokeVersion(Grantee IGrantable, Version IVersion) Grant#[disable-awslint:no-grants]
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#metric(metricName: string, props?: MetricOptions): Metricdef metric(self, metric_name: str, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metric(String metricName, MetricOptions props)public Metric Metric(string metricName, MetricOptions? props = null)func Metric(MetricName *string, Props MetricOptions) Metric#metricDuration(props?: MetricOptions): Metricdef metric_duration(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricDuration(MetricOptions props)public Metric MetricDuration(MetricOptions? props = null)func MetricDuration(Props MetricOptions) Metric#Average over 5 minutes
metricErrors(props?: MetricOptions): Metricdef metric_errors(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricErrors(MetricOptions props)public Metric MetricErrors(MetricOptions? props = null)func MetricErrors(Props MetricOptions) Metric#Sum over 5 minutes
metricInvocations(props?: MetricOptions): Metricdef metric_invocations(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricInvocations(MetricOptions props)public Metric MetricInvocations(MetricOptions? props = null)func MetricInvocations(Props MetricOptions) Metric#Sum over 5 minutes
metricThrottles(props?: MetricOptions): Metricdef metric_throttles(self, props: typing.Optional[MetricOptions] = None) -> Metricpublic Metric metricThrottles(MetricOptions props)public Metric MetricThrottles(MetricOptions? props = null)func MetricThrottles(Props MetricOptions) Metric#Sum over 5 minutes
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.