我可以从S3中上传的特定文件触发ECS/Fargate任务吗? [英] Can I trigger an ECS/Fargate task from a specific file upload in S3?

查看:48
本文介绍了我可以从S3中上传的特定文件触发ECS/Fargate任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道上传文件时可以触发任务(每个 https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatch-Events-tutorial-ECS.html ),但是,当特定文件已上传?

I know that I can trigger a task when a file is uploaded (per https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatch-Events-tutorial-ECS.html) however, how can I trigger a task when a specific file is uploaded?

Amazon似乎没想到人们会有多个工作在同一个存储桶中查看不同的文件:(

Amazon seems not to have anticipated people having multiple jobs watching the same bucket for different files :(

推荐答案

您可以使用CloudTrail Data Events中的CloudWatch Events完成此操作.

You can accomplish this with CloudWatch Events from CloudTrail Data Events.

前往 CloudTrail ,然后为您的帐户创建跟踪.

Head over to CloudTrail, and create a Trail for your account.

  • 对于将足迹应用于所有区域",请选择否".
  • 在管理"事件下的读/写事件"下,不选择任何一个.
  • 在数据"事件下,选择S3.输入您的S3存储桶名称和文件夹名称(前缀)以记录其数据事件,然后选择写入(不设置读取).
  • 在存储"位置下,创建一个新的存储桶或提供用于存储日志文件的存储桶.
  • 选择创建

接下来,创建一个CloudWatch Event规则,在CloudTrail数据事件发生时以您的ECS任务为目标.

Next, create a CloudWatch Event rule that targets your ECS Task when the CloudTrail Data Event happens.

前往CloudWatch,然后创建新的事件规则.

Head over to CloudWatch and Create a new Event rule.

  • 对于事件源,选择事件模式
  • 更改显示构建事件模式以按服务匹配事件"的下拉列表,以选择自定义事件模式"
  • 在下面输入事件模式:
{
  "source": [
    "aws.s3"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "s3.amazonaws.com"
    ],
    "eventName": [
      "PutObject"
    ],
    "requestParameters": {
      "bucketName": [
        "your-bucket-name" // this is the bucket where your events are happening
      ],
      "key": [
        "your-object-key" // this is the object key you want to trigger starting your ECS task, note that it's an array.
      ]
    }
  }
}

  • 根据需要自定义上面的 bucketName key .
  • 对于您的目标,选择"ECS任务",并根据需要配置任务.
  • 选择配置详细信息,为规则命名,并将状态设置为 Enabled ,然后单击创建规则.
    • Customize the bucketName and key above as appropriate for your use.
    • For your target, select ECS Task, configure the task as appropriate.
    • Select Configure details, give the rule a name and set the State to Enabled, and click Create rule.
    • 现在启用了规则,当您将具有指定键的对象上传到指定存储桶时,CloudWatch Events将触发您指定的ECS任务.

      Now that your rule is enabled, when you upload an object with the specified key to the specified bucket, CloudWatch Events will trigger the ECS Task you specified.

      这篇关于我可以从S3中上传的特定文件触发ECS/Fargate任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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