安装 AWSPower外壳。 NetCore 在 Linux 或 macOS 上 - AWS Tools for PowerShell (版本 5)

的版本 5 (V5) AWS Tools for PowerShell 已经发布!

有关重大更改和迁移应用程序的信息,请参阅迁移主题

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

安装 AWSPower外壳。 NetCore 在 Linux 或 macOS 上

有关 AWS Tools for PowerShell 在 Linux 或 macOS 上安装的一般信息,包括先决条件和其他选项,请参阅父主题

有关上预安装 PowerShell 的工具的信息 AWS CloudShell,请参阅已安装在 CloudShell

注意

AWSPower壳牌。 NetCore 不是安装的推荐方法 AWS Tools for PowerShell。有关推荐的方法,请参安装AWS.Tools(推荐)阅。

升级到较新版本的 AWSPower Shell。 NetCore,请按照中的说明进行操作AWS Tools for PowerShell 在 Linux 或 macOS 上更新。卸载早期版本的 AWSPower命令行管理程序。 NetCore 第一。

你可以安装 AWSPower命令行管理程序。 NetCore 用以下两种方式之一:

  • AWSPowerShell.NetCore.zip 下载模块并将其提取到其中一个模块目录中。您可以通过输出 $Env:PSModulePath 变量的值来查找模块目录。

  • 按照以下步骤所述,使用 Install-Module cmdlet 从 PowerShell 库中安装。

安装 AWSPower命令行管理程序。 NetCore 在 Linux 或 macOS 上使用 Install-Module cmdle t

通过运行以下命令启动 PowerShell 核心会话。

$ pwsh
注意

我们建议您不要sudo pwsh以提升的管理员权限开始 PowerShell 运行 PowerShell 。这是因为此操作具有潜在的安全风险,并且不符合最低特权原则。

安装 AWSPower命令行管理程序。 NetCore PowerShell 图库中的单模块包,运行以下命令。

PS > Install-Module -Name AWSPowerShell.NetCore Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y

如果您收到存储库 “不可信” 的通知,则系统会询问您是否要安装。输入y PowerShell 以允许安装模块。为了在不信任存储库的情况下避免出现提示,您可以运行以下命令。

PS > Install-Module -Name AWSPowerShell.NetCore -Force

除非您想为计算机的所有用户安装,否则不必以 root 用户身份运行此命令。 AWS Tools for PowerShell 为此,请在已启动的 PowerShell 会话中运行以下命令sudo pwsh

PS > Install-Module -Scope AllUsers -Name AWSPowerShell.NetCore -Force

脚本执行

Set-ExecutionPolicy 命令在非 Windows 系统上不可用。你可以运行Get-ExecutionPolicy,这表明在非 Windows 系统上运行的 PowerShell Core 中的默认执行策略设置为Unrestricted。有关更多信息,请参阅 Microsoft Technet 网站上的关于执行策略

由于PSModulePath包含 AWS 模块目录的位置,因此 Get-Module -ListAvailable cmdlet 会显示您安装的模块。

AWSPower壳牌。 NetCore

PS > Get-Module -ListAvailable Directory: /Users/username/.local/share/powershell/Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 3.3.563.1 AWSPowerShell.NetCore

将 PowerShell 控制台配置为使用 AWS Tools for PowerShell Core (AWSPowerShell. NetCore 只有)

PowerShell 每当你在模块中运行 cmdlet 时,Core 通常都会自动加载模块。但这对 AWSPower壳牌不起作用。 NetCore 因为它的体积很大。开始运行 AWSPower命令行管理程序。 NetCore cmdlet,你必须先运行该命令。Import-Module AWSPowerShell.NetCoreAWS.Tools 模块中的 cmdlet 不需要此操作。

初始化您的 PowerShell 会话

安装完之后,在基于 Linux 或 macOS 的系统 PowerShell 上启动时 AWS Tools for PowerShell,必须运行 “初始化-AWSDefault 配置” 来指定要使用的 AWS 访问密钥。有关 Initialize-AWSDefaultConfiguration的更多信息,请参阅使用 AWS 凭证

注意

在的早期(3.3.96.0 之前)版本中,此 cmdlet 被 AWS Tools for PowerShell命名为。Initialize-AWSDefaults

版本控制

AWS AWS Tools for PowerShell 定期发布新版本以支持新的 AWS 服务和功能。要确定已安装的版本 AWS Tools for PowerShell ,请运行 Get-AWSPower ShellVersion cmdlet。

例如:

PS > Get-AWSPowerShellVersion AWS Tools for PowerShell Version 5.0.3 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Amazon Web Services SDK for .NET Core Runtime Version 4.0.0.13 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Release notes: https://github.com/aws/aws-tools-for-powershell/blob/main/changelogs/CHANGELOG.ALL.md This software includes third party software subject to the following copyrights: - Logging from log4net, Apache License [http://logging.apache.org/log4net/license.html]

要查看当前版本工具中支持的 AWS 服务列表,请将-ListServiceVersionInfo参数添加到 Get-AWSPower ShellVersion cmdlet 中。

要确定您正在运行 PowerShell 的版本,请输入$PSVersionTable以查看$PSVersionTable自动变量的内容。

例如:

PS > $PSVersionTable Name Value ---- ----- PSVersion 6.2.2 PSEdition Core GitCommitId 6.2.2 OS Darwin 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 Platform Unix PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0

AWS Tools for PowerShell 在 Linux 或 macOS 上更新

随着更新版本的 AWS Tools for PowerShell 发布,您应该定期更新在本地运行的版本。

更新 PowerShell 核心工具

运行 Get-AWSPowerShellVersion cmdlet 以确定你正在运行的版本,并将其与PowerShell 图库网站上提供的适用于 Windows PowerShell 的工具版本进行比较。我们建议您每两到三个星期检查一次。只有在更新到支持新命令和 AWS 服务的版本后,才会提供对新命令和服务的支持。

在安装更新版本的 AWSPower Shell 之前。 NetCore,卸载现有模块。在卸载现有软件包之前,请关闭所有打开的 PowerShell 会话。运行以下命令来卸载该程序包。

PS > Uninstall-Module -Name AWSPowerShell.NetCore -AllVersions

在卸载程序包后,通过运行以下命令来安装更新的模块。

PS > Install-Module -Name AWSPowerShell.NetCore

安装完成后,运行命令将更新后的 cmdlet 加载Import-Module AWSPowerShell.NetCore到您的 PowerShell 会话中。

相关信息