AWS - Create Lambda (deprecated)

Octopus.Script exported 2018-04-16 by harrisonmeister belongs to ‘AWS’ category.

Creates a AWS Lambda Function from the specified zip.

If the function exists, it will update the function code and update function configuration.

To create environment variables, add variables in project starting with ‘env.’. For example, to create environment variable S3BucketName = MyTestFolder, create variable ‘env.S3BucketName’ = ‘MyTestFolder’. This function has been deprecated in favor of the new AWS Deploy Lambda step template. That new step requires 2019.10.x to run properly. This step is left in place for older versions of Octopus Deploy to still use.

Parameters

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

AWS Secret Access Key

AWSSecretAccessKey =

The secret access key to use when executing the script

AWS Access Key

AWSAccessKey =

The access key to use when executing the script

AWS Region

AWSRegion =

The Amazon Region see https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/ for further info

AWS Lambda Function Name

FunctionName =

The name of the AWS Lambda Function

AWS Lambda Function Zip Location

FunctionZip =

The zip location of the AWS Lambda Function

AWS Lambda Function Handler

Handler =

The handler signature (ASSEMBLY::TYPE::METHOD) of the AWS Lambda Function

AWS Lambda Function Runtime

Runtime =

The runtime of the AWS Lambda Function

AWS Lambda Function Role

Role =

The role of the AWS Lambda Function, in ARN format

AWS Lambda Function Description

Description =

The description of the AWS Lambda Function

AWS Lambda Function Memory Size

MemorySize = 128

The memory size of the AWS Lambda Function. The default value is 128 MB. The value must be a multiple of 64 MB

AWS Lambda Function Timeout

Timeout =

The timeout of the AWS Lambda Function

AWS Lambda Function VPC Subnet Id

AWSCL_VpcConfig_SubnetId =

A list of one or more subnet IDs in your VPC.

AWS Lambda Function VPC Security Group Id

AWSCL_VpcConfig_SecurityGroupId =

A list of one or more security groups IDs in your VPC.

Script body

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

# Check for the PowerShell cmdlets (from AWS - Create Cloud Formation Stack Octopus Step).
try{ 
    Import-Module AWSPowerShell -ErrorAction Stop
}catch{
    
    $modulePath = "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1"
    Write-Output "Unable to find the AWS module checking $modulePath" 
    
    try{
        Import-Module $modulePath        
    }
    catch{
        throw "AWS PowerShell not found! Please make sure to install them from https://aws.amazon.com/powershell/" 
    }
}

function Get-EnvironmentVariables () {
    $resultEV = @{}
    $environmentVariableConst = 'env.'

    $envVariables = $OctopusParameters.Keys | ? {$_ -like $environmentVariableConst + '*' }
    
    foreach($item in $envVariables)
    {
        $key = $item.Replace($environmentVariableConst, '')
        $value = $OctopusParameters[$item]

        $resultEV.Add($key, $value)
    }
    
    return $resultEV
}

# Get the parameters.
$functionName = $OctopusParameters['FunctionName']
$functionZip = $OctopusParameters['FunctionZip']
$handler = $OctopusParameters['Handler']
$runtime = $OctopusParameters['Runtime']
$role = $OctopusParameters['Role']
$description = $OctopusParameters['Description']
$memorySize = $OctopusParameters['MemorySize']
$timeout = $OctopusParameters['Timeout']
$awsRegion = $OctopusParameters['AWSRegion']
$awsSecretAccessKey = $OctopusParameters['AWSSecretAccessKey']
$awsAccessKey = $OctopusParameters['AWSAccessKey']
$AWSCL_VpcConfig_SubnetId = $OctopusParameters['AWSCL_VpcConfig_SubnetId']
$vpcSubnetIds = if($AWSCL_VpcConfig_SubnetId) { $AWSCL_VpcConfig_SubnetId.Split(',') }
$AWSCL_VpcConfig_SecurityGroupId = $OctopusParameters['AWSCL_VpcConfig_SecurityGroupId']
if($AWSCL_VpcConfig_SecurityGroupId) { $vpcSecurityGroupIds = $AWSCL_VpcConfig_SecurityGroupId.Split(',') }

# Check the parameters.
if (-NOT $awsSecretAccessKey) { throw "You must enter a value for 'AWS Access Key'." }
if (-NOT $awsAccessKey) { throw "You must enter a value for 'AWS Secret Access Key'." }
if (-NOT $awsRegion) { throw "You must enter a value for 'AWS Region'." }
if (-NOT $functionName) { throw "You must enter a value for 'Function Name'." }
if (-NOT $functionZip) { throw "You must enter a value for 'Function Zip'." }
if (-NOT $handler) { throw "You must enter a value for 'Handler'." }
if (-NOT $runtime) { throw "You must enter a value for 'Runtime'." }
if (-NOT $role) { throw "You must enter a value for 'Role'." }
if (-NOT $memorySize) { throw "You must enter a value for 'Memory Size'." }
if (-NOT $timeout) { throw "You must enter a value for 'Timeout'." }

Write-Output "--------------------------------------------------"
Write-Output "AWS Region: $awsRegion"
Write-Output "AWS Lambda Function Name: $functionName"
Write-Output "AWS Lambda Handler: $handler"
Write-Output "AWS Lambda Runtime: $runtime"
Write-Output "AWS Lambda Memory Size: $memorySize"
Write-Output "AWS Lambda Timeout: $timeout"
Write-Output "AWS Lambda Role: $role"
Write-Output "--------------------------------------------------"

# Set up the credentials and the dependencies.
Set-DefaultAWSRegion -Region $awsRegion
$credential = New-AWSCredentials -AccessKey $awsAccessKey -SecretKey $awsSecretAccessKey

$awsEnvironmentVariables = Get-EnvironmentVariables

# Check if the function exists, with a try catch
try {
    Get-LMFunction -Credential $credential -FunctionName $functionName -Region $awsRegion
    
    Write-Host 'Updating Lambda function code.'

    # Update the function.
    Update-LMFunctionCode -Credential $credential -Region $awsRegion -FunctionName $functionName -ZipFilename  $functionZip
    
    Write-Host 'Updating Lambda function configuration.'

    Update-LMFunctionConfiguration -Credential $credential -Region $awsRegion -FunctionName $functionName -Description $description -Handler $handler -MemorySize $memorySize -Role $role -Runtime $runtime -Timeout $timeout -Environment_Variable $awsEnvironmentVariables -VpcConfig_SecurityGroupId $vpcSecurityGroupIds -VpcConfig_SubnetId $vpcSubnetIds
    
    # Feedback
    Write-Output "--------------------------------------------------"
    Write-Output "AWS Lambda Function updated."
    Write-Output "--------------------------------------------------"
}
catch {
    # Create the function.
    Publish-LMFunction -Credential $credential -Region $awsRegion -FunctionName $functionName -FunctionZip $functionZip -Handler $handler -Runtime $runtime -Role $role -Description $description -MemorySize $memorySize -Timeout $timeout -Environment_Variable $awsEnvironmentVariables -VpcConfig_SecurityGroupId $vpcSecurityGroupIds -VpcConfig_SubnetId $vpcSubnetIds

    # Feedback
    Write-Output "--------------------------------------------------"
    Write-Output "AWS Lambda Function created."
    Write-Output "--------------------------------------------------"
}

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": "001609c0-35d0-4faa-95c3-a995faaeaa5e",
  "Name": "AWS - Create Lambda (deprecated)",
  "Description": "Creates a [AWS Lambda Function](#https://aws.amazon.com/lambda/) from the specified zip.\n\nIf the function exists, it will update the function code and update function configuration.\n- Requires the [AWS PowerShell cmdlets](http://aws.amazon.com/powershell/)\n\nTo create environment variables, add variables in project starting with 'env.'.\nFor example, to create environment variable S3BucketName = MyTestFolder, create variable 'env.S3BucketName' = 'MyTestFolder'.  This function has been deprecated in favor of the new AWS Deploy Lambda step template.  That new step requires 2019.10.x to run properly.  This step is left in place for older versions of Octopus Deploy to still use.",
  "Version": 7,
  "ExportedAt": "2018-04-16T10:25:57.788Z",
  "ActionType": "Octopus.Script",
  "Author": "harrisonmeister",
  "Parameters": [
    {
      "Id": "d0fe2641-f1ea-4760-aac0-da3b0a68d27a",
      "Name": "AWSSecretAccessKey",
      "Label": "AWS Secret Access Key",
      "HelpText": "The [secret access key](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) to use when executing the script",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      },
      "Links": {}
    },
    {
      "Id": "2102fea4-4491-40da-b91c-d0044a131e4c",
      "Name": "AWSAccessKey",
      "Label": "AWS Access Key",
      "HelpText": "The [access key](http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) to use when executing the script",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "cc68295e-5bd7-42a0-a093-21cf99cbedb8",
      "Name": "AWSRegion",
      "Label": "AWS Region",
      "HelpText": "The Amazon Region see [https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) for further info",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "2bc4b496-8267-41ef-a319-d2d028e3d8ae",
      "Name": "FunctionName",
      "Label": "AWS Lambda Function Name",
      "HelpText": "The name of the AWS Lambda Function",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "b1e02e55-b7fb-434e-aa3b-10e2f136e16a",
      "Name": "FunctionZip",
      "Label": "AWS Lambda Function Zip Location",
      "HelpText": "The zip location of the AWS Lambda Function",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "c51f5b24-3b86-4285-b406-5cc90c6b95a4",
      "Name": "Handler",
      "Label": "AWS Lambda Function Handler",
      "HelpText": "The handler signature (ASSEMBLY::TYPE::METHOD) of the AWS Lambda Function",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "0373bf3a-e961-4722-8cf9-e607b42ca344",
      "Name": "Runtime",
      "Label": "AWS Lambda Function Runtime",
      "HelpText": "The runtime of the AWS Lambda Function",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "nodejs|nodejs\nnodejs4.3|nodejs4.3\nnodejs6.10|nodejs6.10\njava8|java8\npython2.7|python2.7\npython3.6|python3.6\ndotnetcore1.0|dotnetcore1.0\ndotnetcore2.0|dotnetcore2.0\nnodejs4.3-edge|nodejs4.3-edge\ngo1.x|go1.x"
      },
      "Links": {}
    },
    {
      "Id": "17791000-4b1c-425e-992a-3909b085a3ad",
      "Name": "Role",
      "Label": "AWS Lambda Function Role",
      "HelpText": "The role of the AWS Lambda Function, in [ARN](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) format",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "eef1166c-1d9c-483f-95e4-5603d6f04e70",
      "Name": "Description",
      "Label": "AWS Lambda Function Description",
      "HelpText": "The description of the AWS Lambda Function",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      },
      "Links": {}
    },
    {
      "Id": "ac367ef3-7aef-45c3-89f2-1e7ef2821cf3",
      "Name": "MemorySize",
      "Label": "AWS Lambda Function Memory Size",
      "HelpText": "The memory size of the AWS Lambda Function. The default value is 128 MB. The value must be a multiple of 64 MB",
      "DefaultValue": "128",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "48d6f0dc-b8de-4903-8411-5bde136c2ccd",
      "Name": "Timeout",
      "Label": "AWS Lambda Function Timeout",
      "HelpText": "The timeout of the AWS Lambda Function",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "5fd40dab-518e-4329-9bff-c61a6e4177fa",
      "Name": "AWSCL_VpcConfig_SubnetId",
      "Label": "AWS Lambda Function VPC Subnet Id",
      "HelpText": "A list of one or more subnet IDs in your VPC.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "4918ab99-d21c-4002-9a04-c5073979ed4b",
      "Name": "AWSCL_VpcConfig_SecurityGroupId",
      "Label": "AWS Lambda Function VPC Security Group Id",
      "HelpText": "A list of one or more security groups IDs in your VPC.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "# Check for the PowerShell cmdlets (from AWS - Create Cloud Formation Stack Octopus Step).\ntry{ \n    Import-Module AWSPowerShell -ErrorAction Stop\n}catch{\n    \n    $modulePath = \"C:\\Program Files (x86)\\AWS Tools\\PowerShell\\AWSPowerShell\\AWSPowerShell.psd1\"\n    Write-Output \"Unable to find the AWS module checking $modulePath\" \n    \n    try{\n        Import-Module $modulePath        \n    }\n    catch{\n        throw \"AWS PowerShell not found! Please make sure to install them from https://aws.amazon.com/powershell/\" \n    }\n}\n\nfunction Get-EnvironmentVariables () {\n    $resultEV = @{}\n    $environmentVariableConst = 'env.'\n\n    $envVariables = $OctopusParameters.Keys | ? {$_ -like $environmentVariableConst + '*' }\n    \n    foreach($item in $envVariables)\n    {\n        $key = $item.Replace($environmentVariableConst, '')\n        $value = $OctopusParameters[$item]\n\n        $resultEV.Add($key, $value)\n    }\n    \n    return $resultEV\n}\n\n# Get the parameters.\n$functionName = $OctopusParameters['FunctionName']\n$functionZip = $OctopusParameters['FunctionZip']\n$handler = $OctopusParameters['Handler']\n$runtime = $OctopusParameters['Runtime']\n$role = $OctopusParameters['Role']\n$description = $OctopusParameters['Description']\n$memorySize = $OctopusParameters['MemorySize']\n$timeout = $OctopusParameters['Timeout']\n$awsRegion = $OctopusParameters['AWSRegion']\n$awsSecretAccessKey = $OctopusParameters['AWSSecretAccessKey']\n$awsAccessKey = $OctopusParameters['AWSAccessKey']\n$AWSCL_VpcConfig_SubnetId = $OctopusParameters['AWSCL_VpcConfig_SubnetId']\n$vpcSubnetIds = if($AWSCL_VpcConfig_SubnetId) { $AWSCL_VpcConfig_SubnetId.Split(',') }\n$AWSCL_VpcConfig_SecurityGroupId = $OctopusParameters['AWSCL_VpcConfig_SecurityGroupId']\nif($AWSCL_VpcConfig_SecurityGroupId) { $vpcSecurityGroupIds = $AWSCL_VpcConfig_SecurityGroupId.Split(',') }\n\n# Check the parameters.\nif (-NOT $awsSecretAccessKey) { throw \"You must enter a value for 'AWS Access Key'.\" }\nif (-NOT $awsAccessKey) { throw \"You must enter a value for 'AWS Secret Access Key'.\" }\nif (-NOT $awsRegion) { throw \"You must enter a value for 'AWS Region'.\" }\nif (-NOT $functionName) { throw \"You must enter a value for 'Function Name'.\" }\nif (-NOT $functionZip) { throw \"You must enter a value for 'Function Zip'.\" }\nif (-NOT $handler) { throw \"You must enter a value for 'Handler'.\" }\nif (-NOT $runtime) { throw \"You must enter a value for 'Runtime'.\" }\nif (-NOT $role) { throw \"You must enter a value for 'Role'.\" }\nif (-NOT $memorySize) { throw \"You must enter a value for 'Memory Size'.\" }\nif (-NOT $timeout) { throw \"You must enter a value for 'Timeout'.\" }\n\nWrite-Output \"--------------------------------------------------\"\nWrite-Output \"AWS Region: $awsRegion\"\nWrite-Output \"AWS Lambda Function Name: $functionName\"\nWrite-Output \"AWS Lambda Handler: $handler\"\nWrite-Output \"AWS Lambda Runtime: $runtime\"\nWrite-Output \"AWS Lambda Memory Size: $memorySize\"\nWrite-Output \"AWS Lambda Timeout: $timeout\"\nWrite-Output \"AWS Lambda Role: $role\"\nWrite-Output \"--------------------------------------------------\"\n\n# Set up the credentials and the dependencies.\nSet-DefaultAWSRegion -Region $awsRegion\n$credential = New-AWSCredentials -AccessKey $awsAccessKey -SecretKey $awsSecretAccessKey\n\n$awsEnvironmentVariables = Get-EnvironmentVariables\n\n# Check if the function exists, with a try catch\ntry {\n    Get-LMFunction -Credential $credential -FunctionName $functionName -Region $awsRegion\n    \n    Write-Host 'Updating Lambda function code.'\n\n    # Update the function.\n    Update-LMFunctionCode -Credential $credential -Region $awsRegion -FunctionName $functionName -ZipFilename  $functionZip\n    \n    Write-Host 'Updating Lambda function configuration.'\n\n    Update-LMFunctionConfiguration -Credential $credential -Region $awsRegion -FunctionName $functionName -Description $description -Handler $handler -MemorySize $memorySize -Role $role -Runtime $runtime -Timeout $timeout -Environment_Variable $awsEnvironmentVariables -VpcConfig_SecurityGroupId $vpcSecurityGroupIds -VpcConfig_SubnetId $vpcSubnetIds\n    \n    # Feedback\n    Write-Output \"--------------------------------------------------\"\n    Write-Output \"AWS Lambda Function updated.\"\n    Write-Output \"--------------------------------------------------\"\n}\ncatch {\n    # Create the function.\n    Publish-LMFunction -Credential $credential -Region $awsRegion -FunctionName $functionName -FunctionZip $functionZip -Handler $handler -Runtime $runtime -Role $role -Description $description -MemorySize $memorySize -Timeout $timeout -Environment_Variable $awsEnvironmentVariables -VpcConfig_SecurityGroupId $vpcSecurityGroupIds -VpcConfig_SubnetId $vpcSubnetIds\n\n    # Feedback\n    Write-Output \"--------------------------------------------------\"\n    Write-Output \"AWS Lambda Function created.\"\n    Write-Output \"--------------------------------------------------\"\n}\n",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptSource": "Inline"
  },
  "Category": "AWS",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/aws-lambda-create.json",
  "Website": "/step-templates/001609c0-35d0-4faa-95c3-a995faaeaa5e",
  "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 Monday, April 16, 2018