AWS Elastic Beanstalk .Net WebApp Deploy

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

Deploy a .Net WebApp build to AWS Elastic Beanstalk. This template uses the awsdeploy tool. ALL step fields need to be populated for this template to work.

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

Parameters

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

Profile Name

ProfileName

AWS Profile Name

Application Name

ApplicationName

AWS Application Name

Environment Name

EnvironmentName

AWS Environment Name

Region

Region

AWS Application Region

Upload Bucket

UploadBucket

AWS Application Upload Bucket

Access Key

AccessKey

AWS Access Key

Secret Key

SecretKey

AWS Secret Key

Build Directory

BuildDirectory

Path to the compiled code that needs to be packaged by MSDeploy.

MSDeploy Output Directory

MSDeployOutputDirectory

Path where MSDeploy should put the newly created package.

MSDeploy Params File Path

MSDeployParamsFilePath = parameters.xml

Subpath (relative to your #{BuildDirectory}) to the “parameters.xml” file. Include filename.

Script body

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

$env:Path += ";C:\Program Files (x86)\AWS Tools\Deployment Tool\;C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\"
$AwsDeployConfigFileName = "aws-deploy.config"
$AwsDeployConfigFile = Join-Path $BuildDirectory $AwsDeployConfigFileName
$MSDeployParamsFile = Join-Path $BuildDirectory $MSDeployParamsFilePath
$DeployArchive = Join-Path $MSDeployOutputDirectory.trim().replace(" ", "_") "deploy.zip"

if (!(Test-Path $AwsDeployConfigFile))
{
    # Create an empty, dummy file (not used, awsdeploy params used instead)
    New-Item -path $BuildDirectory -name $AwsDeployConfigFileName -type "file"
}

if (Test-Path $DeployArchive)
{
    # Delete deploy archive if it exists
    Remove-Item $DeployArchive
}

$EscapedBuildDirectory = $BuildDirectory -replace "\\","\\"
$EscapedBuildDirectory = $EscapedBuildDirectory -replace "\.","\."
$MSDeployParamsContent = (Get-Content $MSDeployParamsFile)
$MSDeployParamsContent = $MSDeployParamsContent -replace "{BUILD_DIRECTORY}",$EscapedBuildDirectory
Set-Content $MSDeployParamsFile $MSDeployParamsContent

Write-Host "Creating WebDeploy package file $DeployArchive with the contents of directory $BuildDirectory"
msdeploy.exe -verb:sync `
    -source:iisApp="$BuildDirectory" `
    -dest:package="$DeployArchive" `
    -declareParamFile="$MSDeployParamsFile"

Write-Host "Starting AWSdeploy"
awsdeploy -r -v `
    "-DAWSProfileName=$($ProfileName)" `
    "-DApplication.Name=$($ApplicationName)" `
    "-DEnvironment.Name=$($EnvironmentName)" `
    "-DRegion=$($Region)" `
    "-DUploadBucket=$($UploadBucket)" `
    "-DAWSAccessKey=$($AccessKey)" `
    "-DAWSSecretKey=$($SecretKey)" `
    "-DTemplate=ElasticBeanstalk" `
    "-DDeploymentPackage=$($DeployArchive)" `
    "$AwsDeployConfigFile"

# Sleep to give time to the deployment process to start
Start-Sleep -Seconds 5

$i = 0
$isReady = $FALSE
# Wait no more than 10 minutes for the deployment to finish (or 120 sleeps of 5 seconds)
while ((!$isReady) -and ($i -lt 120)) {
    $i++
    $ebHealth = Get-EBEnvironment -AccessKey "$AccessKey" -SecretKey "$SecretKey" -Region "$Region" -EnvironmentName "$EnvironmentName"

    if ($ebHealth.Status -eq "Ready") {
        Write-Host "Deployment successful."
        $isReady=$TRUE;
    } else {
        Write-Host "Deployment status: $($ebHealth.Status)"
    }
    Start-Sleep -Seconds 5
}

if (!$isReady) {
    Write-Host "Deployment failed. Please check your AWS console."
}

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": "11060b54-15bc-4b12-a912-197c6c18b7b7",
  "Name": "AWS Elastic Beanstalk .Net WebApp Deploy",
  "Description": "Deploy a .Net WebApp build to AWS Elastic Beanstalk. This template uses the awsdeploy tool. ALL step fields need to be populated for this template to work.\n\nAWS Toolkit needs to be installed on your deployment server for this to work properly:\nhttps://aws.amazon.com/visualstudio/",
  "Version": 2,
  "ExportedAt": "2017-01-05T09:21:06.133Z",
  "ActionType": "Octopus.Script",
  "Author": "dovetail-technologies",
  "Parameters": [
    {
      "Name": "ProfileName",
      "Label": "Profile Name",
      "HelpText": "AWS Profile Name",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "ApplicationName",
      "Label": "Application Name",
      "HelpText": "AWS Application Name",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "EnvironmentName",
      "Label": "Environment Name",
      "HelpText": "AWS Environment Name",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "Region",
      "Label": "Region",
      "HelpText": "AWS Application Region",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "UploadBucket",
      "Label": "Upload Bucket",
      "HelpText": "AWS Application Upload Bucket",
      "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": "BuildDirectory",
      "Label": "Build Directory",
      "HelpText": "Path to the compiled code that needs to be packaged by MSDeploy.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    },
    {
      "Name": "MSDeployOutputDirectory",
      "Label": "MSDeploy Output Directory",
      "HelpText": "Path where MSDeploy should put the newly created package.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    },
    {
      "Name": "MSDeployParamsFilePath",
      "Label": "MSDeploy Params File Path",
      "HelpText": "Subpath (relative to your #{BuildDirectory}) to the \"parameters.xml\" file. Include filename.",
      "DefaultValue": "parameters.xml",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.ScriptBody": "$env:Path += \";C:\\Program Files (x86)\\AWS Tools\\Deployment Tool\\;C:\\Program Files (x86)\\IIS\\Microsoft Web Deploy V3\\\"\n$AwsDeployConfigFileName = \"aws-deploy.config\"\n$AwsDeployConfigFile = Join-Path $BuildDirectory $AwsDeployConfigFileName\n$MSDeployParamsFile = Join-Path $BuildDirectory $MSDeployParamsFilePath\n$DeployArchive = Join-Path $MSDeployOutputDirectory.trim().replace(\" \", \"_\") \"deploy.zip\"\n\nif (!(Test-Path $AwsDeployConfigFile))\n{\n    # Create an empty, dummy file (not used, awsdeploy params used instead)\n    New-Item -path $BuildDirectory -name $AwsDeployConfigFileName -type \"file\"\n}\n\nif (Test-Path $DeployArchive)\n{\n    # Delete deploy archive if it exists\n    Remove-Item $DeployArchive\n}\n\n$EscapedBuildDirectory = $BuildDirectory -replace \"\\\\\",\"\\\\\"\n$EscapedBuildDirectory = $EscapedBuildDirectory -replace \"\\.\",\"\\.\"\n$MSDeployParamsContent = (Get-Content $MSDeployParamsFile)\n$MSDeployParamsContent = $MSDeployParamsContent -replace \"{BUILD_DIRECTORY}\",$EscapedBuildDirectory\nSet-Content $MSDeployParamsFile $MSDeployParamsContent\n\nWrite-Host \"Creating WebDeploy package file $DeployArchive with the contents of directory $BuildDirectory\"\nmsdeploy.exe -verb:sync `\n    -source:iisApp=\"$BuildDirectory\" `\n    -dest:package=\"$DeployArchive\" `\n    -declareParamFile=\"$MSDeployParamsFile\"\n\nWrite-Host \"Starting AWSdeploy\"\nawsdeploy -r -v `\n    \"-DAWSProfileName=$($ProfileName)\" `\n    \"-DApplication.Name=$($ApplicationName)\" `\n    \"-DEnvironment.Name=$($EnvironmentName)\" `\n    \"-DRegion=$($Region)\" `\n    \"-DUploadBucket=$($UploadBucket)\" `\n    \"-DAWSAccessKey=$($AccessKey)\" `\n    \"-DAWSSecretKey=$($SecretKey)\" `\n    \"-DTemplate=ElasticBeanstalk\" `\n    \"-DDeploymentPackage=$($DeployArchive)\" `\n    \"$AwsDeployConfigFile\"\n\n# Sleep to give time to the deployment process to start\nStart-Sleep -Seconds 5\n\n$i = 0\n$isReady = $FALSE\n# Wait no more than 10 minutes for the deployment to finish (or 120 sleeps of 5 seconds)\nwhile ((!$isReady) -and ($i -lt 120)) {\n    $i++\n    $ebHealth = Get-EBEnvironment -AccessKey \"$AccessKey\" -SecretKey \"$SecretKey\" -Region \"$Region\" -EnvironmentName \"$EnvironmentName\"\n\n    if ($ebHealth.Status -eq \"Ready\") {\n        Write-Host \"Deployment successful.\"\n        $isReady=$TRUE;\n    } else {\n        Write-Host \"Deployment status: $($ebHealth.Status)\"\n    }\n    Start-Sleep -Seconds 5\n}\n\nif (!$isReady) {\n    Write-Host \"Deployment failed. Please check your AWS console.\"\n}",
    "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-elastic-beanstalk-dotnet-webapp-deploy.json",
  "Website": "/step-templates/11060b54-15bc-4b12-a912-197c6c18b7b7",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////9o0R/eLD/Nu0/erS95Qg+bhr95sv/vHh+r96/vjw+bFc/NSl+KI++82W+saI+KpNeDqM1wAAA41JREFUeNrsnG2XazAURiuo0Cr//9feliIvR3DvXJFZe3+a6XpW5+xWEpyY2w0AAAAAAAAAAAAAAAAAAADgf1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LpWZgu83/vTNRidhlE0rYAAAAAAAAAAAAAAAAAAACAZPkjwAAMDi+bsnPP/wAAAABJRU5ErkJggg==",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Thursday, January 5, 2017