Deploy an Application onto AWS Lambda
Warning
This content is part of the legacy version of Waypoint that is no longer actively maintained. For additional information on the new vision of Waypoint, check out this blog post and the HCP Waypoint documentation.
With Waypoint, it is quick and easy to deploy and release applications on AWS Lambda.
In this tutorial, you will use Waypoint's AWS Lambda plugin to build a Docker image containing a Ruby application, push it to a Elastic Container Registry (ECR) repository, then deploy the image to Lambda. Afterwards, you will update the application and deploy the updated application.
Prerequisites
You'll need to install waypoint
0.3.0 or greater locally, clone the example repository (detailed in the next section), set up your AWS credentials, and create an Elastic Container Registry.
You'll be most comfortable if you have already used Waypoint to do a local deployment with our Get Started collection.
Optional: Provision a Kubernetes cluster and install the Waypoint server to Kubernetes in order to unlock all Waypoint functionality (including application logs
, exec
, and ui
access).
Clone the examples repository
The code for this tutorial is in the hashicorp/waypoint-examples
repository. Clone the repository with git.
Change into the cloned repository. This project uses Ruby but the following instructions will work with any language that can be built with a cloud native buildpack.
Install the Waypoint server
The Waypoint server must be installed. You may install it locally which requires fewer steps but limits the functionality of some Waypoint commands. Or, install to a Kubernetes or Nomad cluster for full functionality (including the logs
, exec
, and ui
commands).
You can run the Waypoint server locally in Docker in order to achieve a minimal deployment of your applications on ECS.
Note
A local server used with a remote deployment only supports limited functionality. The logs
, exec
, and other commands require a remote server with a remote deployment.
Install the Waypoint server to your local Docker instance.
If you run into any errors, see the troubleshooting page which has instructions for resetting the Waypoint server in Docker.
Explore waypoint.hcl
Open the
waypoint.hcl
file. In this section, you will explore the build
, deploy
, and release
steps for this
project.
The
waypoint.hcl
file uses theaws-ecr
registry plugin during thebuild
stage. Theaws-ecr
plugin uses your AWS credentials and internally builds the correct URL to the AWS API.It is also possible to configure this manually with the
docker
plugin. Other configuration options are listed in the plugin documentation.Use the
aws-lambda
plugin for thedeploy
stage. Theregion
parameter is required, but you can specify theiam_role
,memory
andtimeout
for your Lambda function. See the plugin documentation for other configuration options.Finally, Waypoint will release your application using the
aws-alb
plugin, which will provision an Application Load Balancer (ALB) to serve traffic to your Lambda endpoint.
Initialize Waypoint
Initialize the project with the init
command.
Read the troubleshooting page if you run into any errors.
Build, deploy, and release the application
Deploy the application with up
. Waypoint will error the first time when attempting to provision Lambda. This is expected behavior and will be resolved in a future release.
Tip
This may take a few minutes to execute, especially if this is the first time that you push the image to the registry.
Rerun waypoint up
to deploy Lambda and the ALB.
Visit the Release URL or the Deployment URL to view the application running on Lambda.
Try appending ?name=Turing
to the Release or Deployment URL (for example: http://waypoint-learn-waypoint-lambda-1827600373.us-west-2.elb.amazonaws.com/?name=Turing
). The service will return a welcome message with the name you inserted.
You can visit the Lambda console to verify the deployed Lambda function.
Update Lambda function
You can schedule a new application deployment through Waypoint.
First, update the welcome message in handler.rb
.
Then, redeploy your application with the up
command.
Visit the Release URL or the Deployment URL to view the application running on Lambda.
Tip
It might take a couple of minutes for the Lambda function to warm up.
Notice that Lambda is returning the updated welcome message.
Destroy the instance
To deprovision the container, run destroy
.
If there is an error, try again after a few seconds.
Note
The destroy
command will not delete container images in the registry or the ECS cluster itself. Visit the ECR console to manually delete the entire registry or individual container images.
Next steps
In this tutorial, you deployed a web application with Waypoint.
AWS Lambda can also be used to deploy an API Gateway or schedule periodic tasks as with cron
.
Experiment with omitting the aws-alb
releaser if you want to use Waypoint to build and deploy a container but use other AWS features with your deployed container.
Learn more about Waypoint by following along with the other tutorials for Azure, Google Cloud, and others, or read the documentation for other Waypoint plugins.