Amazon S3 Upload

Octopus.Script exported 2018-04-10 by Phillip Haydon belongs to ‘AWS’ category.

Upload files and folders to an S3 bucket from a specified location.

Either specify a single file or a folder containing the files and folders to be uploaded.

Important! For this plugin to function, you must install AWS Tools for Windows PowerShell on your tentacle server and you must restart your tentacle service.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

S3 Region

S3Region = eu-west-1

A region is the location that your S3 bucket was created.

Amazon has many different region names and you can read more about Amazon Region names here.

Default Region If you didn’t specify a region when setting up your S3 buckets, you may be using the default. According to Amazon:

For accounts created on or after March 8, 2013, the default region is us-west-2; for older accounts, the default region is us-east-1.

Bucket Name

S3Bucket =

This is the name of the bucket on S3 to which you’d like your files and folders uploaded.

Prefix

S3Prefix =

This is the prefix for the path you want the folder to be uploaded to if they differ from the source structure.

Source Folder

SourceFolderLocation =

This is the local folder located on your tentacle server that you’d like to upload to S3

Example: C:\Deployment\S3Distributables

Access Key ID

S3AccessKey =

Your public S3 Key.

This can be found by clicking My Account/Consoles and navigating to Security Credentials.

Secret Access Key

S3SecretKey =

Your private S3 Key.

This can be found by clicking My Account/Consoles and navigating to Security Credentials.

Make Public

MakePublic = False

null

Recursive

Recursive = True

Do you want to upload to loop through all of the child folders/files and retrieve everything?

Script body

Steps based on this template will execute the following PowerShell script.


$recurse = [boolean]::Parse($Recursive)

$params = @{}

#Sets the Permissions to public if the selection is true
if ($MakePublic -eq $True) {
    $params.add("CannedACLName", "public-read")
}

#Initialises the S3 Credentials based on the Access Key and Secret Key provided, so that we can invoke the APIs further down
Set-AWSCredentials -AccessKey $S3AccessKey -SecretKey $S3SecretKey -StoreAs S3Creds

#Initialises the Default AWS Region based on the region provided
Set-DefaultAWSRegion -Region $S3Region

#Gets all relevant files and uploads them
function Upload($item) 
{
    #Gets all files and child folders within the given directory
    foreach ($i in Get-ChildItem $item) {

        #Checks if the item is a folder
        if($i -is [System.IO.DirectoryInfo]) {

            #Inserts all files within a folder to AWS           
            Write-S3Object -ProfileName S3Creds -BucketName $S3Bucket -KeyPrefix $S3Prefix$($i.Name) -Folder $i.FullName -Recurse:$recurse @params

        } else {

            #Inserts file to AWS
            Write-S3Object -ProfileName S3Creds -BucketName $S3Bucket -Key $S3Prefix$($i.Name) -File $i.FullName @params

        }
    }
}

