简体   繁体   English

使用PowerShell Core上传到Amazon S3存储桶

[英]Uploading to an Amazon S3 bucket with PowerShell Core

I have a script that works perfectly to upload to an S3 bucket with Windows PowerShell, but it doesn't work with PowerShell Core. 我有一个脚本,可以完美地使用Windows PowerShell上传到S3存储桶,但不适用于PowerShell Core。 According to Amazon, most of the cmdlets that work in one should work in the other. 根据Amazon的说法,在一个中起作用的大多数cmdlet应该在另一个中起作用。

This is the command I'm using: 这是我正在使用的命令:

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

Again, when I try to run the command directly PowerShell it works as expected, but in PowerShell Core I get this error: 同样,当我尝试直接运行命令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

For PowerShell Core you will need to explicitly import the AWSPowerShell.NetCore module before your script or command runs. 对于PowerShell Core,您需要在脚本或命令运行之前显式导入AWSPowerShell.NetCore模块。 Due to the large number of cmdlets (over 5000 currently) in the module we cannot at present list the exported cmdlet names in the module manifest and are exploring other alternatives (such as in future creating per-service modules, but no ETA yet). 由于模块中的cmdlet数量众多(当前超过5000个),我们目前无法在模块清单中列出导出的cmdlet名称,并正在探索其他替代方法(例如,在将来创建按服务的模块中,但尚未建立ETA)。

Assuming a 'clean' machine, then 假设有一台“干净”的机器,那么

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

Should then work for you. 然后应该为您工作。 Of course if you already have the correct module installed then you can skip the first command. 当然,如果您已经安装了正确的模块,则可以跳过第一个命令。 I set up my PowerShell profiles for both Windows and Core to always do an import. 我将Windows和Core的PowerShell配置文件都设置为始终进行导入。

Why this works on Windows, for some, is that up until mid last year we did list the exported cmdlets in the manifest. 对于某些人来说,这在Windows上起作用的原因是直到去年中旬,我们才在清单中列出了导出的cmdlet。 Right when we passed the 4000 cmdlets count in the module however, publishing to the PowerShell Gallery blocked due to a hidden limit and forced us to stop listing them. 就在我们通过模块中的4000个cmdlet计数时,由于隐藏的限制,发布到PowerShell画廊被阻止,并迫使我们停止列出它们。 With the exported cmdlets listed in a manifest, PowerShell doesn't need an explicit import statement. 清单中列出了导出的cmdlet,PowerShell不需要显式的import语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM