Build a Serverless URL Shortener With Go

Using AWS Lambda, DynamoDB, and API Gateway

Photo by Maxwell Nelson on Unsplash

This blog post covers how to build a Serverless URL shortener application using Go. It leverages AWS Lambda for business logic, DynamoDB for persistence and API Gateway to provide the HTTP endpoints to access and use the application. The sample application presented in this blog is a trimmed down version of bit.ly or other solutions you may have used or encountered.

It’s structured as follows:

  • I will start off with a quick introduction and dive into how to deploy try the solution.
  • After that, I will focus on the code itself. This will cover:
  • The part which is used to write the infrastructure (using Go bindings for AWS CDK)
  • And also the core business logic which contains the Lambda function (using Lambda Go support) as well as the DynamoDB operations (using the DynamoDB Go SDK)

In this blog, you will learn:

  • How to use the DynamoDB Go SDK (v2) to execute CRUD operations such as PutItem, GetItem, UpdateItem and DeleteItem
  • How to use AWS CDK Go bindings to deploy a Serverless application to create and manage a DynamoDB table, Lambda functions, API Gateway and other components as well.

Once you deploy the application, you will be able to create short codes for URLs using the endpoint exposed by the API Gateway and also access them.

# create short code for a URL (e.g. https://abhirockzz.github.io/)
curl -i -X POST -d 'https://abhirockzz.github.io/' -H 'Content-Type: text/plain' $URL_SHORTENER_APP_URL
# access URL via short code
curl -i $URL_SHORTENER_APP_URL/<short-code>

Build a Serverless URL Shortener With Go was originally published in Better Programming on Medium, where people are continuing the conversation by highlighting and responding to this story.

0
(Visited 2 times, 1 visits today)