在ECR事件后触发AWS Lambda函数 [英] Trigger AWS lambda function after ECR event

查看:84
本文介绍了在ECR事件后触发AWS Lambda函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当将新映像推送到AWS容器注册表时,我都试图使AWS Lambda函数运行。我已经创建并测试了可以正常工作的功能。然后,我使用以下模式创建了一个简单的CloudWatch事件规则:

I am trying to get an AWS Lambda function to run whenever a new image is pushed to an AWS container registry. I have created and tested the function which works fine. I have then created a simple CloudWatch event rule with the pattern:

{
  "source": [
    "aws.ecr"
  ]
}

我相信这会触发

该规则具有lambda函数的目标。问题在于,当将新映像推送到注册表(或删除等)时,未调用该函数。该功能的CloudWatch日志中没有任何内容。事件规则中是否缺少某些内容,或者是否存在诊断出问题的方法?

The rule has a target of the lambda function. The problem is the function is not called when a new image is pushed to the registry (or deleted etc). Nothing appears in the CloudWatch logs for the function. Is there something missing from the event rule or a way to diagnose what could be going wrong?

推荐答案

CloudTrail记录PutImage事件,并且可以将其写入CloudWatch Logs。只要在CloudWatch Logs中编写了 PutImage 事件,便可以触发警报,该事件可以通过SNS进一步触发Lambda函数。

CloudTrail records PutImage event and can write it to CloudWatch Logs. An Alarm can be triggered whenever a PutImage event is written in CloudWatch Logs which can further trigger a Lambda Function through SNS.

您将创建一个Logs Metric Filters,类似这样。

You would create a Logs Metric Filter, Something like this.

{ ($.eventSource = ecr.amazonaws.com) && ($.eventName = PutImage) && ($.requestParameters.repositoryName = "<RepoName>") && ($.errorCode NOT EXISTS) }

您需要配置ECR CloudTrail API调用事件。

You need to configure the ECR CloudTrail API Calls Events.

{
  "source": [
    "aws.ecr"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "ecr.amazonaws.com"
    ]
  }
}

这篇关于在ECR事件后触发AWS Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