Amazon Cloudfront Cache Invalidation

Octopus.Script exported 2017-01-05 by dovetail-technologies belongs to ‘AWS’ category.

Invalidate AWS Cloudfront cache. This template uses the AWS CLI tool. ALL step fields need to be populated for this template to work.

AWS CLI needs to be installed on your deployment server for this to work properly: https://aws.amazon.com/cli/

Parameters

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

AWS credentials profile name

CredentialsProfileName

Used to store your AWS credentials to: ~/.aws/

HAS TO BE UNIQUE - check that no other Octopus projects is using the same AWS credential profile name.

Region

Region

AWS Cloudfront Region

Distribution Id

DistributionId

AWS Cloudfront Distribution Id

Access Key

AccessKey

AWS Access Key

Secret Key

SecretKey

AWS Secret Key

Invalidation Paths

InvalidationPaths

Space-delimited list of paths to invalidate.

For example: /index.html /images/*

Script body

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

Write-Host "Setting up AWS profile environment"
aws configure set aws_access_key_id $AccessKey --profile $CredentialsProfileName
aws configure set aws_secret_access_key $SecretKey --profile $CredentialsProfileName
aws configure set default.region $Region --profile $CredentialsProfileName
aws configure set preview.cloudfront true --profile $CredentialsProfileName

Write-Host "Initiating AWS cloudfront invalidation of the following paths:"
Write-Host $InvalidationPaths
aws cloudfront create-invalidation --profile $CredentialsProfileName --distribution-id $DistributionId --paths $InvalidationPaths

Write-Host "Please note that it may take up to 15-20 minutes for AWS to complete the cloudfront cache invalidation"

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": "de9a03dc-25e1-40fe-8047-716e4462bd23",
  "Name": "Amazon Cloudfront Cache Invalidation",
  "Description": "Invalidate AWS Cloudfront cache. This template uses the AWS CLI tool. ALL step fields need to be populated for this template to work.\n\nAWS CLI needs to be installed on your deployment server for this to work properly:\nhttps://aws.amazon.com/cli/",
  "Version": 1,
  "ExportedAt": "2017-01-05T09:27:06.133Z",
  "ActionType": "Octopus.Script",
  "Author": "dovetail-technologies",
  "Parameters": [
    {
      "Name": "CredentialsProfileName",
      "Label": "AWS credentials profile name",
      "HelpText": "Used to store your AWS credentials to: ~/.aws/\n\nHAS TO BE UNIQUE - check that no other Octopus projects is using the same AWS credential profile name.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "Region",
      "Label": "Region",
      "HelpText": "AWS Cloudfront Region",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "DistributionId",
      "Label": "Distribution Id",
      "HelpText": "AWS Cloudfront Distribution Id",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "AccessKey",
      "Label": "Access Key",
      "HelpText": "AWS Access Key",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "SecretKey",
      "Label": "Secret Key",
      "HelpText": "AWS Secret Key",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "InvalidationPaths",
      "Label": "Invalidation Paths",
      "HelpText": "Space-delimited list of paths to invalidate.\n\nFor example: \n/index.html /images/*",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.ScriptBody": "Write-Host \"Setting up AWS profile environment\"\naws configure set aws_access_key_id $AccessKey --profile $CredentialsProfileName\naws configure set aws_secret_access_key $SecretKey --profile $CredentialsProfileName\naws configure set default.region $Region --profile $CredentialsProfileName\naws configure set preview.cloudfront true --profile $CredentialsProfileName\n\nWrite-Host \"Initiating AWS cloudfront invalidation of the following paths:\"\nWrite-Host $InvalidationPaths\naws cloudfront create-invalidation --profile $CredentialsProfileName --distribution-id $DistributionId --paths $InvalidationPaths\n\nWrite-Host \"Please note that it may take up to 15-20 minutes for AWS to complete the cloudfront cache invalidation\"",
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.NuGetFeedId": null,
    "Octopus.Action.Package.NuGetPackageId": null
  },
  "Category": "AWS",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/aws-cloudfront-invalidate-cache.json",
  "Website": "/step-templates/de9a03dc-25e1-40fe-8047-716e4462bd23",
  "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 Thursday, January 5, 2017