亚马逊EC2不使用用户数据的PHP亚马逊、数据、用户、PHP

2023-09-11 09:47:04 作者:朕不想活了

我发动我的PHP code Ubuntu的EC2实例和传递用户数据给它。 我不拥有该实例..但他们提供给它的用户级访问。

首先,我试图通过传递用户数据来运行特定的工作,但它似乎并没有工作。

我说的很简单,发送触摸的test.txt作为用户数据。实例被正确启动,但该文件没有被创建为应该是我猜。

我缺少任何一个步骤?我查了一下,这不是使用ssh荷兰国际集团,以实例创建的文件。有一件事是我是不是在实例根用户。请问是什么效果?

 < PHP
使用error_reporting(-1);
标题(内容类型:text / plain的;字符集= UTF-8);
require_once'../sdk.class.php;
//实例化类
$ EC2 =新AmazonEC2();
$ userdata2 =摸喜,TXT;
回声$ userdata2;
$响应= $ ec2-> run_instances('AMI-5f21e236',1,1,
阵列('KeyName是'=>基数2),
阵列('的UserData'=> $ userdata2)
阵列('InstanceType'=>'的m1.small)
);
的var_dump($响应 - > isOK());
?>
 

解决方案

如果你想运行code为用户数据的脚本,那么你需要用两个字符开始用户数据#!

京东向亚马逊永远学不到的精华是什么

例如,您的触摸命令可能是:

 #!/斌/庆典
触摸/tmp/hello-world.txt
 

我不是一个PHP程序员,但我认为这可能工作的基础上我的研究:

 #!的/ usr / bin中/ PHP
< PHP
[...您的code在这里...]
?>
 

下面就是我介绍了用户数据的脚本的概念文章:

  

http://alestic.com/2009/06/ec2-user-数据脚本

这已被纳入其中所使用的一些AMI的发行版,包括Ubuntu和Linux的亚马逊Ubuntu的云的init包。

云初始化有一些更灵活的指定的东西在启动的方式,但shabang(#!)方法是一种简单的方法,在第一次启动运行任何脚本。

I am launching a ubuntu EC2 instance with my PHP code and passing user data to it. I don't own that instance.. but they provide user level access to it.

Firstly i tried to run a particular job by passing user data, but it did not seem to work.

I made it very simple and send "touch test.txt" as user data. The instance was launched properly but the file was not created as should be i guess.

Am I missing any step? I checked that file was not created using ssh 'ing to the instance. One thing was i was not in root user at instance. Will that effect anything?

<?php
error_reporting(-1);
header("Content-type: text/plain; charset=utf-8");
require_once '../sdk.class.php';
// Instantiate the class
$ec2 = new AmazonEC2();
$userdata2="touch hi".".txt";
echo $userdata2;
$response = $ec2->run_instances('ami-5f21e236', 1, 1,
array('KeyName' => 'radix2'),
array('UserData' => $userdata2),
array('InstanceType' => 'm1.small')
);
var_dump($response->isOK());
?>

解决方案

If you are trying to run your code as a user-data script, then you need to start the user data with the two characters #!

For example, your touch command might be:

#!/bin/bash
touch /tmp/hello-world.txt

I'm not a PHP programmer, but I think this might work based on my research:

#!/usr/bin/php
<?php
[...your code here...]
?>

Here's the article where I introduced the concept of user-data scripts:

http://alestic.com/2009/06/ec2-user-data-scripts

This has been incorporated into Ubuntu's cloud-init package which is used by a number of AMI distros including Ubuntu and Amazon Linux.

cloud-init has some more flexible ways of specifying things at startup, but the shabang (#!) method is a simple way to run any script at first boot.