Проблема со скриптом Powershell, передающим файлы в S3 Bucket - PullRequest
0 голосов
/ 15 мая 2018

Я пытаюсь настроить скрипт powershell в попытке настроить автоматический перенос каталога в S3 Bucket, я следую инструкциям, перечисленным в http://todhilton.com/technicalwriting/upload-backup-your-files-to-amazon-s3-with-powershell/, но при запуске я получаю следующую ошибку.

Unable to find type [Amazon.AWSClientFactory].
At line:18 char:9
+ $client=[Amazon.AWSClientFactory]::CreateAmazonS3Client($accessKeyID, ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Amazon.AWSClientFactory:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Код, который я имею, вставлен ниже ... Если у кого-то есть понимание, которое было бы удивительным:)

# Constants
$sourceDrive = "C:\"
$sourceFolder = "Users\Administrator\AppData\Roaming\folder"
$sourcePath = $sourceDrive + $sourceFolder
$s3Bucket = "bucket"
$s3Folder = "Archive"

# Constants – Amazon S3 Credentials
$accessKeyID="KEY"
$secretAccessKey="Secret"

# Constants – Amazon S3 Configuration
$config=New-Object Amazon.S3.AmazonS3Config
$config.RegionEndpoint=[Amazon.RegionEndpoint]::"ap-southeast-2"
$config.ServiceURL = "https://s3-ap-southeast-2.amazonaws.com/"

# Instantiate the AmazonS3Client object
$client=[Amazon.AWSClientFactory]::CreateAmazonS3Client($accessKeyID,$secretAccessKey,$config)

# FUNCTION – Iterate through subfolders and upload files to S3
function RecurseFolders([string]$path) {
  $fc = New-Object -com Scripting.FileSystemObject
  $folder = $fc.GetFolder($path)
  foreach ($i in $folder.SubFolders) {
    $thisFolder = $i.Path

    # Transform the local directory path to notation compatible with S3 Buckets and Folders
    # 1. Trim off the drive letter and colon from the start of the Path
    $s3Path = $thisFolder.ToString()
    $s3Path = $s3Path.SubString(2)
    # 2. Replace back-slashes with forward-slashes
    # Escape the back-slash special character with a back-slash so that it reads it literally, like so: "\\"
    $s3Path = $s3Path -replace "\\", "/"
    $s3Path = "/" + $s3Folder + $s3Path

    # Upload directory to S3
    Write-S3Object -BucketName $s3Bucket -Folder $thisFolder -KeyPrefix $s3Path
  }

  # If subfolders exist in the current folder, then iterate through them too
  foreach ($i in $folder.subfolders) {
    RecurseFolders($i.path)
  }
}

# Upload root directory files to S3
$s3Path = "/" + $s3Folder + "/" + $sourceFolder
Write-S3Object -BucketName $s3Bucket -Folder $sourcePath -KeyPrefix $s3Path

# Upload subdirectories to S3
RecurseFolders($sourcePath)

1 Ответ

0 голосов
/ 15 мая 2018

Пожалуйста, проверьте ниже:

Amazon AWSClientFactory не существует

Change: AWSClientFactory is removed

Я использовал приведенный ниже скрипт:

# Bucket region details
$RegionEndpoint = 'us-east-1'
#$ServiceURL = 'https://s3-us-east-1.amazonaws.com/'

#Credentials initialized
$credsCSV = Get-ChildItem "E:\myAPIUser_credentials.csv" 
$credsContent = Import-Csv $credsCSV.FullName

$accessKeyID = $credsContent.'Access key ID'
$secretAccessKey = $credsContent.'Secret access key'

Initialize-AWSDefaults -Region $RegionEndpoint -AccessKey $accessKeyID -SecretKey $secretAccessKey

$sourceFolder = "E:\Code\powershell\PSmy\git\AWSPowerShell"
$targetFolder = Get-Date -Format "dd-MMM-yyyy"

Write-S3Object -BucketName $s3Bucket.BucketName -Folder $sourceFolder -Recurse -KeyPrefix $targetFolder\
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...