admin管理员组文章数量:1336195
state_machine_input = {
'STATE_MACHINE_DEFINITION_NAME': event_dict.get('workflowToBeTriggered'),
'LDAP_USER': event_dict.get('updatedBy')
}
eventbridge_client = boto3.client('events')
response = eventbridge_client.put_targets(
Rule=f"{EVENT_NAMING_SUFFIX}{event_dict.get('name')}",
Targets=[
{
'Id': SM_INITIATION_LAMBDA_FUNCTION_NAME,
'Arn': SM_INITIATION_LAMBDA_FUNCTION_ARN,
'Input': json.dumps(state_machine_input, indent=2)
}
]
)
I am creating an eventbridge rule to trigger a lambda, and i need to pass constant input to the target. this part is my problem: 'Input': json.dumps(state_machine_input, indent=2) that is not working on the eventbridge. the rule is being created with the Target input but it is not working.
if i remove the indent=2, and then i manually click the prettify on the aws console eventbridge, then it works.
I already tried adding these separators=(',', ':'), ensure_ascii=False nothing works. only the prettify button.
which i cant do in production, it should be working already upon deployment without manual intervention.
prettify button
state_machine_input = {
'STATE_MACHINE_DEFINITION_NAME': event_dict.get('workflowToBeTriggered'),
'LDAP_USER': event_dict.get('updatedBy')
}
eventbridge_client = boto3.client('events')
response = eventbridge_client.put_targets(
Rule=f"{EVENT_NAMING_SUFFIX}{event_dict.get('name')}",
Targets=[
{
'Id': SM_INITIATION_LAMBDA_FUNCTION_NAME,
'Arn': SM_INITIATION_LAMBDA_FUNCTION_ARN,
'Input': json.dumps(state_machine_input, indent=2)
}
]
)
I am creating an eventbridge rule to trigger a lambda, and i need to pass constant input to the target. this part is my problem: 'Input': json.dumps(state_machine_input, indent=2) that is not working on the eventbridge. the rule is being created with the Target input but it is not working.
if i remove the indent=2, and then i manually click the prettify on the aws console eventbridge, then it works.
I already tried adding these separators=(',', ':'), ensure_ascii=False nothing works. only the prettify button.
which i cant do in production, it should be working already upon deployment without manual intervention.
prettify button
Share Improve this question asked Nov 20, 2024 at 6:00 MondyMondy 74 bronze badges2 Answers
Reset to default 0The issue is likely due to extra whitespaces or formatting introduced by the indent=2 argument when serializing the JSON using json.dumps
Turns out the issue is easy to fix. I needed to add permission to invoke the lambda by the specific rule. It only confuses me because of the fact that the prettify button will do the work which is nice but not actually the reason why its working. It is working whenever i made any changes and save it via the aws console, that way the eventbridge is smart enough to add the necessary permission to make it. But if you create the rule via a lambda(boto3) it will not automatically add that permission.
本文标签:
版权声明:本文标题:aws event bridge - How to put the Targets Input correctly on the eventbridge rule using boto3 put_targets without manually click 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742378564a2463653.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论