Trying to call an aws api which gives the master IP address. When I'm calling this api via command it is working fine. Using powershell for this. But, I want to call this api UI using php.While calling via php I am not able to call this api.
My powershell script is,
Clear-Host
Clear-History
$Username = "**"
$Password = "***"
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
$ips = @()
Write-Host "----------------------------------"
Try
{
echo "Creating Instances will start now..."
python C:\AWS\Distributed-setup-3\CreateInstance.py
}
Catch
{
echo "Instance not created"
exit
}
Write-Host "----------------------------------"
echo "Creating setup...."
Start-Sleep -Seconds 60
python C:\AWS\Distributed-setup-3\statusCheck.py
Start-Sleep -Seconds 60
$content = Get-Content C:\AWS\Distributed-setup-3\InstanceId.txt
echo $content
Write-Host "----------------------------------"
ForEach ($id In $content){
echo "execute.ps1 id"
echo $id
$instances = aws ec2 describe-instances --instance-ids $id --query Reservations[].Instances[].PublicIpAddress
$instance = $instances[1]
$instance = $instance -replace '"' , ""
$instance = $instance.Trim()
$ips = $ips+$instance
}
Write-Host "----------------------------------"
Clear-Content 'C:\AWS\Distributed-setup-3\ipconfig.txt'
ForEach ($i In $ips){
#echo $i
if($i -eq ($ips[0])){
Write-Host "Master is "$i
}
else
{
Write-Host "Client "$i
$index = [array]::indexof($ips,$i)
$index = $index+1
if($ips[$index] -eq $null){
$i | Add-Content 'C:\AWS\Distributed-setup-3\ipconfig.txt'
}
else{
$i = $i+","
$i | Add-Content 'C:\AWS\Distributed-setup-3\ipconfig.txt'
}
}
}
Write-Host "----------------------------------"
aws s3 cp C://AWS/Distributed-setup-3/ipconfig.txt s3://s3merahkee
aws s3 cp C://AWS/Distributed-setup-3/Input.yaml s3://s3merahkee
Write-Host "----------------------------------"
Write-Host "Executing jmeter distributed test on remote system" $ips
Write-Host "----------------------------------"
ForEach ($ip In $ips){
if($ip -eq ($ips[0])){
#echo "Executing hub"
Write-Host "Master ip is "$ip
}
else
{
#Write-Host "Executing slave "$ip
Start-Job "C:\AWS\Distributed-setup-3\instance_2.ps1" -ArgumentList $ip
}
}
Start-Sleep -Seconds 60
Write-Host "----------------------------------"
Get-job | Receive-Job
Write-Host "----------------------------------"
$hub = $ips[0]
echo -n "Executing Master :"$hub
Start-Sleep -Seconds 10
Invoke-Command -ComputerName $hub -ScriptBlock { cmd.exe /c C:\Users\Administrator\Desktop\gitclone.bat } -credential $Cred
Write-Host "----------------------------------"
ForEach ($ip In $ips){
echo -n "Executing on remote system for reports " $ip
Try
{
Invoke-Command -ComputerName $ip -ScriptBlock { cmd.exe /c C:\Users\Administrator\Desktop\report.bat } -credential $Cred
}
Catch{
echo "Unable to connect check the remote connection permission"
}
}
Write-Host "----------------------------------"
ForEach ($id In $content){
$instances = aws ec2 describe-instances --instance-ids $id --query 'Reservations[].Instances[].PrivateIpAddress'
$instance = $instances[1]
$instance = $instance -replace '"' , ""
$i = $instance.Trim()
#echo $i
aws s3 cp s3://s3merahkee/Logs/$i C:\AWS\Distributed-setup-3\Reports --recursive
cd C:\AWS\Distributed-setup-3\Reports
Rename-Item jmeter-server.log jmeter-server_$i.log
}
Write-Host "----------------------------------"
echo "Terminating instance"
ForEach ($id In $content){
aws ec2 terminate-instances --instance-ids $id
}
Write-Host "----------------------------------"
Write-Host "Execution completed"
In php file,
<?php
ini_set('max_execution_time', 500);
$output= shell_exec('aws ec2 describe-instances --instance-ids i-03bb2e6b53fcd4335 --query Reservations[].Instances[].PublicIpAddress');
echo( '<pre>' );
echo( $output );
echo( '</pre>' );
?>
Here the api is,
aws ec2 describe-instances --instance-ids $id --query Reservations[].Instances[].PublicIpAddress
Trying to do it quite a lot time, still unsuccessful in this, can anyone help ?