[英]add shell script to lambda function on EC2
I have a lambda function that boots a machine on EC2 triggered by a file uploaded on S3 bucket.我有一个 lambda function,它通过上传到 S3 存储桶的文件触发在 EC2 上启动一台机器。 I would like to run a shell command that is in that machine after the boot, but I failed to do so.
我想在启动后运行该机器中的 shell 命令,但我没有这样做。 Any thoughts of what I can do?
想知道我能做什么吗?
import boto3
region = 'us-east-1'
instances = ['i-079e6065f959e151a']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.start_instances(InstanceIds=instances)
On the Amazon EC2 instance, store your script in:在 Amazon EC2 实例上,将您的脚本存储在:
/var/lib/cloud/scripts/per-boot/
Any scripts in that directory will be automatically run each time that the instance boots (or 'Starts').每次实例启动(或“启动”)时,该目录中的任何脚本都会自动运行。
When the instance has finished its work, it should perform a shutdown with:当实例完成其工作时,它应该执行关闭:
sudo shutdown now -h
This will return the instance to a Stopped state.这会将实例返回到 Stopped state。
See: Auto-Stop EC2 instances when they finish a task - DEV Community请参阅: 完成任务时自动停止 EC2 实例 - DEV Community
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.