gpt4 book ai didi

amazon-web-services - 在 SAM 模板中使用 !If 内部函数

转载 作者:行者123 更新时间:2023-12-03 07:39:19 25 4
gpt4 key购买 nike

我认为您可以使用 SAM 对状态机执行类似的操作:

SM:
Type: AWS::Serverless::StateMachine
Properties:
Name: !Sub "${StageName}-State-Machine"
DefinitionUri: statemachine/dddd.asl.json
Events:
Schedule:
!If
- IsPrimaryRegion
-
Type: Schedule
Properties:
Description: Schedule to run the twilio number state machine
Enabled: !Ref ScheduleEnabled
Schedule: "rate(1 hour)"
-
Type: Schedule
Properties:
Description: Schedule to run the twilio number state machine
Enabled: !Ref ScheduleEnabled
Schedule: "rate(1 hour)"

但是 SAM 验证失败。如果我在属性中使用 State 而不是 Enabled,它也会失败。最终我希望有一种方法可以使用参数或任何其他方式动态设置启用。但状态验证失败。

也尝试过这个:

Enabled: !If [IsPrimaryRegion, true, false]

最佳答案

您需要定义Conditions block ,然后您可以在模板中使用这些条件,如下所示:

Parameters:
PrimaryRegion:
Type: String
Description: Primary region

Conditions:
IsPrimaryRegion: !Equals [ !Ref PrimaryRegion, !Ref "AWS::Region" ]

Resources:
SM:
Type: AWS::Serverless::StateMachine
Properties:
Name: !Sub "${StageName}-State-Machine"
DefinitionUri: statemachine/dddd.asl.json
Events:
Schedule:
Type: Schedule
Properties:
Description: Schedule to run the twilio number state machine
Enabled: !If [ IsPrimaryRegion, true, false ]
Schedule: "rate(1 hour)"

最终:

Parameters:
PrimaryRegion:
Type: String
Description: Primary region

Conditions:
IsPrimaryRegion: !Equals [ !Ref PrimaryRegion, !Ref "AWS::Region" ]
IsNotPrimaryRegion: !Not [ !Equals [ !Ref PrimaryRegion, !Ref "AWS::Region" ] ]

Resources:
SMPrimary:
Type: AWS::Serverless::StateMachine
Condition: IsPrimaryRegion
Properties:
Name: !Sub "${StageName}-State-Machine"
...
Enabled: true
SM:
Type: AWS::Serverless::StateMachine
Condition: IsNotPrimaryRegion
Properties:
Name: !Sub "${StageName}-State-Machine"
...
Enabled: false

关于amazon-web-services - 在 SAM 模板中使用 !If 内部函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73735525/

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