PHP SDK を使用して、ECS (Ec2 コンテナー サービス) で "TaskDefinition" を起動しようとしています。
- TaskDefinition を作成しました。
- クラスターを作成しました。
- サービスを作成しました。
次のステップは「registerContainerInstance」になると思っていましたが、このメソッドを呼び出すとエラーが発生しました:
[Aws\Ecs\Exception\EcsException] 「 https://ecs.eu-west-1.amazonaws.com
」 で「RegisterContainerInstance」を実行中にエラーが発生しました。AWS HTTP エラー: クライアント エラー: 400 ClientException (クライアント): ID ドキュメントが提供されましたが、有効ではありません。- {" __type":"ClientException","message":"ID ドキュメントが提供されましたが、有効ではありません。"}
これは、「instanceIdentityDocument」と「instanceIdentityDocumentSignature」を送信していないためです。しかし、この 2 つのパラメーターを取得する方法がわかりません。
以前に EC2 を手動で起動する必要がありますか?
私が知らない別の方法はありますか?
<?php
namespace App\Http\Controllers;
use Aws\Ecs\EcsClient;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
class ECSController extends Controller
{
protected $ecsClient;
function __construct() {
$config = Config::get('aws');
$this->ecsClient = new EcsClient([
'version' => 'latest',
'region' => $config['region'],
'credentials' => [
'key' => $config['credentials']['key'],
'secret' => $config['credentials']['secret'],
],
]);
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
/* $response = [
'photos' => []
];
return Response::json($response, $statusCode); */
echo "index\n";
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
$file = file_get_contents('config/configEC2basic.json');
$data = json_decode($file, true /* associative arrays */);
$result = $this->ecsClient->registerTaskDefinition($data);
if ($result['taskDefinition']['status'] == "ACTIVE")
{
$taskName = $result['taskDefinition']['containerDefinitions'][0]['name'];
if ($result['taskDefinition']['revision'] == 1)
echo "Task : '".$taskName."' has been created\n";
else
echo "Task : '".$taskName."' has been updated\n";
}
else
echo "Error : The task is not active.\n";
$clusterName = $this->ecsClient->createCluster([
'clusterName' => 'kaemo',
]);
$result = $this->ecsClient->createService([
'desiredCount' => 1,
'serviceName' => 'kaedevAWS1',
'taskDefinition' => 'testkaeDEV4',
'cluster' => 'kaemo'
]);
}
public function start()
{
$result = $this->ecsClient->registerContainerInstance([
'cluster' => 'kae',
'totalResources' => [
[
'integerValue' => 1,
"longValue" => 0,
'name' => "CPU",
'type' => "INTEGER",
"doubleValue" => 0.0,
],
[
'integerValue' => 996,
"longValue" => 0,
'name' => "MEMORY",
'type' => "INTEGER",
"doubleValue" => 0.0,
],
[
'integerValue' => 0,
"longValue" => 0,
'name' => "PORTS",
'type' => "STRINGSET",
"doubleValue" => 0.0,
"stringSetValue" => [
"80",
"22"
]
]
]
]);
echo ">".print_r($result, true);
/* $result = $this->ecsClient->runTask([
'taskDefinition' => 'testkaemoDEV4',
'cluster' => 'kaemo'
]);
echo ">".print_r($result, true); */
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}