我有以下CFN事件规则,应该启动MyLambda
。当我运行这个CFN模板时,我可以看到创建的规则具有正确的间隔,正确的输入json并且它是 ENABLED 。但它并没有开始。我没有看到我的lambda创建的任何日志(我正在使用print语句)。
但是当我使用UI(相同的配置等)创建类似的规则时,它工作正常。我不确定我在这里缺少什么。
CWEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: "Description"
Name: "CWEventRule"
ScheduleExpression: "rate(5 minutes)"
State: "ENABLED"
Targets:
-
Arn:
Fn::GetAtt:
- "MyLambda"
- "Arn"
Id: "MyLambda"
Input: "{\"jsonkey\":\"jsonvalue\"}"
更新了带角色的cfn模板
CloudWatchEventRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- !Sub lambda.amazonaws.com
- !Sub events.amazonaws.com
Action: "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: CloudWatchEventPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- "lambda:InvokeFunction"
Resource: "*"
CWEventRule:
Type: "AWS::Events::Rule"
Properties:
Description: "Description"
Name: "CWEventRule"
ScheduleExpression: "rate(5 minutes)"
State: "ENABLED"
RoleArn: !GetAtt [ CloudWatchEventRole, Arn ]
Targets:
-
Arn:
Fn::GetAtt:
- "MyLambda"
- "Arn"
Id: "MyLambda"
Input: "{\"jsonkey\":\"jsonvalue\"}"
答案 0 :(得分:4)
您需要向Event调用Lambda权限。这可以通过创建 AWS :: Lambda :: Permission 资源来实现。
$x = 0;
while($x <= 5) {
$contentItems = $relatedArray[$rand_keys[$x]];
$contentItems = explode('|', $contentItems);
echo '
<p><a href="'.$contentItems[3].'"><img class="faux" src="'.$contentItems[4].'"></a></p>
';
$x++;
}
答案 1 :(得分:1)
RoleArn应该与目标关联如下。可以找到更多信息here
Targets:
-
Arn:
Fn::GetAtt:
- "MyLambda"
- "Arn"
Id: "MyLambda"
Input: "{\"jsonkey\":\"jsonvalue\"}"
RoleArn:
Fn::GetAtt:
- CloudWatchEventRole
- Arn