Cloudwatch 事件不会触发通过 CloudFormation 创建的 Lambda 函数

问题描述

请找到我尝试使用 cloudformation 创建 lambda 函数和事件规则的代码,cloudformation 已成功部署,一切看起来都不错,但在计划时间我的事件规则没有触发或调用 lambda 函数我有检查权限也一切正常,但不起作用。

请您在这里帮忙。

Parameters:
  CRONScheduler:
    Description: 'Define the CRON Schedule for the event to trigger'
    Type: String
    Default: cron(* * * * * *)

Resources:
  EventRule:
    Type: AWS::Events::Rule
    Properties:
      Description: 'ScheduledRule'
      ScheduleExpression: !Ref CRONScheduler
      State: ENABLED
      Targets:
        -
          Arn:
            Fn::GetAtt:
              - "LambdaFunction"
              - "Arn"
          Id: "TargetFunctionV1"
          Input: '{"Account_id ": "369885648310"}'

  PermissionForEventsToInvokeLambda:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !Ref LambdaFunction
      Action: "lambda:InvokeFunction"
      Principal: "events.amazonaws.com"
      SourceArn:
        Fn::GetAtt:
          - "EventRule"
          - "Arn"

  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Description: "My Lambda Function"
      FunctionName: "MyLambdaFunccc"
      Role: arn:aws:iam::369885648310:role/service-role/myfunction-role-cjkkxygt
      Runtime: python3.8
      #Code:
      #  ZipFile: |
      #      import boto3
      #      def lambda_handler(event,context):
      #        client = boto3.client('ec2')
      #        response = client.describe_instances(InstanceIds = ['i-03de56c4f3969694a'])
      #        for instance in response['Reservations']:
      #          for depth in instance['Instances']:
      #            print('the machine details are {},{},{}'.format(depth['ImageId'],depth['InstanceType'],depth['Monitoring']))

      #Handler: index.lambda_handler
      Code:
        S3Bucket: cftfiles
        S3Key: InstanceStateChange.zip
      Handler: InstanceStateChange.lambda_handler

Lambda 权限:

{
  "Version": "2012-10-17","Id": "default","Statement": [
    {
      "Sid": "MYCFTT-PermissionForEventsToInvokeLambda-JD1QWW6MYAKG","Effect": "Allow","Principal": {
        "Service": "events.amazonaws.com"
      },"Action": "lambda:InvokeFunction","Resource": "arn:aws:lambda:us-east-1:369885648310:function:MyLambdaFunccc","Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:events:us-east-1:369885648310:rule/MYCFTT-EventRule-5VIMAR0OVQXD"
        }
      }
    }
  ]
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)