{"id":4584,"date":"2022-06-10T09:00:00","date_gmt":"2022-06-10T07:00:00","guid":{"rendered":"https:\/\/blog.besharp.it\/?p=4584"},"modified":"2022-06-10T09:52:45","modified_gmt":"2022-06-10T07:52:45","slug":"building-a-fully-serverless-aws-based-url-shortener-using-just-a-few-services","status":"publish","type":"post","link":"https:\/\/blog.besharp.it\/building-a-fully-serverless-aws-based-url-shortener-using-just-a-few-services\/","title":{"rendered":"Building a fully Serverless AWS-based URL shortener using just a few services"},"content":{"rendered":"\n

Today is essential to fully exploit the potential of the cloud to carry out efficient and successful projects. The serverless paradigm<\/strong> is one of the most disruptive paradigms, still revolutionizing the sector.<\/p>\n\n\n\n

By exploiting the principles of serverless computing, it is possible to build applications in which the infrastructural component scales automatically<\/strong>, perfectly following the demand curve. An excellent serverless infrastructure allows you to reduce infrastructure and maintenance costs<\/strong> by reducing the customer’s area of responsibility<\/strong>. The entire infrastructure is highly available<\/strong>, scalable, and elastic by design.<\/p>\n\n\n\n

In this article, we want to introduce you to a completely serverless solution to create a URL shortener<\/strong>. In the following paragraphs, we will show a real-world use case: from the requirements to the design of a solution based on AWS’ fully managed and serverless services.<\/p>\n\n\n\n

The requirements<\/h2>\n\n\n\n

The URL shortener provides an API that can be used for link creation.<\/p>\n\n\n\n

The API should respond to a GET request like this one https:\/\/example.com\/api\/v1\/action\/shorten?url=[URI]<\/p>\n\n\n\n

The response must be plain text, and the body ought to contain the shortened URL https:\/\/example.com\/f\/7427<\/p>\n\n\n\n

When visiting the short URL, the URL shortener will redirect the visitor to the full URL.<\/p>\n\n\n\n

No authorization nor authentication is needed for this version of the URL shortener. <\/p>\n\n\n\n

The URL shortener should redirect and enforce HTTPS.<\/p>\n\n\n\n

Our solution<\/h2>\n\n\n\n

We’ll try not to use the obvious solution of just exposing a public RESTFul API using API Gateway, Lamba, and DynamoDB because it would not be fun \ud83d\ude42 and<\/em> more importantly, it isn’t the most cost-efficient solution.<\/p>\n\n\n\n

We will take advantage of the following AWS services<\/p>\n\n\n\n