[英]cron job that does not run : starring python, phantomjs, ec2 box
[英]Run a Job on EC2 from a (python) lambda
将文件放入S3后,将触发Lambda函数,该实习生应触发EC2实例中的作业。 从Lambda获取访问EC2并运行作业的最佳方法是什么?
import boto3
def trigger_handler(event, context):
#Get IP addresses of EC2 instances
client = boto3.client('ec2')
instDict=client.describe_instances(
Filters=[{'Name':'tag:Environment','Values':['Dev']}]
)
hostList=[]
for r in instDict['Reservations']:
for inst in r['Instances']:
hostList.append(inst['PublicIpAddress'])
#Invoke worker function for each IP address
client = boto3.client('lambda')
for host in hostList:
print "Invoking worker_function on " + host
invokeResponse=client.invoke(
FunctionName='worker_function',
InvocationType='Event',
LogType='Tail',
Payload='{"IP":"'+ host +'"}'
)
print invokeResponse
return{
'message' : "Trigger function finished"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.