简体   繁体   English

带有 lambda 的 AWS Cron 作业

[英]AWS Cron jobs with lambdas

I want to set up cron jobs for my application using lambda functions.我想使用 lambda 函数为我的应用程序设置 cron 作业。 My current architecture consists of an auto-scaling group behind a load balancer, both inside the same VPC.我当前的架构由负载均衡器后面的自动缩放组组成,两者都在同一个 VPC 内。 My intention is to call a specific path to my application, for instance "/cron/task1" using lambdas, and call them at regular intervals using the cron-like syntax.我的意图是调用我的应用程序的特定路径,例如使用 lambdas 的“/cron/task1”,并使用类似 cron 的语法定期调用它们。 How can I secure my application so that such endpoints can only be reached from lambda functions and not from outside the vpc, while allowing reachability to all other paths of the application from the final users?如何保护我的应用程序,以便只能从 lambda 函数而不是从 vpc 外部访问此类端点,同时允许最终用户访问应用程序的所有其他路径?

Api authorization may be what you need. Api 授权可能是您需要的。 One of the easiest way(not most secure) to do is;最简单的方法之一(不是最安全的)是;

  • Both you lambda and application share a common secret你们 lambda 和应用程序共享一个共同的秘密
  • When a request is made from lambda to your application you hash all the query parameters like this;当从 lambda 向您的应用程序发出请求时,您的 hash 所有查询参数都是这样的;

myapp.url/cron/task1?a=value&c=something&b=foobar myapp.url/cron/task1?a=value&c=something&b=foobar

You sort parameters in ascending/descending order您按升序/降序对参数进行排序

{
  "a": "val",
  "b": "foobar"
  "c": "some",
}
  • by using the shared common secret you hash all those key and make a new string such as cf23df2207d99a74fbe169e3eba035e633b65d94通过使用共享的公共秘密 hash 所有这些密钥并制作一个新字符串,例如cf23df2207d99a74fbe169e3eba035e633b65d94

now your request will be现在您的请求将是

myapp.url/cron/task1?a=val&c=some&b=foobar&token=cf23df2207d99a74fbe169e3eba035e633b65d94 myapp.url/cron/task1?a=val&c=some&b=foobar&token=cf23df2207d99a74fbe169e3eba035e633b65d94

  • when your application receives this request, it takes token out and sort the rest(the same order lambda used) and using the same secret key it creates a hash.当您的应用程序收到此请求时,它取出令牌并对其余令牌进行排序(使用相同的顺序 lambda)并使用相同的密钥创建 hash。
  • if the hashes are matched then you know it is coming from lambda since they both know the same secret.如果哈希匹配,那么您知道它来自 lambda,因为它们都知道相同的秘密。 If it isn't, then you can discard that request.如果不是,那么您可以放弃该请求。

You may keep that secrets in aws kms to not expose and make it more secure.您可以将这些秘密保存在aws kms中,以免暴露并使其更安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM