Coder Social home page Coder Social logo

bfansports / amazon-api-gateway-url-shortener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/amazon-api-gateway-url-shortener

0.0 0.0 1.0 1.87 MB

Creates a serverless URL shortener on AWS without using AWS Lambda or any other compute.

License: MIT No Attribution

JavaScript 25.52% HTML 7.11% Vue 66.53% Shell 0.32% SCSS 0.51%

amazon-api-gateway-url-shortener's Introduction

Simpler Functionless URL Shortener

This app creates a URL shortener without using any compute. All business logic is handled at the Amazon API Gateway level. The basic app will create an API Gateway instance utilizing Cognito for authentication and authorization. It will also create an Amazon DynamoDB table for data storage. It will also create a simple Vuejs application as a demo client.

Read the blog series about this application:

  1. Building a serverless URL shortener app without AWS Lambda – part 1
  2. Building a serverless URL shortener app without AWS Lambda – part 2
  3. Building a serverless URL shortener app without AWS Lambda – part 3

About this fork

There is no Amplify, Cognito, Cloud Front. You will target the API directly.

Authentication is done using API Gateway API Keys. You must configure one and provide a key in your queries header using the X-API-Key header.

DynamoDB table now allows item auto expiration after one month. We add a new field expiration to all entries and set the table to use this field to auto expire items.

owner is now set to bFAN and not dynamic as there is no more Cognito UserPool but you can change it directly in the api.xml file.

The Backend

Services Used

Requirements for deployment

  • AWS CLI

  • AWS SAM CLI v0.37.0+

  • Forked copy of this repository. Instructions for forking a GitHib repository can be found here

  • A GitHub personal access token with the repo scope as shown below. Instructions for creating a personal access token can be found here

    Personal access token scopes

    Be sure and store you new token in a place that you can find it.

Deploying

In the terminal, use the SAM CLI guided deployment the first time you deploy

sam deploy -g

Choose options

You can choose the default for all options except GithubRepository and **

## The name of the CloudFormation stack
Stack Name [URLShortener]:

## The region you want to deploy in
AWS Region [eu-west-1]:

## The name of the application (lowercase no spaces). This must be globally unique
Parameter AppName [shortener]:

## GitHub forked repository URL
Parameter GithubRepository []:

## Github Personal access token
Parameter PersonalAccessToken:

## Shows you resources changes to be deployed and requires a 'Y' to initiate deploy
Confirm changes before deploy [y/N]: 

## SAM needs permission to be able to create roles to connect to the resources in your template
Allow SAM CLI IAM role creation [Y/n]:

## Save your choice for later deployments
Save arguments to samconfig.toml [Y/n]:

SAM will then deploy the AWS CloudFormation stack to your AWS account and provide required outputs for the included client.

After the first deploy you may re-deploy using sam deploy or redeploy with different options using sam deploy -g.

Usage

You must include the X-API-Key Header in your http queries to authenticate with API Gateway. The Key is available in API Gateway API Keys section in the console.

The URLs to call are:

  • POST shorter.bfansports.com/app: Create a new short URL.
    • body: {"id":"ABCDEFGHIJ12345", "url":"https://the.url.I.want.to.reach.com"}
  • GET shorter.bfansports.com/${id}: Get the URL associated with an ID
    • path: The ID of the URL to redirect to

Other calls are available. See the api.yaml file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.