Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/usr/bin/env pwsh
  2. param(
  3. [Parameter(Mandatory)]
  4. $filePrefix,
  5. $s3Lookup = $(Import-PowerShellDataFile "$PSScriptRoot/s3lookup.psd1"),
  6. $profileName = [Environment]::GetEnvironmentVariable('AWSWEB_PROFILE').Trim("`""),
  7. $dataFolderPath = "$PSScriptRoot/data"
  8. )
  9. $InformationPreference = "Continue"
  10.  
  11. if (-not(Test-Path $dataFolderPath)) {
  12. New-Item $dataFolderPath -ItemType Directory | Out-Null
  13. }
  14.  
  15. if ( -not ($s3Lookup.ContainsKey($profileName))) {
  16. throw "Profile missing, ensure $PSScriptRoot/s3Lookup.psd1 contains an entry for $profileName"
  17. }
  18.  
  19. $s3Bucket = $s3Lookup[$profileName]
  20. $result = aws s3api list-objects --bucket $s3Bucket --prefix $filePrefix | ConvertFrom-Json -Depth 100
  21. $files = $result.Contents
  22. $files | ForEach-Object {
  23. $file = $_
  24. $srcFilePath = "s3://$($s3Bucket)/$($file.Key)"
  25. $targetFilePath = "$dataFolderPath/$($file.Key)"
  26. Write-Information "Copying $srcFilePath to $targetFilePath ..."
  27. aws s3 cp $srcFilePath $targetFilePath | Out-Null
  28. Write-Information "Done copying $srcFilePath to $targetFilePath"
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement