我使用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
});
}
}
我已经看过AWS CDK文档,但是找不到找到以前版本的方法。您还有其他好主意吗?
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Version.html
答案 0 :(得分:1)
已解决
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
});
}
}