My thoughts on tech.
10 January 2017
AWS Lambda is one of the AWS Compute Services, alongside with Amazon EC2 or Amazon EC2 Container Service. In a nutshell, AWS Lambda is the serverless offer from AWS, allowing ”you run code without provisioning or managing servers”.
In the DevOps spirit, and using Octopus as the Continuous Deployment tool, I couldn’t find a step template to create an AWS Lambda function. If it doesn’t exist, create it and give it away!
AWS Lambda supports a broad range of technologies, such as Java, Python or NodeJS. The new kid on the block was .NET Core, announced on 1st of December 2016. It was a good announcement for Microsoft tech shops, having another tool in the toolbelt.
The tools used for this demo were:
Using one of the Visual Studio AWS Lambda templates for the demo, the project was created and committed here. In a nutshell, the AWS Lambda function receives an Amazon S3 event and returns the S3 object Content Type. Simple and straightforward.
You can use your preferred CI server. In your CI server will need to:
Publish the AWS Lambda .NET project
dotnet publish AWSLambdaDemo -c Release
Create the NuGet package for Octopus
Octo.exe pack --id AWSLambdaDemo --version 1.0.0.0
Upload the AWS Lambda NuGet package to Octopus Server
NuGet.exe push AWSLambdaDemo.1.0.0.0.nupkg -ApiKey myApiKey -Source https://myOctopusServer
These instructions are generic, and depending on your CI server technology can be done in different ways. You can take them as generic steps, and adapt to your needs.
The step template is simple and straightforward. The Powershell script:
The step template has a prerequisite, it depends on the AWS Tools for Windows Powershell. You need to download and install it on the machines where the step will run.
To create the AWS Lambda function, we need to use a pivot machine. At the moment is not possible to publish it directly to AWS.
We will use the Octopus out-of-the-box features to deploy the AWSLambdaDemo package to the Pivot Machine, and the new step template to publish the function to AWS.
The Demo Octopus Project will look like this:
The first step just deploys the upload NuGet AWSLambdaDemo package to a custom location in the Pivot Machine (with the role AWS Lambda Demo).
The second step creates the AWS Lambda from the deployed NuGet AWSLambdaDemo package from the custom location.
After creating a release (potentially triggered by the CI server), Octopus Server can deploy it.
And voilá! A new AWS Lambda function is deployed!
The step template is under the Octopus Library OSS. You can fork and add new features to it, or open an issue in my fork. All suggestions are welcome.
[1] - http://docs.aws.amazon.com/lambda/latest/dg/welcome.html