如何在EventBridge规则CloudFormation模板中指定AWS Batch作业的shareIdentifier
要在CloudFormation模板中为EventBridge触发的Batch作业指定shareIdentifier,你需要遵循以下配置方式:
- 不要在
BatchParameters中直接添加shareIdentifier/ShareIdentifier,该字段不在EventBridge Batch目标的官方属性定义中,会被判定为无效键。 - 正确的方式是通过
Input字段传递该参数,但必须保证JSON格式正确(禁止使用HTML转义字符),因为EventBridge会将Input中的顶层参数映射到Batch的SubmitJobAPI请求中。
正确配置示例
在你的EventBridge规则Target中,按如下方式配置:
AWSTemplateFormatVersion: '2010-09-09' Resources: MyEventBridgeRule: Type: AWS::Events::Rule Properties: Description: 触发带shareIdentifier的Batch作业 ScheduleExpression: "rate(1 minute)" # 替换为你的实际触发条件 State: ENABLED Targets: - Arn: !Ref MyBatchJobQueue Id: "BatchJobTarget" BatchParameters: JobDefinition: !Ref MyBatchJobDefinition JobName: "MyScheduledJob" JobQueue: !Ref MyBatchJobQueue Input: | { "shareIdentifier": "mid", "parameters": { "your-job-param-1": "value1", "your-job-param-2": "value2" } }
关键说明
- JSON格式正确性:不要用
"代替双引号,直接使用标准JSON语法,否则EventBridge无法正确解析参数。 - 参数层级:
shareIdentifier需要作为Input的顶层键,和parameters(作业容器参数)同级,这样EventBridge会将其作为SubmitJobAPI的请求参数传递。 - 配合BatchParameters:
BatchParameters中仍需指定JobDefinition、JobName和JobQueue,这些基础参数会和Input中的内容合并生成最终的SubmitJob请求。
如果上述配置仍不生效,可以尝试使用InputTransformer构造请求:
Targets: - Arn: !Ref MyBatchJobQueue Id: "BatchJobTarget" BatchParameters: JobDefinition: !Ref MyBatchJobDefinition JobName: "MyScheduledJob" JobQueue: !Ref MyBatchJobQueue InputTransformer: InputPathsMap: {} InputTemplate: | { "shareIdentifier": "mid", "parameters": <$> }
内容的提问来源于stack exchange,提问作者Jacob Kearney
相关产品推荐
相关产品推荐

