You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(lambda): add alias to latest version through code hash
It is a common use case to define an alias for the latest version of a function. In order to do that, one needs to define a Version resource that points to the latest version and then associate an Alias with it.
This was not trivial to do so far. Now it is:
fn.addAlias('foo')
This will define a lambda.Version with a name the derives from the hash of the lambda's source code and then define a lambda.Alias associated with this version object. Since the name of the version resource is based on the hash, when the code changes, a new version will be created automatically.
To support this, `lambda.Code.bind()` now returns an optional `codeHash` attribute. It is supported for `lambda.Code.fromAsset` and `lambda.Code.fromInline`, for which we can calculate the source hash based on the content.
Resolves#6750Resolves#5334
thrownewError(`version name must be provided because the the lambda code hash cannot be calculated. Only "lambda.Code.fromAsset" and "lambda.Code.fromInline" support code hash`);
602
+
}
603
+
604
+
name=this.codeHash;
605
+
}
606
+
580
607
returnnewVersion(this,'Version'+name,{
581
608
lambda: this,
582
609
codeSha256,
@@ -586,6 +613,23 @@ export class Function extends FunctionBase {
586
613
});
587
614
}
588
615
616
+
/**
617
+
* Defines an alias for this function associated with the latest version of
618
+
* the function.
619
+
*
620
+
* @param name The name for this alias.
621
+
* @param options Options for the alias. If this function uses assets or
622
+
* inline code, do not specify `versionName`. Otherwise, `versionName` is
0 commit comments