Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS CLIの全サブコマンドとPowerShell Cmdletの対応表を出力するやつ
Import-Module AWSPowerShell.NetCore
Get-ChildItem C:\temp\awscli\*.txt | ForEach-Object {
Write-Host "$($_.BaseName)..." -ForegroundColor Green
#
$serviceName = $_.BaseName
$commands = $_ | Get-Content | ForEach-Object {
try {
# 1つの AwsCliCommand から複数の Cmdlet を返す場合がある
$awsCLI = $_
$awsCLISubcommandName = ($awsCLI -replace "aws $serviceName","").Trim()
$awsCLIUrl = "https://docs.aws.amazon.com/cli/latest/reference/$serviceName/$awsCLISubcommandName.html"
Get-AWSCmdletName -AwsCliCommand $awsCLI | ForEach-Object {
$o = [PSCustomObject]@{
CLI = $awsCLI
CLISubCommand = $awsCLISubcommandName
CLIUrl = $awsCLIUrl
CmdLet = ''
CmdletUrl = ''
ServiceName = ''
Prefix = ''
ServiceOperation = ''
}
$o.Cmdlet = $_.CmdletName
$o.CmdletUrl = "https://docs.aws.amazon.com/powershell/latest/reference/items/$($_.CmdletName).html"
$o.Prefix = $_.CmdletNounPrefix
$o.ServiceName = $_.ServiceName
$o.ServiceOperation = $_.ServiceOperation
Write-Output $o
}
} catch {
$o = [PSCustomObject]@{
CLI = $awsCLI
CLISubCommand = $awsCLISubcommandName
CLIUrl = $awsCLIUrl
CmdLet = ''
CmdletUrl = ''
ServiceName = ''
Prefix = ''
ServiceOperation = ''
}
Write-Output $o
}
}
# output
$markdown = if ($null -eq $commands) {
& {
"# $serviceName"
""
"* No CLI commands"
""
} | Out-String
} else {
& {
"# $serviceName"
""
"* [CLI Reference($serviceName)](https://docs.aws.amazon.com/cli/latest/reference/$serviceName/index.html)"
""
"|AWS CLI|PowerShell|Prefix|"
"|----|----|:--:|"
foreach ($c in $commands) {
if ($c.CmdLet) {
"|[$($c.CLI)]($($c.CLIUrl))|[$($c.CmdLet)]($($c.CmdletUrl))|$($c.Prefix)|"
} else {
"|[$($c.CLI)]($($c.CLIUrl))||$($c.Prefix)|"
}
}
} | Out-String
}
$markdown | Out-File -FilePath ".\markdown\$($_.BaseName).md"
}
#!/bin/bash
for c in $(aws list-commands 2>&1 | tail -n +9 | awk -F'|' '{printf "%s\n%s\n",$1,$2}' | tr -d ' ')
do
# wait, help,空白 は除外
# /mnt/c/temp/awscli/ に出力
eval "aws $c list-commands" 2>&1 | tail -n +9 | awk -F'|' '{printf "%s\n%s\n",$1,$2}' | tr -d ' ' | sed -e /wait/d -e /help/d -e /^$/d | \
awk -v "v1=$c" '{printf "aws %s %s\n",v1,$0}' > "/mnt/c/temp/awscli/$c.txt"
done
  • その他ちょっとしたコマンドたち
# AWS CLIのバージョン取得
aws --version 2>&1 | awk '{print $1}' | awk -F'/' '{print $2}'

# PowerShellのバージョン取得
Get-Module AWSPowerShell.NetCore | ForEach-Object { $_.Version.ToString() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.