在AWS上,每天运行一次AWS CLI命令 [英] On AWS, run an AWS CLI command daily
问题描述
我有一个AWS CLI调用(在这种情况下,要启动配置的EMR集群以执行一些步骤然后关闭),但是我不确定如何每天运行它.
I have an AWS CLI invocation (in this case, to launch a configured EMR cluster to do some steps and then shut down) but I'm not sure how to go about running it daily.
我想做到这一点的一种方法是运行cron作业的EC2微型实例,或启动该命令的微型计算机中的ECS任务,但似乎一切都太过分了.看来在Lambda中也可以做到这一点,但从我所知道的来看,这很笨拙.
I guess one way to do it is an EC2 micro instance running a cron job, or an ECS task in a micro that launches the command, but that all seems like it might be overkill. It looks like there's also a way to do it in Lambda, but rom what I can tell it'd be kludgy.
这不一定是一个好的长期解决方案,只有在我能正确执行之前(数据管道),一些合适的方法才可以正常工作.
This doesn't have to be a good long-term solution, something that's suitable until I can do it right (Data Pipelines) would work just fine.
建议?
推荐答案
如果不是严格要求使用AWS CLI,则可以使用其中一种AWS开发工具包来以编程方式调用Lambda.
If it is not a strict requirement to use the AWS CLI, you can use one of the AWS SDK instead to programmatically invoke Lambda.
- 使用 cron 安排CloudWatch规则
- 配置后,CloudWatch Rules将触发Lambda函数
- 使用一个受支持的SDK(例如
- Schedule a CloudWatch Rules using cron
- When configured, the CloudWatch Rules will trigger a Lambda function
- Implement a Lambda function that calls EMR using one of the supported SDKs (e.g. the EMR class in the AWS JavaScript SDK)
- Make sure that you have the IAM configuration in place
完整示例可在使用CloudWatch Events计划AWS Lambda函数中找到
Kludgy?是的,需要进行配置,但是如果考虑到启动EC2/ECS所需的工作量(并确保在出现故障时重新启动),我会说它已经稳定了.
Kludgy? Yes, configuration is needed, however if you take into account the amount of work required to launch EC2 / ECS (and make sure that it re-launches in the event of failure), I'd say it evens out.
这篇关于在AWS上,每天运行一次AWS CLI命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!