Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
Last active September 9, 2019 12:18
Show Gist options
  • Save leandrosilva/971a053236f0d912b5b1c33573cd2621 to your computer and use it in GitHub Desktop.
Save leandrosilva/971a053236f0d912b5b1c33573cd2621 to your computer and use it in GitHub Desktop.
PowerShell module with helper functions to deal with AWS S3
####################
# EXTERNAL MODULES #
####################
# https://docs.aws.amazon.com/powershell/latest/reference/Index.html
if (-not (Get-Module -ListAvailable -Name AWSPowerShell)) {
"AWS module is not installed. Let's get it installed..."
Install-Module -Name AWSPowerShell
}
####################
# HELPER FUNCTIONS #
####################
# https://docs.aws.amazon.com/powershell/latest/reference/items/Get-S3ObjectMetadata.html
# https://docs.aws.amazon.com/powershell/latest/reference/items/Read-S3Object.html
function Get-RemoteVersionCatalogMetadata {
return Get-S3ObjectMetadata `
-Region $env:APP_S3_REGION `
-AccessKey $env:APP_S3_ACCESS_KEY `
-SecretKey $env:APP_S3_SECRET_KEY `
-BucketName $env:APP_S3_BUCKET `
-Key configs/dummyapp-version-catalog.json `
-ErrorAction Stop
}
function Read-RemoteVersionCatalog ($LocalFilePath) {
$_ = Read-S3Object `
-Region $env:APP_S3_REGION `
-AccessKey $env:APP_S3_ACCESS_KEY `
-SecretKey $env:APP_S3_SECRET_KEY `
-BucketName $env:APP_S3_BUCKET `
-Key configs/dummyapp-version-catalog.json `
-File $LocalFilePath `
-ErrorAction Stop
if ($_) {
"Download has completed: $LocalFilePath."
}
}
function Read-RemotePackage ($Version, $LocalFilePath) {
$_ = Read-S3Object `
-Region $env:APP_S3_REGION `
-AccessKey $env:APP_S3_ACCESS_KEY `
-SecretKey $env:APP_S3_SECRET_KEY `
-BucketName $env:APP_S3_BUCKET `
-Key releases/$Version.zip `
-File $LocalFilePath `
-ErrorAction Stop
if ($_) {
"Download has completed: $LocalFilePath."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment