C:\Users\mpotanin> $instance = aws ec2 describe-instances --instance-ids i-ecf1fe5c C:\Users\...> ConvertFrom-Json $instance ConvertFrom-Json : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'InputObject'. . At line:1 char:19 + ConvertFrom-Json $instance + ~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [ConvertFrom-Json], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
$instance | ConvertFrom-Json ConvertFrom-Json ($instance -join "") ConvertFrom-Json "$instance"
(aws ec2 describe-instances --instance-ids i-ecf1fe5c | ConvertFrom-Json).Reservations[0].Instances[0].PublicIpAddress
aws ec2 describe-instances --instance-ids i-ecf1fe5c --query 'Reservations[0].Instances[0].PublicIpAddress' | ConvertFrom-Json
aws ec2 describe-instances --instance-ids i-ecf1fe5c --query 'Reservations[0].Instances[0].PublicIpAddress' --output=text
function get-address([String]$instanceId) { aws ec2 describe-instances --instance-ids $instanceId --query 'Reservations[0].Instances[0].PublicIpAddress' | convertfrom-json } ssh -i devkey.pem -l ubuntu (get-address i-ecf1fe5c)
function reduce ($f,$a) { if ($a.Length -eq 1) { $a } else { $p = $a[0] foreach ($x in 1..($a.Length-1)) { $p = $f.Invoke($p,$a[$x])[0] } $p } } function get-json($data) { ConvertFrom-json "$data" } function get-cf-outputs($cfName) { $o = (get-json(aws cloudformation describe-stacks --stack-name $cfName)).Stacks[0].Outputs $r = foreach($i in $o) { @{$i.OutputKey = $i.OutputValue} } reduce {param($a,$i); $a+$i } $r }
(get-cf-outputs microservice-rds-dev).DatabaseEndpoint
C:\Users\...> aws dynamodb put-item --table-name tableName --item '{"groupId":{"S":"5"}, "ancestors":{"L":[{"S":"5"},{"S":"0"}]}}' Error parsing parameter '--item': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
function put-item([string]$table, $data) { aws dynamodb put-item --table-name $table --item (convertto-json -Depth 128 $data).Replace('\','\\').Replace('"','\"') }
Source: https://habr.com/ru/post/273473/
All Articles