gpt4 book ai didi

amazon-web-services - 使用 PowerShell Core 上传到 Amazon S3 存储桶

转载 作者:行者123 更新时间:2023-12-05 02:14:22 25 4
gpt4 key购买 nike

我有一个脚本可以完美地使用 Windows PowerShell 上传到 S3 存储桶,但它不适用于 PowerShell Core。根据 Amazon 的说法,大多数在一个中运行的 cmdlet 应该在另一个中运行。

这是我正在使用的命令:

Write-S3Object -BucketName $bucketName -Folder $localDir -KeyPrefix $targetFolder -AccessKey $accessKey -SecretKey $secretKey -Recurse

同样,当我尝试直接在 PowerShell 中运行命令时,它按预期工作,但在 PowerShell Core 中出现此错误:

Write-S3Object : The term 'Write-S3Object' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Write-S3Object -BucketName "cloud-storage-poc" -Folder "C:\Users\Admi ...
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-S3Object:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

最佳答案

对于 PowerShell Core,您需要在脚本或命令运行之前显式导入 AWSPowerShell.NetCore 模块。由于模块中有大量 cmdlet(目前超过 5000 个),我们目前无法在模块 list 中列出导出的 cmdlet 名称,并且正在探索其他替代方案(例如将来创建每个服务的模块,但还没有 ETA)。

假设有一台“干净”的机器,那么<​​/p>

Install-Module AWSPowerShell.NetCore
Import-Module AWSPowerShell.NetCore
Write-S3Object ...

然后应该为你工作。当然,如果您已经安装了正确的模块,那么您可以跳过第一个命令。我将 Windows 和 Core 的 PowerShell 配置文件设置为始终执行导入。

对于某些人来说,为什么这在 Windows 上有效,是因为直到去年年中我们才在 list 中列出了导出的 cmdlet。然而,就在我们通过模块中的 4000 个 cmdlet 计数时,发布到 PowerShell Gallery 由于隐藏限制而被阻止并迫使我们停止列出它们。通过在 list 中列出导出的 cmdlet,PowerShell 不需要显式导入语句。

关于amazon-web-services - 使用 PowerShell Core 上传到 Amazon S3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53643033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com