我使用 AWS CDK 来管理 Lambda。
我为 Lambda 函数创建了两个别名,development并且production.
但我不知道如何将版本与每个别名关联起来。
export class CdkLambdaStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const fnDemo = new NodejsFunction(this, 'demo', {
entry: 'lib/lambda-handler/index.ts',
currentVersionOptions: {
removalPolicy: RemovalPolicy.RETAIN,
retryAttempts: 1
}
});
// In this case, production would be the most recent version
// I want to specify the previous stable version
fnDemo.currentVersion.addAlias('production');
new lambda.Alias(this, 'demo-development-alias', {
aliasName: 'development',
version: fnDemo.latestVersion
});
}
}
Run Code Online (Sandbox Code Playgroud)
我查看了 AWS CDK 文档,但找不到获取以前版本的方法。您还有其他好主意吗?
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Version.html
解决
import cdk = require('@aws-cdk/core');
import * as lambda from '@aws-cdk/aws-lambda';
import {NodejsFunction} from '@aws-cdk/aws-lambda-nodejs';
import {RemovalPolicy} from "@aws-cdk/core";
export class CdkLambdaStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const fnDemo = new NodejsFunction(this, 'demo', {
entry: 'lib/lambda-handler/index.ts',
currentVersionOptions: {
removalPolicy: RemovalPolicy.RETAIN,
}
});
const prodVersion = lambda.Version.fromVersionArn(this, 'prodVersion', `${fnDemo.functionArn}:1`);
prodVersion.addAlias('production');
const stgVersion = lambda.Version.fromVersionArn(this, 'stgVersion', `${fnDemo.functionArn}:2`);
stgVersion.addAlias('staging');
const currentVersion = fnDemo.currentVersion;
const development = new lambda.Alias(this, 'demo-development', {
aliasName: 'development',
version: currentVersion
});
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7631 次 |
| 最近记录: |