传递一个脚本,而在亚马逊EC2启动实例 [英] Passing a script while starting an instance in Amazon EC2

查看:204
本文介绍了传递一个脚本,而在亚马逊EC2启动实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过一个脚本,而我开始一个实例?这样的实例将执行该脚本一旦其初始化?

Is it possible to pass a script while I'm starting an instance? So that the instance will execute that script once its initialized?

public static void startInstance(final String instanceId) {
    StartInstancesRequest startRequest = new StartInstancesRequest().withInstanceIds(instanceId);
    logger.info(String.format("Starting instance '%s':...", instanceId));
    ec2.startInstances(startRequest);       
}

你知道吗?脚本将是一种启动脚本,我需要尽快执行的实例已准备就绪。先谢谢了。

Any idea? Script will be kind of startup script which I need to execute as soon as the instance is ready. Thanks in advance.

推荐答案

我公司推出的概念的在社区的Ubuntu AMI的2009年(的一些想法来自RightScale的简化版本)用户数据的脚本的:

I introduced the concept of user-data scripts in the community Ubuntu AMIs in 2009 (simplified version of some ideas from RightScale):

<一个href="http://alestic.com/2009/06/ec2-user-data-scripts">http://alestic.com/2009/06/ec2-user-data-scripts

它归结为:

如果实例的用户数据开始的两个字符#!则实例运行它作为第一个启动的root用户。

If the instance user-data starts with the two characters #! then the instance runs it as the root user on the first boot.

此功能后来被包含在Ubuntu官方的AMI在CloudInit包:

This feature was later included in the official Ubuntu AMIs in the CloudInit package:

<一个href="https://help.ubuntu.com/community/CloudInit">https://help.ubuntu.com/community/CloudInit

亚马逊现在包括CloudInit包在自己亚马逊的Linux AMI的:

Amazon now includes the CloudInit package in their own Amazon Linux AMIs:

<一个href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AmazonLinuxAMIBasics.html">http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AmazonLinuxAMIBasics.html

其他的发行版,欢迎(可能的话)在其AMI的这一功能。

Other distros are welcome to (and may already) include this feature in their AMIs.

这篇关于传递一个脚本,而在亚马逊EC2启动实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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