AWS Revamps Slow-Loading PowerShell Tools
Slow load times for the growing number of Windows PowerShell scripts ("cmdlets") available on the Amazon Web Services Inc. (AWS) cloud platform has resulted in a revamp, currently in preview.
AWS Tools for PowerShell let PowerShell-using AWS customers manage their cloud resources the same way they manage Windows, Linux and MacOS environments.
AWS provides two modules for PowerShell: AWSPowerShell for PowerShell v2 through v5.1 on Windows; and AWSPowerShell.NetCore for PowerShell v6 or higher on Windows, macOS and Linux.
However, after the number of cmdlets in each AWS PowerShell module increased from about 550 in the 2012 debut to nearly 6,000, problems began to appear.
"First, the import time of the modules has grown significantly," Steve Roberts, senior technical evangelist at AWS in a recent blog post. "On my 8th Gen Core i7 laptop the time to import either module has grown beyond 25 seconds. Second, the team discovered an issue with listing all of the cmdlets in the module manifests and subsequently had to revert to specifying '*' for the CmdletsToExport manifest property. This prevents PowerShell from determining the cmdlets in the modules until they are explicitly imported, impacting tab completion of cmdlet names.
"In my shell profile I use the Set-AWSCredential and Set-DefaultAWSRegion cmdlets to set an initial scope for my shells. Thus I have to first explicitly import the module and then wait for the shell to become usable. This slow load time is obviously unsustainable, even more so when writing AWS Lambda functions in PowerShell when we particularly want a fast startup time."
The answer was a new set of modules offered in preview in order to solicit developer feedback before the new scheme takes effect. That new scheme places each individual AWS service in its own PowerShell module, with all of them depending on a common shared module called AWS.Tools.Common. This is the same modular approach used for AWS SDK for .NET.
Roberts said the benefits of this approach include:
- Instead of downloading and installing a single large module for all services, users can now install only the modules for services actually need. The common module will be installed automatically when a service-specific module is installed.
- Users no longer need to explicitly import any of the preview modules before use, as the CmdletsToExport manifest property for each module is now properly specified.
- The versioning strategy for the new modules currently follows the AWSPowerShell and AWSPowerShell.NetCore modules. The strategy is detailed on the team's GitHub repository notice for the preview and AWS welcomes feedback on it.
- Shell startup time is fast! On the same system Roberts noted earlier the load time for his command shells is now between 1 and 2 seconds on average. "The only change to my shell profile was to remove the explicit module import," he said.
Also, some old or obsolete cmdlets have been removed from the tools package. The older modules will remain operative and updated along with the preview modules as the AWS team ensures backwards compatibility, and the two module sets can't be used at the same time.
The new modules are available in the PowerShell Gallery. More details can be found in a GitHub issue.
David Ramel is the editor of Visual Studio Magazine.