gpt4 book ai didi

amazon-web-services - 如何在 Cloudformation 中使用属性条件

转载 作者:行者123 更新时间:2023-12-03 07:22:35 26 4
gpt4 key购买 nike

我正在尝试使用 CloudFormation 模板创建 lambda 函数、版本和别名,并且它按预期工作。但就我而言,我想根据一些输入参数配置RoutingConfig

示例:如果忍耐提供了 TrafficShitVersion 作为输入参数,那么只有我想将 RoutingConfig 添加到别名。

任何人都可以帮助我如何实现这一用例

--- 
Description: "Lambda Example"
Parameters:
TrafficShitVersion :
Default: 0
Type: String
Description: TrafficShitVersion

Conditions:
CreateRouting: !Not
- !Equals
- !Ref TrafficShitVersion
- 0
Resources:
MyLambdaFunction:
Properties:
Code:
ZipFile: |
exports.handler = function(event){
console.log(JSON.stringify(event, null, 4))
const response = {
statusCode: 200,
body: JSON.stringify('Hello from LambdaV5!')
}
return response
};
FunctionName: bhanuFunction
Handler: index.handler
Role: "RoleARN"
Runtime: nodejs12.x
Tags:
-
Key: "lambda:createdBy"
Value: SAM
Type: "AWS::Lambda::Function"
myfunctionVersion3:
DeletionPolicy: Retain
Properties:
FunctionName:
Ref: MyLambdaFunction
Type: "AWS::Lambda::Version"
myfunctionVersionAlias:
Properties:
FunctionName:
Ref: MyLambdaFunction
FunctionVersion:
Fn::GetAtt :
- myfunctionVersion3
- Version
Name: MyTestAliash
//Need to add the condition only if TrafficShitVersion is provided then only add ***RoutingConfig***
RoutingConfig:
AdditionalVersionWeights:
- FunctionVersion: !Ref TrafficShitVersion
FunctionWeight: 0.5
Type: "AWS::Lambda::Alias"

最佳答案

根据 AWS 文档,我们可以使用 Fn::IfAWS::NoValue 来相应地设置属性。

模板将如下所示:

MyLambdaFunctionAlias: 

Properties:
FunctionName:
Ref: MyLambdaFunction
FunctionVersion:
Fn::GetAtt :
- MyFunctionVersion3
- Version
Name: MyTestAlias
RoutingConfig:
!If
- "CreateRouting"
-
AdditionalVersionWeights:
- FunctionVersion: !Ref TrafficShitVersion
FunctionWeight: 0
- !Ref "AWS::NoValue"
Type: "AWS::Lambda::Alias"

关于amazon-web-services - 如何在 Cloudformation 中使用属性条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72319477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com