Upload($SourceFolderLocation)

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "302e0653-e84e-4db6-be53-1ee1a56dea88",
  "Name": "Amazon S3 Upload",
  "Description": "Upload files and folders to an S3 bucket from a specified location.\n\nEither specify a single file or a folder containing the files and folders to be uploaded.\n\n**Important!** _For this plugin to function, you must install [AWS Tools for Windows PowerShell](http://aws.amazon.com/powershell/) on your tentacle server and you must restart your tentacle service._",
  "Version": 11,
  "ExportedAt": "2018-04-10T11:05:46.352Z",
  "ActionType": "Octopus.Script",
  "Author": "Phillip Haydon",
  "Parameters": [
    {
      "Name": "S3Region",
      "Label": "S3 Region",
      "HelpText": "A region is the location that your S3 bucket was created.\n\nAmazon has many different region names and you [can read more about Amazon Region names here](http://docs.aws.amazon.com/general/latest/gr/rande.html).\n\n**Default Region**\nIf you didn't specify a region when setting up your S3 buckets, you may be using the default. According to Amazon:\n>  For accounts created on or after March 8, 2013, the default region is us-west-2; for older accounts, the default region is us-east-1.",
      "DefaultValue": "eu-west-1",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "us-east-1\nus-west-1\nus-west-2\nap-south-1\nap-northeast-2\nap-southeast-1\nap-southeast-2\nap-northeast-1\neu-central-1\neu-west-1\nsa-east-1"
      }
    },
    {
      "Name": "S3Bucket",
      "Label": "Bucket Name",
      "HelpText": "This is the name of the bucket on S3 to which you'd like your files and folders uploaded.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "S3Prefix",
      "Label": "Prefix",
      "HelpText": "This is the prefix for the path you want the folder to be uploaded to if they differ from the source structure.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "SourceFolderLocation",
      "Label": "Source Folder",
      "HelpText": "This is the local folder located on your tentacle server that you'd like to upload to S3\n\nExample: _C:\\Deployment\\S3Distributables_",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "S3AccessKey",
      "Label": "Access Key ID",
      "HelpText": "Your public S3 Key.\n\nThis can be found by clicking _My Account/Consoles_ and navigating to _Security Credentials_.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "S3SecretKey",
      "Label": "Secret Access Key",
      "HelpText": "Your private S3 Key.\n\nThis can be found by clicking _My Account/Consoles_ and navigating to _Security Credentials_.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "MakePublic",
      "Label": "Make Public",
      "HelpText": null,
      "DefaultValue": "False",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    },
    {
      "Name": "Recursive",
      "Label": "Recursive",
      "HelpText": "Do you want to upload to loop through all of the child folders/files and retrieve everything?",
      "DefaultValue": "True",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "\n$recurse = [boolean]::Parse($Recursive)\n\n$params = @{}\n\n#Sets the Permissions to public if the selection is true\nif ($MakePublic -eq $True) {\n    $params.add(\"CannedACLName\", \"public-read\")\n}\n\n#Initialises the S3 Credentials based on the Access Key and Secret Key provided, so that we can invoke the APIs further down\nSet-AWSCredentials -AccessKey $S3AccessKey -SecretKey $S3SecretKey -StoreAs S3Creds\n\n#Initialises the Default AWS Region based on the region provided\nSet-DefaultAWSRegion -Region $S3Region\n\n#Gets all relevant files and uploads them\nfunction Upload($item) \n{\n    #Gets all files and child folders within the given directory\n    foreach ($i in Get-ChildItem $item) {\n\n        #Checks if the item is a folder\n        if($i -is [System.IO.DirectoryInfo]) {\n\n            #Inserts all files within a folder to AWS           \n            Write-S3Object -ProfileName S3Creds -BucketName $S3Bucket -KeyPrefix $S3Prefix$($i.Name) -Folder $i.FullName -Recurse:$recurse @params\n\n        } else {\n\n            #Inserts file to AWS\n            Write-S3Object -ProfileName S3Creds -BucketName $S3Bucket -Key $S3Prefix$($i.Name) -File $i.FullName @params\n\n        }\n    }\n}\n\nUpload($SourceFolderLocation)\n",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "Category": "AWS",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/amazon-s3-upload.json",
  "Website": "/step-templates/302e0653-e84e-4db6-be53-1ee1a56dea88",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////9o0R/eLD/Nu0/erS95Qg+bhr95sv/vHh+r96/vjw+bFc/NSl+KI++82W+saI+KpNeDqM1wAAA41JREFUeNrsnG2XazAURiuo0Cr//9feliIvR3DvXJFZe3+a6XpW5+xWEpyY2w0AAAAAAAAAAAAAAAAAAADgf1J0bda/9N70q83a3enzUHWVjbR1sW0xp6sd6fPI72VmUt3zA+kymD6N5vnIBMrHsxHTjsUXOX0e+iVaTNU5Q0A/Q+k+4oAp+ixMbw6A4rGVVjGHR92ulNXWuTAlBNJN/FFyr5yy3qN9rawmF9IxR4hqX4U1WMplmGtruVBDuiuswbKkzaGhX+cfXsqbZlXXv0dsYR13nw9fLenGXD7f6U5Ony4yTpzyZLNMUcpMr0xNzfwdRRMR1/LP2cqMctNqKx1LZFydm2U022ueEtLL6HbHfmSRYRn4HDXaXyzU4XRkkZWK/+JlRBBBBBFEEEEEEUQQQQQRRBBB5B9uYJc7SyuLw+nI7R2ptKWJcywd18Utza0rnM4iN66M6qzS5E93Lf1zLaviUL/ISs/Nt6W00DEyuRgiP2Yxvrd15z/Y26ncG76jy1Ta5jEy/L0p/VMWy33woVm8UYN1Y9fqKrzfZ5iedtaV34+kNxHak2Wg2SSkY7djx/bQWkNP6nkE0lH3Lyx7D1aak1Z1erWJ+U130Vz0Sude7mZqv995nW7mZxJd27Sg5XQppuMdWY3xl1XXOge8MasWjZfund0KbvrkE9fK7OPNne+2U9YEWX3nemtSbvLv6LJ7gZ9X45yBl9ZxrZ9d3vjT8rz62tOsny7jXkpYPX9jQmvF8yF55TdaslGviZy1vAmfoTobsZztGNEv7qZZSr/6HRc/0yzlb3HiKhURRBBBBBFEEEEEEUQQQQQRRBD5XSLav38tllbVzeH02Ww/UWA+6XgsHdXFKc2vK5Quoz/duVRnlrb26crpizzXOVU3l2Zb5Pfe+d1OX8ViqW7qH9gt51K44bukr2XxrW54vMaoy7mxa/cgvPRVKcQG7uOCD58HLQLt3r17Iy6AqjYeDG7TUenWW+p9Ot/IOF/lwuHV1nk6o8M469PWXhtr+0BeX/x7Ue40W3xacfb2gXFxUZcX8TYB3Kyfp+GThsjKti2zgZuMiLshxW3gpiQyrn/DXhR/i1NqIte5pkUEEUQQQQQRRBBBBBFEEEEEEUR+g4jQUZBEqjqFO9mOiyeShoXvYoukZOG4GCLpWZgu83/vTNRidhlE0rYAAAAAAAAAAAAAAAAAAACAZPkjwAAMDi+bsnPP/wAAAABJRU5ErkJggg==",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Tuesday, April 10, 2018