我认为您可以使用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: !If [IsPrimaryRegion, true, false]发布于 2022-09-16 21:32:17
您需要定义条件块,然后可以在模板中使用这些条件,如下所示:
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: falsehttps://stackoverflow.com/questions/73735525
复制相似问题