gpt4 book ai didi

amazon-web-services - 将参数传递给 AWS Cloudwatch 事件目标 lambda 函数

转载 作者:行者123 更新时间:2023-12-05 07:01:57 25 4
gpt4 key购买 nike

我想将参数传递给 AWS Cloudwatch 事件调用的 lambda 函数。参数名称为 alarmActions,我的事件规则 CFT 模板如下:

"LambdaInvokeScheduler": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "Scheduled Rule for invoking lambda function",
"EventPattern": {
"source": [
"aws.ecs"
],
"detail-type": [
"ECS Container Instance State Change"
],
"detail": {
"clusterArn": [
{ "Fn::GetAtt": ["WindowsCluster", "Arn"] }
]
}
},
"State": "ENABLED",
"Targets": [{
"Arn": { "Fn::GetAtt": ["AlarmCreationLambdaFunction", "Arn"] },
"Id": "AlarmCreationLambdaFunction",
"Input": { "Fn::Join" : ["", [ "{ \"alarmActions\": \"", { "Fn::Join" : [":", [ "arn:aws:sns", { "Ref" : "AWS::Region" }, { "Ref" : "AWS::AccountId" }, "CloudWatch"]] }, "\" }"]] }
}]
}
}

我使用了 Input 参数来传递 JSON 文本。围绕它的文档不多。我只是想找到正确的方法来做到这一点。

最佳答案

我找到了解决方案。我以错误的方式引用 lambda 中的参数。

我的 lambda 函数是这样的:

def func(event, context, alarmActions)
{
print(alarmActions)
}

当我进行以下更新时它起作用了:

def func(event, context)
{
print(event['alarmActions'])
}

关于amazon-web-services - 将参数传递给 AWS Cloudwatch 事件目标 lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63700811/

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