Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env pwsh
- param(
- [Parameter(Mandatory)]
- $filePrefix,
- $s3Lookup = $(Import-PowerShellDataFile "$PSScriptRoot/s3lookup.psd1"),
- $profileName = [Environment]::GetEnvironmentVariable('AWSWEB_PROFILE').Trim("`""),
- $dataFolderPath = "$PSScriptRoot/data"
- )
- $InformationPreference = "Continue"
- if (-not(Test-Path $dataFolderPath)) {
- New-Item $dataFolderPath -ItemType Directory | Out-Null
- }
- if ( -not ($s3Lookup.ContainsKey($profileName))) {
- throw "Profile missing, ensure $PSScriptRoot/s3Lookup.psd1 contains an entry for $profileName"
- }
- $s3Bucket = $s3Lookup[$profileName]
- $result = aws s3api list-objects --bucket $s3Bucket --prefix $filePrefix | ConvertFrom-Json -Depth 100
- $files = $result.Contents
- $files | ForEach-Object {
- $file = $_
- $srcFilePath = "s3://$($s3Bucket)/$($file.Key)"
- $targetFilePath = "$dataFolderPath/$($file.Key)"
- Write-Information "Copying $srcFilePath to $targetFilePath ..."
- aws s3 cp $srcFilePath $targetFilePath | Out-Null
- Write-Information "Done copying $srcFilePath to $targetFilePath"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement