AWS - Deploy Lambda Function

Octopus.AwsRunScript exported 2022-09-16 by twerthi belongs to ‘AWS’ category.

Deploys a Zip file to an AWS Lambda function.

This step does not perform variable substitution (it used to). It takes the .zip file from the specified feed and uploads it to AWS as is. The recommended approach to changing a lambda configuration per environment is to use environment variables

This step uses the following AWS CLI commands to deploy the AWS Lambda. You will be required to install the AWS CLI on your server/worker for this to work. The AWS CLI is pre-installed on the dynamic workers in Octopus Cloud as well as the provided docker containers for Execution Containers.

This step template is worker-friendly, you can pass in a package reference rather than having to reference a previous step that downloaded the package. This step requires Octopus Deploy 2019.10.0 or higher.

Output Variables

This step template sets the following output variables:

  • LambdaArn: The ARN of the Lambda Function
  • PublishedVersion: The most recent version published (only set when Publish is set to Yes).

Parameters

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

Function Name

AWS.Lambda.FunctionName =

Required.

The name of the function to create or update. See documentation

Examples:

  • Function name - my-function .
  • Function ARN - arn:aws:lambda:us-west-2:123456789012:function .
  • Partial ARN - 123456789012:function .

The length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.

AWS Account

AWS.Lambda.Account =

Required.

The AWS Account with permissions to create / update AWS Lambdas.

Region

AWS.Lambda.Region =

Required.

The region where the function will live.

Package

AWS.Lambda.Package =

Required.

The package containing the code you wish to deploy to the AWS Lambda function.

Function Role

AWS.Lambda.FunctionRole =

Required.

The Amazon Resource Name (ARN) of the function’s execution role. This role must exist prior to this step is run. See documentation for more detail on creating an execution role.

Runtime

AWS.Lambda.Runtime =

Required.

The runtime of the AWS Lambda. See documentation for more details on what runtimes are supported.

Handler

AWS.Lambda.FunctionHandler =

Required.

The name of the method within your code that Lambda calls to execute your function. The format includes the file name. It can also include namespaces and other qualifiers, depending on the runtime. For more information, see Programming Model

Memory Size

AWS.Lambda.MemorySize = 128

Required.

The amount of memory that your function has access to. Increasing the function’s memory also increases its CPU allocation. The default value is 128 MB. The value must be a multiple of 64 MB.

Description

AWS.Lambda.Description =

Optional.

A description of the function.

VPC Subnet Ids

AWS.Lambda.VPCSubnetIds =

Optional.

Format: SubnetId1,SubnetId2

For network connectivity to AWS resources in a VPC, specify a list of security groups and subnets in the VPC. When you connect a function to a VPC, it can only access resources and the internet through that VPC. For more information, see VPC Settings.

VPC Security Group Ids

AWS.Lambda.VPCSecurityGroupIds =

Optional.

Format: SecurityGroupId1,SecurityGroupId2

For network connectivity to AWS resources in a VPC, specify a list of security groups and subnets in the VPC. When you connect a function to a VPC, it can only access resources and the internet through that VPC. For more information, see VPC Settings.

Environment Variables

AWS.Lambda.EnvironmentVariables =

Optional.

Format: KeyName1=string,KeyName2=string

Environment variables that are accessible from function code during execution.

Environment Variables Encryption Key

AWS.Lambda.EnvironmentVariablesKey =

Optional.

The ARN of the AWS Key Management Service (AWS KMS) key that’s used to encrypt your function’s environment variables. If it’s not provided, AWS Lambda uses a default service key.

Timeout

AWS.Lambda.FunctionTimeout =

Optional.

The amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds.

Tags

AWS.Lambda.Tags =

Optional.

Format: KeyName1=string,KeyName2=string

A list of tags to apply to the function.

File System Config

AWS.Lambda.FileSystemConfig =

Optional.

Format: Arn=string,LocalMountPath=string

Connection settings for an Amazon EFS file system.

Tracing Config

AWS.Lambda.TracingConfig =

Optional.

Format: Mode=string

Set Mode to Active to sample and trace a subset of incoming requests with AWS X-Ray.

Dead Letter Config

AWS.Lambda.DeadLetterConfig =

Optional.

Format: TargetArn=string

A dead letter queue configuration that specifies the queue or topic where Lambda sends asynchronous events when they fail processing. For more information, see Dead Letter Queues.

Publish

AWS.Lambda.Publish = Yes

Required.

Creates a version from the current code and configuration of a function. Use versions to create a snapshot of your function code and configuration that doesn’t change.

Important: Lambda doesn’t publish a version if the function’s configuration and code haven’t changed since the last version. Use UpdateFunctionCode or UpdateFunctionConfiguration to update the function before publishing a version.

Script body

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

$functionName = $OctopusParameters["AWS.Lambda.FunctionName"] 
$functionRole = $OctopusParameters["AWS.Lambda.FunctionRole"]
$functionRunTime = $OctopusParameters["AWS.Lambda.Runtime"]
$functionHandler = $OctopusParameters["AWS.Lambda.FunctionHandler"]
$functionMemorySize = $OctopusParameters["AWS.Lambda.MemorySize"]
$functionDescription = $OctopusParameters["AWS.Lambda.Description"]
$functionVPCSubnetId = $OctopusParameters["AWS.Lambda.VPCSubnetIds"]
$functionVPCSecurityGroupId = $OctopusParameters["AWS.Lambda.VPCSecurityGroupIds"]
$functionEnvironmentVariables = $OctopusParameters["AWS.Lambda.EnvironmentVariables"]
$functionEnvironmentVariablesKey = $OctopusParameters["AWS.Lambda.EnvironmentVariablesKey"]
$functionTimeout = $OctopusParameters["AWS.Lambda.FunctionTimeout"]
$functionTags = $OctopusParameters["AWS.Lambda.Tags"]
$functionFileSystemConfig = $OctopusParameters["AWS.Lambda.FileSystemConfig"]
$functionDeadLetterConfig = $OctopusParameters["AWS.Lambda.DeadLetterConfig"]
$functionTracingConfig = $OctopusParameters["AWS.Lambda.TracingConfig"]
$functionVersionNumber = $OctopusParameters["Octopus.Action.Package[AWS.Lambda.Package].PackageVersion"]
$functionPublishOption = $OctopusParameters["AWS.Lambda.Publish"]

$functionReleaseNumber = $OctopusParameters["Octopus.Release.Number"]
$functionRunbookRun = $OctopusParameters["Octopus.RunbookRun.Id"]
$stepName = $OctopusParameters["Octopus.Step.Name"]

$regionName = $OctopusParameters["AWS.Lambda.Region"]
$newArchiveFileName = $OctopusParameters["Octopus.Action.Package[AWS.Lambda.Package].PackageFilePath"]

if ([string]::IsNullOrWhiteSpace($functionName))
{
	Write-Error "The parameter Function Name is required."
    Exit 1
}

if ([string]::IsNullOrWhiteSpace($functionRole))
{
	Write-Error "The parameter Role is required."
    Exit 1
}

if ([string]::IsNullOrWhiteSpace($functionRunTime))
{
	Write-Error "The parameter Run Time is required."
    Exit 1
}

if ([string]::IsNullOrWhiteSpace($functionHandler))
{
	Write-Error "The parameter Handler is required."
    Exit 1
}

if ([string]::IsNullOrWhiteSpace($functionPublishOption))
{
	Write-Error "The parameter Publish is required."
    Exit 1
}

if ([string]::IsNullOrWhiteSpace($functionReleaseNumber) -eq $false)
{
    $deployVersionTag = "Octopus-Release=$functionReleaseNumber"
}
else
{
	$deployVersionTag = "Octopus-Runbook-Run=$functionRunbookRun"
}

Write-Host "Function Name: $functionName"
Write-Host "Function Role: $functionRole"
Write-Host "Function Runtime: $functionRunTime"
Write-Host "Function Handler: $functionHandler"
Write-Host "Function Memory Size: $functionMemorySize"
Write-Host "Function Description: $functionDescription"
Write-Host "Function Subnet Ids: $functionVPCSubnetId"
Write-Host "Function Security Group Ids: $functionVPCSecurityGroupId"
Write-Host "Function Environment Variables: $functionEnvironmentVariables"
Write-Host "Function Environment Variables Key: $functionEnvironmentVariablesKey"
Write-Host "Function Timeout: $functionTimeout"
Write-Host "Function Tags: $functionTags"
Write-Host "Function File System Config: $functionFileSystemConfig"
Write-Host "Function Dead Letter Config: $functionDeadLetterConfig"
Write-Host "Function Tracing Config: $functionTracingConfig"
Write-Host "Function file path: fileb://$newArchiveFileName"
Write-Host "Function Publish: $functionPublishOption"

Write-Host "Attempting to find the function $functionName in the region $regionName"
$hasExistingFunction = $true

try
{
    $existingFunction = aws lambda get-function --function-name "$functionName" 2> $null
    
    Write-Host "The exit code from the lookup was $LASTEXITCODE"
    if ($LASTEXITCODE -eq 255 -or $LASTEXITCODE -eq 254)
    {
    	$hasExistingFunction = $false
    }   
    
    $existingFunction = $existingFunction | ConvertFrom-Json
}
catch
{
	Write-Host "The function was not found"
	$hasExistingFunction = $false
}

Write-Host "Existing functions: $hasExistingFunction"
Write-Host $existingFunction

$aliasInformation = $null
if ($hasExistingFunction -eq $false)
{
	Write-Highlight "Creating $functionName in $regionName"    
	$functionInformation = aws lambda create-function --function-name "$functionName" --zip-file fileb://$newArchiveFileName --handler $functionHandler --runtime $functionRuntime --role $functionRole --memory-size $functionMemorySize
}
else
{
	Write-Highlight "Updating the $functionName code"
    $updatedConfig = aws lambda update-function-code --function-name "$functionName" --zip-file fileb://$newArchiveFileName
    
    Write-Highlight "Waiting for update to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
    
    Write-Highlight "Updating the $functionName base configuration"    
    $functionInformation = aws lambda update-function-configuration --function-name "$functionName" --role $functionRole --handler $functionHandler --runtime $functionRuntime --memory-size $functionMemorySize
    
    Write-Highlight "Waiting for base configuration update to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
}

$functionInformation = $functionInformation | ConvertFrom-JSON
$functionArn = $functionInformation.FunctionArn

Write-Host "Function ARN: $functionArn"

if ([string]::IsNullOrWhiteSpace($functionEnvironmentVariables) -eq $false)
{
	Write-Highlight "Environment variables specified, updating environment variables configuration for $functionName"
	$environmentVariables = "Variables={$functionEnvironmentVariables}"
    
    if ([string]::IsNullOrWhiteSpace($functionEnvironmentVariablesKey) -eq $true)
    {
    	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --environment "$environmentVariables"
    }
    else
    {
    	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --environment "$environmentVariables" --kms-key-arn "$functionEnvironmentVariablesKey"
    }
    
    Write-Highlight "Waiting for environment variable update to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
}

if ([string]::IsNullOrWhiteSpace($functionTimeout) -eq $false)
{
	Write-Highlight "Timeout specified, updating timeout configuration for $functionName"
	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --timeout "$functionTimeout"
    
    Write-Highlight "Waiting for timeout upate to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
}

if ([string]::IsNullOrWhiteSpace($functionTags) -eq $false)
{
	Write-Highlight "Tags specified, updating tags configuration for $functionName"
	$updatedConfig = aws lambda tag-resource --resource "$functionArn" --tags "$functionTags"
}

if ([string]::IsNullOrWhiteSpace($deployVersionTag) -eq $false)
{
	Write-Highlight "Deploy version tag found with value of $deployVersionTag, updating tags configuration for $functionName"
    aws lambda untag-resource --resource "$functionArn" --tag-keys "Octopus-Release" "Octopus-Runbook-Run"
	$updatedConfig = aws lambda tag-resource --resource "$functionArn" --tags "$deployVersionTag"
}

if ([string]::IsNullOrWhiteSpace($functionVPCSubnetId) -eq $false -and [string]::IsNullOrWhiteSpace($functionVPCSecurityGroupId) -eq $false)
{
	Write-Highlight "VPC subnets and security group specified, updating vpc configuration for $functionName"
	$vpcConfig = "SubnetIds=$functionVPCSubnetId,SecurityGroupIds=$functionVPCSecurityGroupId"
	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --vpc-config "$vpcConfig"
    
    Write-Highlight "Waiting for vpc configuration to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
}

if ([string]::IsNullOrWhiteSpace($functionDescription) -eq $false)
{
	Write-Highlight "Description specified, updating description configuration for $functionName"
	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --description "$functionDescription"
    
    Write-Highlight "Waiting for description configuration ..."
    aws lambda wait function-updated --function-name "$functionName"
}

if ([string]::IsNullOrWhiteSpace($functionFileSystemConfig) -eq $false)
{
	Write-Highlight "File System Config specified, updating file system configuration for $functionName"
	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --file-system-configs "$functionFileSystemConfig"	
    
    Write-Highlight "Wating for file system configuration update to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
}

if ([string]::IsNullOrWhiteSpace($functionDeadLetterConfig) -eq $false)
{
	Write-Highlight "Dead Letter specified, updating dead letter configuration for $functionName"
	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --dead-letter-config "$functionDeadLetterConfig"	
    
    Write-Highlight "Waitng for Dead Letter configuration update to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
}

if ([string]::IsNullOrWhiteSpace($functionTracingConfig) -eq $false)
{
	Write-Highlight "Tracing config specified, updating tracing configuration for $functionName"
	$updatedConfig = aws lambda update-function-configuration --function-name "$functionArn" --tracing-config "$functionTracingConfig"	
    
    Write-Highlight "Waiting for tracing configuration to complete ..."
    aws lambda wait function-updated --function-name "$functionName"
}

Write-Host $updatedConfig | ConvertFrom-JSON

if ($functionPublishOption -eq "Yes")
{
	Write-Highlight "Publishing the function with the description $functionVersionNumber to create a snapshot of the current code and configuration of this function in AWS."
	$publishedVersion = aws lambda publish-version --function-name "$functionArn" --description "$functionVersionNumber"
    
    $publishedVersion = $publishedVersion | ConvertFrom-JSON
    
    Write-Highlight "Setting the output variable 'Octopus.Action[$($stepName)].Output.PublishedVersion' to $($publishedVersion.Version)"
    Set-OctopusVariable -name "PublishedVersion" -value "$($publishedVersion.Version)"    
}

Write-Highlight "Setting the output variable 'Octopus.Action[$($stepName)].Output.LambdaArn' to $functionArn"
Set-OctopusVariable -name "LambdaArn" -value "$functionArn"

Write-Highlight "AWS Lambda $functionName successfully deployed."

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": "9b5ee984-bdd2-49f0-a78a-07e21e60da8a",
  "Name": "AWS - Deploy Lambda Function",
  "Description": "Deploys a Zip file to an AWS Lambda function.  \n\nThis step does **not** perform variable substitution (it used to).  It takes the .zip file from the specified feed and uploads it to AWS as is.  The recommended approach to changing a lambda configuration per environment is to use [environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html)  \n\nThis step uses the following AWS CLI commands to deploy the AWS Lambda.  You will be required to install the AWS CLI on your server/worker for this to work.  The AWS CLI is pre-installed on the [dynamic workers](https://octopus.com/docs/infrastructure/workers/dynamic-worker-pools) in Octopus Cloud as well as the provided docker containers for [Execution Containers](https://octopus.com/docs/deployment-process/execution-containers-for-workers).\n\n- [create-function](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/create-function.html)\n- [get-function](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/get-function.html)\n- [publish-version](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/publish-version.html)\n- [tag-resource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/tag-resource.html)\n- [untag-resource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/untag-resource.html)\n- [update-function-code](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-code.html)\n- [update-function-configuration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-configuration.html)\n\nThis step template is worker-friendly, you can pass in a package reference rather than having to reference a previous step that downloaded the package. This step requires **Octopus Deploy 2019.10.0** or higher.\n\n## Output Variables\n\nThis step template sets the following output variables:\n\n- `LambdaArn`: The ARN of the Lambda Function\n- `PublishedVersion`: The most recent version published (only set when Publish is set to `Yes`).",
  "Version": 8,
  "ExportedAt": "2022-09-16T00:50:35.270Z",
  "ActionType": "Octopus.AwsRunScript",
  "Author": "twerthi",
  "Packages": [
    {
      "Id": "8dbae499-5aa8-438e-a2fe-ae29fb8f0a39",
      "Name": "AWS.Lambda.Package",
      "PackageId": null,
      "FeedId": null,
      "AcquisitionLocation": "Server",
      "Properties": {
        "Extract": "False",
        "SelectionMode": "deferred",
        "PackageParameterName": "AWS.Lambda.Package"
      }
    }
  ],
  "Parameters": [
    {
      "Id": "bf72bc3e-3ce6-4b63-b23f-1171b5cc72dd",
      "Name": "AWS.Lambda.FunctionName",
      "Label": "Function Name",
      "HelpText": "Required.\n\nThe name of the function to create or update.  See [documentation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/create-function.html#options)\n\nExamples:\n- Function name - my-function .\n- Function ARN - arn:aws:lambda:us-west-2:123456789012:function:my-function .\n- Partial ARN - 123456789012:function:my-function .\n\nThe length constraint applies only to the full ARN. If you specify only the function name, it is limited to 64 characters in length.\n",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "13dcec09-00f8-4af0-80e4-23bcb47eaf17",
      "Name": "AWS.Lambda.Account",
      "Label": "AWS Account",
      "HelpText": "Required.\n\nThe AWS Account with permissions to create / update AWS Lambdas.\n",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "AmazonWebServicesAccount"
      }
    },
    {
      "Id": "8fd7ff24-7557-4f96-a809-ce611c473b13",
      "Name": "AWS.Lambda.Region",
      "Label": "Region",
      "HelpText": "Required.\n\nThe region where the function will live.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "us-east-2|US East (Ohio)\nus-east-1|US East (N. Virginia)\nus-west-1|US West (N. California)\nus-west-2|US West (Oregon)\naf-south-1|Africa (Cape Town)\nap-east-1|Asia Pacific (Hong Kong)\nap-south-1|Asia Pacific (Mumbai)\nap-northeast-3|Asia Pacific (Osaka-Local)\nap-northeast-2|Asia Pacific (Seoul)\nap-southeast-1|Asia Pacific (Singapore)\nap-southeast-2|Asia Pacific (Sydney)\nap-northeast-1|Asia Pacific (Tokyo)\nca-central-1|Canada (Central)\neu-central-1|Europe (Frankfurt)\neu-west-1|Europe (Ireland)\neu-west-2|Europe (London)\neu-south-1|Europe (Milan)\neu-west-3|Europe (Paris)\neu-north-1|Europe (Stockholm)\nme-south-1|Middle East (Bahrain)\nsa-east-1|South America (São Paulo)"
      }
    },
    {
      "Id": "11928ce7-e1b8-451c-9a9b-481acac60611",
      "Name": "AWS.Lambda.Package",
      "Label": "Package",
      "HelpText": "Required.\n\nThe package containing the code you wish to deploy to the AWS Lambda function.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Package"
      }
    },
    {
      "Id": "d45499b4-5f4a-4bae-a4b9-336e97a75cdc",
      "Name": "AWS.Lambda.FunctionRole",
      "Label": "Function Role",
      "HelpText": "Required.\n\nThe Amazon Resource Name (ARN) of the function’s execution role.  This role must exist prior to this step is run.  See [documentation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html) for more detail on creating an execution role.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "926b93c6-a47a-4899-9865-e7329b93b4b8",
      "Name": "AWS.Lambda.Runtime",
      "Label": "Runtime",
      "HelpText": "Required.\n\nThe runtime of the AWS Lambda.  See [documentation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/create-function.html#options) for more details on what runtimes are supported.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "nodejs|nodejs\nnodejs4.3|nodejs4.3\nnodejs4.3-edge|nodejs4.3-edge\nnodejs6.10|nodejs6.10\nnodejs8.10|nodejs8.10\nnodejs10.x|nodejs10.x\nnodejs12.x|nodejs12.x\nnodejs14.x|nodejs14.x\njava8|java8\njava8.al2|java8.al2\njava11|java11\npython2.7|python2.7\npython3.6|python3.6\npython3.7|python3.7\npython3.8|python3.8\npython3.9|python3.9\ndotnetcore1.0|dotnetcore1.0\ndotnetcore2.0|dotnetcore2.0\ndotnetcore2.1|dotnetcore2.1\ndotnetcore3.1|dotnetcore3.1\ndotnet6|dotnet6\nnodejs4.3-edge|nodejs4.3-edge\ngo1.x|go1.x\nruby2.5|ruby2.5\nruby2.7|ruby2.7\nprovided|provided\nprovided.al2|provided.al2"
      }
    },
    {
      "Id": "1b8bfb82-3736-4d9a-8b05-a39319eb5735",
      "Name": "AWS.Lambda.FunctionHandler",
      "Label": "Handler",
      "HelpText": "Required.\n\nThe name of the method within your code that Lambda calls to execute your function. The format includes the file name. It can also include namespaces and other qualifiers, depending on the runtime. For more information, see [Programming Model](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-features.html)",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "68428e8e-abc3-4f29-a5bb-fe635281d073",
      "Name": "AWS.Lambda.MemorySize",
      "Label": "Memory Size",
      "HelpText": "Required.\n\nThe amount of memory that your function has access to. Increasing the function’s memory also increases its CPU allocation. The default value is 128 MB. The value must be a multiple of 64 MB.",
      "DefaultValue": "128",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "948280bb-50af-495b-9d1d-2f7567a0b0cc",
      "Name": "AWS.Lambda.Description",
      "Label": "Description",
      "HelpText": "Optional.\n\nA description of the function.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "ed2ab9bb-d8a3-4ab4-a576-36b6c0a8f75d",
      "Name": "AWS.Lambda.VPCSubnetIds",
      "Label": "VPC Subnet Ids",
      "HelpText": "Optional.\n\nFormat: `SubnetId1,SubnetId2`\n\nFor network connectivity to AWS resources in a VPC, specify a list of security groups and subnets in the VPC. When you connect a function to a VPC, it can only access resources and the internet through that VPC. For more information, see [VPC Settings](https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html).",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "8c2793a7-1a88-40a2-be28-3a38c7b40658",
      "Name": "AWS.Lambda.VPCSecurityGroupIds",
      "Label": "VPC Security Group Ids",
      "HelpText": "Optional.\n\nFormat: `SecurityGroupId1,SecurityGroupId2`\n\nFor network connectivity to AWS resources in a VPC, specify a list of security groups and subnets in the VPC. When you connect a function to a VPC, it can only access resources and the internet through that VPC. For more information, see [VPC Settings](https://docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html).",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "ba3edded-1e19-47c4-990a-ebdf4eb0bcca",
      "Name": "AWS.Lambda.EnvironmentVariables",
      "Label": "Environment Variables",
      "HelpText": "Optional.\n\nFormat: `KeyName1=string,KeyName2=string`\n\nEnvironment variables that are accessible from function code during execution.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "58d76440-e4f5-46fb-a095-84aedd904a18",
      "Name": "AWS.Lambda.EnvironmentVariablesKey",
      "Label": "Environment Variables Encryption Key",
      "HelpText": "Optional.\n\nThe ARN of the AWS Key Management Service (AWS KMS) key that’s used to encrypt your function’s environment variables. If it’s not provided, AWS Lambda uses a default service key.\n",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "5b9b3111-5349-49e6-ab0d-f386a53bdd7c",
      "Name": "AWS.Lambda.FunctionTimeout",
      "Label": "Timeout",
      "HelpText": "Optional.\n\nThe amount of time that Lambda allows a function to run before stopping it. The default is 3 seconds. The maximum allowed value is 900 seconds.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "567f5eeb-e174-4c8f-8b17-36bd9457ea29",
      "Name": "AWS.Lambda.Tags",
      "Label": "Tags",
      "HelpText": "Optional.\n\nFormat: `KeyName1=string,KeyName2=string`\n\nA list of tags to apply to the function.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "297f4f8e-3837-43a3-b844-a0e0d02e9d5b",
      "Name": "AWS.Lambda.FileSystemConfig",
      "Label": "File System Config",
      "HelpText": "Optional.\n\nFormat: `Arn=string,LocalMountPath=string`\n\nConnection settings for an Amazon EFS file system.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "c720a63a-7b77-4a13-b6ed-6d44126e9372",
      "Name": "AWS.Lambda.TracingConfig",
      "Label": "Tracing Config",
      "HelpText": "Optional.\n\nFormat: `Mode=string`\n\nSet Mode to Active to sample and trace a subset of incoming requests with AWS X-Ray.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "92fd8a1f-e681-4e1c-b382-3df1de12194e",
      "Name": "AWS.Lambda.DeadLetterConfig",
      "Label": "Dead Letter Config",
      "HelpText": "Optional.\n\nFormat: `TargetArn=string`\n\nA dead letter queue configuration that specifies the queue or topic where Lambda sends asynchronous events when they fail processing. For more information, see [Dead Letter Queues](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#dlq).\n",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "67f8da1a-08f1-4cde-a60f-238d1fb08c98",
      "Name": "AWS.Lambda.Publish",
      "Label": "Publish",
      "HelpText": "Required.\n\nCreates a [version](https://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html) from the current code and configuration of a function. Use versions to create a snapshot of your function code and configuration that doesn’t change.\n\n**Important**: Lambda doesn’t publish a version if the function’s configuration and code haven’t changed since the last version. Use UpdateFunctionCode or UpdateFunctionConfiguration to update the function before publishing a version.",
      "DefaultValue": "Yes",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "Yes|Yes\nNo|No"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Aws.AssumeRole": "False",
    "Octopus.Action.AwsAccount.UseInstanceRole": "False",
    "Octopus.Action.AwsAccount.Variable": "#{AWS.Lambda.Account}",
    "Octopus.Action.Aws.Region": "#{AWS.Lambda.Region}",
    "Octopus.Action.Script.ScriptBody": "$functionName = $OctopusParameters[\"AWS.Lambda.FunctionName\"] \n$functionRole = $OctopusParameters[\"AWS.Lambda.FunctionRole\"]\n$functionRunTime = $OctopusParameters[\"AWS.Lambda.Runtime\"]\n$functionHandler = $OctopusParameters[\"AWS.Lambda.FunctionHandler\"]\n$functionMemorySize = $OctopusParameters[\"AWS.Lambda.MemorySize\"]\n$functionDescription = $OctopusParameters[\"AWS.Lambda.Description\"]\n$functionVPCSubnetId = $OctopusParameters[\"AWS.Lambda.VPCSubnetIds\"]\n$functionVPCSecurityGroupId = $OctopusParameters[\"AWS.Lambda.VPCSecurityGroupIds\"]\n$functionEnvironmentVariables = $OctopusParameters[\"AWS.Lambda.EnvironmentVariables\"]\n$functionEnvironmentVariablesKey = $OctopusParameters[\"AWS.Lambda.EnvironmentVariablesKey\"]\n$functionTimeout = $OctopusParameters[\"AWS.Lambda.FunctionTimeout\"]\n$functionTags = $OctopusParameters[\"AWS.Lambda.Tags\"]\n$functionFileSystemConfig = $OctopusParameters[\"AWS.Lambda.FileSystemConfig\"]\n$functionDeadLetterConfig = $OctopusParameters[\"AWS.Lambda.DeadLetterConfig\"]\n$functionTracingConfig = $OctopusParameters[\"AWS.Lambda.TracingConfig\"]\n$functionVersionNumber = $OctopusParameters[\"Octopus.Action.Package[AWS.Lambda.Package].PackageVersion\"]\n$functionPublishOption = $OctopusParameters[\"AWS.Lambda.Publish\"]\n\n$functionReleaseNumber = $OctopusParameters[\"Octopus.Release.Number\"]\n$functionRunbookRun = $OctopusParameters[\"Octopus.RunbookRun.Id\"]\n$stepName = $OctopusParameters[\"Octopus.Step.Name\"]\n\n$regionName = $OctopusParameters[\"AWS.Lambda.Region\"]\n$newArchiveFileName = $OctopusParameters[\"Octopus.Action.Package[AWS.Lambda.Package].PackageFilePath\"]\n\nif ([string]::IsNullOrWhiteSpace($functionName))\n{\n\tWrite-Error \"The parameter Function Name is required.\"\n    Exit 1\n}\n\nif ([string]::IsNullOrWhiteSpace($functionRole))\n{\n\tWrite-Error \"The parameter Role is required.\"\n    Exit 1\n}\n\nif ([string]::IsNullOrWhiteSpace($functionRunTime))\n{\n\tWrite-Error \"The parameter Run Time is required.\"\n    Exit 1\n}\n\nif ([string]::IsNullOrWhiteSpace($functionHandler))\n{\n\tWrite-Error \"The parameter Handler is required.\"\n    Exit 1\n}\n\nif ([string]::IsNullOrWhiteSpace($functionPublishOption))\n{\n\tWrite-Error \"The parameter Publish is required.\"\n    Exit 1\n}\n\nif ([string]::IsNullOrWhiteSpace($functionReleaseNumber) -eq $false)\n{\n    $deployVersionTag = \"Octopus-Release=$functionReleaseNumber\"\n}\nelse\n{\n\t$deployVersionTag = \"Octopus-Runbook-Run=$functionRunbookRun\"\n}\n\nWrite-Host \"Function Name: $functionName\"\nWrite-Host \"Function Role: $functionRole\"\nWrite-Host \"Function Runtime: $functionRunTime\"\nWrite-Host \"Function Handler: $functionHandler\"\nWrite-Host \"Function Memory Size: $functionMemorySize\"\nWrite-Host \"Function Description: $functionDescription\"\nWrite-Host \"Function Subnet Ids: $functionVPCSubnetId\"\nWrite-Host \"Function Security Group Ids: $functionVPCSecurityGroupId\"\nWrite-Host \"Function Environment Variables: $functionEnvironmentVariables\"\nWrite-Host \"Function Environment Variables Key: $functionEnvironmentVariablesKey\"\nWrite-Host \"Function Timeout: $functionTimeout\"\nWrite-Host \"Function Tags: $functionTags\"\nWrite-Host \"Function File System Config: $functionFileSystemConfig\"\nWrite-Host \"Function Dead Letter Config: $functionDeadLetterConfig\"\nWrite-Host \"Function Tracing Config: $functionTracingConfig\"\nWrite-Host \"Function file path: fileb://$newArchiveFileName\"\nWrite-Host \"Function Publish: $functionPublishOption\"\n\nWrite-Host \"Attempting to find the function $functionName in the region $regionName\"\n$hasExistingFunction = $true\n\ntry\n{\n    $existingFunction = aws lambda get-function --function-name \"$functionName\" 2> $null\n    \n    Write-Host \"The exit code from the lookup was $LASTEXITCODE\"\n    if ($LASTEXITCODE -eq 255 -or $LASTEXITCODE -eq 254)\n    {\n    \t$hasExistingFunction = $false\n    }   \n    \n    $existingFunction = $existingFunction | ConvertFrom-Json\n}\ncatch\n{\n\tWrite-Host \"The function was not found\"\n\t$hasExistingFunction = $false\n}\n\nWrite-Host \"Existing functions: $hasExistingFunction\"\nWrite-Host $existingFunction\n\n$aliasInformation = $null\nif ($hasExistingFunction -eq $false)\n{\n\tWrite-Highlight \"Creating $functionName in $regionName\"    \n\t$functionInformation = aws lambda create-function --function-name \"$functionName\" --zip-file fileb://$newArchiveFileName --handler $functionHandler --runtime $functionRuntime --role $functionRole --memory-size $functionMemorySize\n}\nelse\n{\n\tWrite-Highlight \"Updating the $functionName code\"\n    $updatedConfig = aws lambda update-function-code --function-name \"$functionName\" --zip-file fileb://$newArchiveFileName\n    \n    Write-Highlight \"Waiting for update to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n    \n    Write-Highlight \"Updating the $functionName base configuration\"    \n    $functionInformation = aws lambda update-function-configuration --function-name \"$functionName\" --role $functionRole --handler $functionHandler --runtime $functionRuntime --memory-size $functionMemorySize\n    \n    Write-Highlight \"Waiting for base configuration update to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\n$functionInformation = $functionInformation | ConvertFrom-JSON\n$functionArn = $functionInformation.FunctionArn\n\nWrite-Host \"Function ARN: $functionArn\"\n\nif ([string]::IsNullOrWhiteSpace($functionEnvironmentVariables) -eq $false)\n{\n\tWrite-Highlight \"Environment variables specified, updating environment variables configuration for $functionName\"\n\t$environmentVariables = \"Variables={$functionEnvironmentVariables}\"\n    \n    if ([string]::IsNullOrWhiteSpace($functionEnvironmentVariablesKey) -eq $true)\n    {\n    \t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --environment \"$environmentVariables\"\n    }\n    else\n    {\n    \t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --environment \"$environmentVariables\" --kms-key-arn \"$functionEnvironmentVariablesKey\"\n    }\n    \n    Write-Highlight \"Waiting for environment variable update to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\nif ([string]::IsNullOrWhiteSpace($functionTimeout) -eq $false)\n{\n\tWrite-Highlight \"Timeout specified, updating timeout configuration for $functionName\"\n\t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --timeout \"$functionTimeout\"\n    \n    Write-Highlight \"Waiting for timeout upate to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\nif ([string]::IsNullOrWhiteSpace($functionTags) -eq $false)\n{\n\tWrite-Highlight \"Tags specified, updating tags configuration for $functionName\"\n\t$updatedConfig = aws lambda tag-resource --resource \"$functionArn\" --tags \"$functionTags\"\n}\n\nif ([string]::IsNullOrWhiteSpace($deployVersionTag) -eq $false)\n{\n\tWrite-Highlight \"Deploy version tag found with value of $deployVersionTag, updating tags configuration for $functionName\"\n    aws lambda untag-resource --resource \"$functionArn\" --tag-keys \"Octopus-Release\" \"Octopus-Runbook-Run\"\n\t$updatedConfig = aws lambda tag-resource --resource \"$functionArn\" --tags \"$deployVersionTag\"\n}\n\nif ([string]::IsNullOrWhiteSpace($functionVPCSubnetId) -eq $false -and [string]::IsNullOrWhiteSpace($functionVPCSecurityGroupId) -eq $false)\n{\n\tWrite-Highlight \"VPC subnets and security group specified, updating vpc configuration for $functionName\"\n\t$vpcConfig = \"SubnetIds=$functionVPCSubnetId,SecurityGroupIds=$functionVPCSecurityGroupId\"\n\t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --vpc-config \"$vpcConfig\"\n    \n    Write-Highlight \"Waiting for vpc configuration to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\nif ([string]::IsNullOrWhiteSpace($functionDescription) -eq $false)\n{\n\tWrite-Highlight \"Description specified, updating description configuration for $functionName\"\n\t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --description \"$functionDescription\"\n    \n    Write-Highlight \"Waiting for description configuration ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\nif ([string]::IsNullOrWhiteSpace($functionFileSystemConfig) -eq $false)\n{\n\tWrite-Highlight \"File System Config specified, updating file system configuration for $functionName\"\n\t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --file-system-configs \"$functionFileSystemConfig\"\t\n    \n    Write-Highlight \"Wating for file system configuration update to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\nif ([string]::IsNullOrWhiteSpace($functionDeadLetterConfig) -eq $false)\n{\n\tWrite-Highlight \"Dead Letter specified, updating dead letter configuration for $functionName\"\n\t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --dead-letter-config \"$functionDeadLetterConfig\"\t\n    \n    Write-Highlight \"Waitng for Dead Letter configuration update to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\nif ([string]::IsNullOrWhiteSpace($functionTracingConfig) -eq $false)\n{\n\tWrite-Highlight \"Tracing config specified, updating tracing configuration for $functionName\"\n\t$updatedConfig = aws lambda update-function-configuration --function-name \"$functionArn\" --tracing-config \"$functionTracingConfig\"\t\n    \n    Write-Highlight \"Waiting for tracing configuration to complete ...\"\n    aws lambda wait function-updated --function-name \"$functionName\"\n}\n\nWrite-Host $updatedConfig | ConvertFrom-JSON\n\nif ($functionPublishOption -eq \"Yes\")\n{\n\tWrite-Highlight \"Publishing the function with the description $functionVersionNumber to create a snapshot of the current code and configuration of this function in AWS.\"\n\t$publishedVersion = aws lambda publish-version --function-name \"$functionArn\" --description \"$functionVersionNumber\"\n    \n    $publishedVersion = $publishedVersion | ConvertFrom-JSON\n    \n    Write-Highlight \"Setting the output variable 'Octopus.Action[$($stepName)].Output.PublishedVersion' to $($publishedVersion.Version)\"\n    Set-OctopusVariable -name \"PublishedVersion\" -value \"$($publishedVersion.Version)\"    \n}\n\nWrite-Highlight \"Setting the output variable 'Octopus.Action[$($stepName)].Output.LambdaArn' to $functionArn\"\nSet-OctopusVariable -name \"LambdaArn\" -value \"$functionArn\"\n\nWrite-Highlight \"AWS Lambda $functionName successfully deployed.\"",
    "Octopus.Action.EnabledFeatures": ""
  },
  "Category": "AWS",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/aws-deploy-lambda.json",
  "Website": "/step-templates/9b5ee984-bdd2-49f0-a78a-07e21e60da8a",
  "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 Friday, September 16, 2022