我是AWS CDK的新手,我试图(使用C#)完成的是对我的lambda函数进行版本化,然后创建一个引用该版本的新API资源。
例如:程序接受一个版本参数。
internal CdkAppStack(Construct scope, string id, IStackProps props, string bucketName, string functionName, string version) : base(scope, id, props)
{
var bucket = new Bucket(this, bucketName, new BucketProps {
BucketName = bucketName
});
var handler = new Function(this, $"{functionName}Handler", new FunctionProps
{
Runtime = Runtime.DOTNET_CORE_3_1,
Code = Code.FromAsset("Lambdas\\src\\Lambdas\\bin\\Debug\\netcoreapp3.1"),
Handler = "Lambdas::Lambdas.Function::FunctionHandler",
Environment = new Dictionary<string, string>
{
["BUCKET"] = bucket.BucketName,
},
FunctionName = functionName
});
string apiName = !string.IsNullOrEmpty(version) ? $"{functionName}-{version}" : functionName;
bucket.GrantReadWrite(handler);
var api = new RestApi(this, $"{apiName}-API", new RestApiProps
{
RestApiName = $"{apiName}API",
Description = $"This service the Lambda - {functionName}.",
RetainDeployments = true
});
var getWidgetsIntegration = new LambdaIntegration(handler, new LambdaIntegrationOptions
{
RequestTemplates = new Dictionary<string, string>
{
["application/json"] = "{ \"statusCode\": \"200\" }"
}
});
string resource = !string.IsNullOrEmpty(version) ? $"execute-{version}" : "execute";
var helloWorldResource = api.Root.AddResource(resource);
var method = helloWorldResource.AddMethod("POST", getWidgetsIntegration);
}实际结果:
它覆盖了lambda和api资源。
预期结果:(version参数为3)。添加了新资源(execute-3)
发布于 2021-03-31 18:43:44
对于给定的代码,该过程可能如下所示:
当前调配的状态包括execute-2
execute-3.
存在的云信息模板,而execute-2没有计算出为了达到所需的状态(如模板中所述),它需要删除 execute-2和provision Cloudformation
如果你真的想要达到你所描述的,你将不得不添加资源和,而不是删除先前提供的资源(比如编写一个在1..version上运行的循环,并添加所有过去的版本)
另一个(不太推荐的)选择是使用deletion policy。这样,您可以提示cloudformation,而不是删除execute-2 (缺点是execute-2的生命周期不再由任何堆栈管理-->您必须手动管理对其的更改)
https://stackoverflow.com/questions/66884319
复制相似问题