AWS Developer Tools Blog
Listing Cmdlets by Service
In this post, we discussed a new cmdlet you can use to navigate your way around the cmdlets in the AWS Tools for Windows PowerShell module. This cmdlet enables you to search for cmdlets that implemented a service API by answering questions like, “Which cmdlet implements the Amazon EC2 ‘RunInstances’ API?” It can also do a simple translation of AWS CLI commands you might have found in example documentation to give you the equivalent cmdlet.
In the 184.108.40.206 version of the tools, we extended this cmdlet. Now you can use it to get a list of all cmdlets belonging to a service based on words that appear in the service name or the prefix code we use to namespace the cmdlets by service. You could, of course, do something similar by using the PowerShell
Get-Command cmdlet and supplying the
-Noun parameter with a value that is the prefix with a wildcard (for example,
Get-Command -Module AWSPowerShell -Noun EC2*). The problem here is that you need to know the prefix before you can run the command. Although we try to choose memorable and easily guessable prefixes, sometimes the association can be subtle and searching based on one or more words in the service name is more useful.
To list cmdlets by service you supply the
-Service parameter. The value for this parameter is always treated as a case-insensitive regular expression and is used to match against cmdlets using both their ‘namespace’ prefix and full name. For example:
PS C:> Get-AWSCmdletName -Service compute CmdletName ServiceOperation ServiceName ---------- ---------------- ----------- Add-EC2ClassicLinkVpc AttachClassicLinkVpc Amazon Elastic Compute Cloud Add-EC2InternetGateway AttachInternetGateway Amazon Elastic Compute Cloud Add-EC2NetworkInterface AttachNetworkInterface Amazon Elastic Compute Cloud Add-EC2Volume AttachVolume Amazon Elastic Compute Cloud ... Stop-EC2SpotInstanceRequest CancelSpotInstanceRequests Amazon Elastic Compute Cloud Unregister-EC2Address DisassociateAddress Amazon Elastic Compute Cloud Unregister-EC2Image DeregisterImage Amazon Elastic Compute Cloud Unregister-EC2PrivateIpAddress UnassignPrivateIpAddresses Amazon Elastic Compute Cloud Unregister-EC2RouteTable DisassociateRouteTable Amazon Elastic Compute Cloud
When a match for the parameter value is found, the output contains a collection of
PSObject instances. Each instance has members detailing the cmdlet name, service operation, and service name. You can see the assigned prefix code in the cmdlet name. If the search term fails to match any supported service, you’ll see an error message in the output.
You might be asking yourself why we output the service name. We do this because the parameter value is treated as a regular expression and it attempts to match against two pieces of metadata in the module’s cmdlets (service and prefix). It is therefore possible that a term can match more than one service. For example:
PS C:> Get-AWSCmdletName -Service EC2 CmdletName ServiceOperation ServiceName ---------- ---------------- ----------- Add-EC2ClassicLinkVpc AttachClassicLinkVpc Amazon Elastic Compute Cloud Add-EC2InternetGateway AttachInternetGateway Amazon Elastic Compute Cloud ... Unregister-EC2RouteTable DisassociateRouteTable Amazon Elastic Compute Cloud Get-ECSClusterDetail DescribeClusters Amazon EC2 Container Service Get-ECSClusters ListClusters Amazon EC2 Container Service Get-ECSClusterService ListServices Amazon EC2 Container Service ... Unregister-ECSTaskDefinition DeregisterTaskDefinition Amazon EC2 Container Service Update-ECSContainerAgent UpdateContainerAgent Amazon EC2 Container Service Update-ECSService UpdateService Amazon EC2 Container Service
You’ll see the result set contains cmdlets for both Amazon EC2 and Amazon EC2 Container Service. This is because the search term ‘EC2’ matched the noun prefix for the cmdlets exposing the Amazon EC2 service API as well as the service name for the container service.
We hope you find this new capability useful. You can get the new version as a Windows Installer package here or through the PowerShell Gallery.
If you have suggestions for other features, let us know in the comments!