Giter VIP home page Giter VIP logo

aws-infrastructure-code-serverless-webapp's Introduction

Serverless Web Apps using Amazon DynamoDB

Terraform scripts to build the AWS environment where to deploy interactive serverless web applications which uses Amazon API Gateway calls to send requests to AWS Lambda backends that query Amazon DynamoDB data.

Tested using:

Terraform v0.11.10
+ provider.aws v1.42.0

Use case description

Build and run an application and services without needing to provision, manage, and scale infrastructure.

Design, build, and deploy an interactive serverless web application, using a simple HTML/JavaScript web interface which uses Amazon API Gateway calls to end requests to AWS Lambda backends that query Amazon DynamoDB data.

Infrastructure objectives

  • Create Amazon DynamoDB

    Non-sql database to store the application data

  • Create the necessary IAM roles and polices

    To access the application data

  • Create AWS Lambda

    It will interact with DynamoDB and retrieve in several different way

  • Create custom Lambda test
  • Create Amazon API Gateway

    It will expose the Lambda function to the Internet as configured API

  • Public web site

    UI to retrieve information from DynamoDB via Lambda functions

  • Tie the three services together to build a functional serverless web app, and deploy it live on the web.

How to use

Pre-requirement: Set AWS environment variables

$ export TF_VAR_access_key=<your_key>

$ export TF_VAR_secret_key=<your-secret>

$ export TF_VAR_region=<your_region>

Initialize a working directory

$ cd serverless_intrastructure/

$ terraform init

Create an execution plan

$ terraform plan

Apply the changes required to reach the desired state of the configuration

$ terraform apply

Delete infrastructure

$ terraform destroy

How to test?

When applied the configuration terraform will show us the next output:

Outputs:

Get heroes list API endpoint = https://xdlugc2266.execute-api.us-east-1.amazonaws.com/DeploySuperAPI/getheroeslist

Get heroes mission details API endpoint = https://xdlugc2266.execute-api.us-east-1.amazonaws.com/DeploySuperAPI/getmissiondetails

api_gateway_base_url = https://xdlugc2266.execute-api.us-east-1.amazonaws.com/DeploySuperAPI

dynamoDb_created_table_name = SuperMission

Use the endpoint info to test your api directly using this curl calls:

Get heroes list

    curl -X POST \
    <Use your "Get heroes list API endpoint" output value> \
    -H 'Cache-Control: no-cache' \
    -H 'Content-Type: application/json' \
    -H 'Postman-Token: 84ac228b-d6bc-4768-9a28-a21348f68275' \
    -d '{}'

Get missing details for an specific heroe

    curl -X POST \
    <Use your "Get heroes mission details API endpoint" output value> \
    -H 'Access-Control-Request-Headers: content-type' \
    -H 'Access-Control-Request-Method: POST' \
    -H 'Cache-Control: no-cache' \
    -H 'Content-Type: application/json' \
    -H 'Origin: null' \
    -H 'Postman-Token: 8c2ee690-1e93-4784-9981-654cc7d6515c' \
    -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3604.0 Safari/537.36' \
    -d '{
    "superhero": "Batman"
    }'

Generate the SDK For Your API

On the Stage editor of your ServerlessSuperHeroesApi API Gateway, click the SDK Generation tab, then configure:

  • Platform: Javascript
  • Click Generate SDK

Next:

  • Save the zip file to a location on your computer.

  • Extract the content of the JavaScript zip file you downloaded in the serverless_intrastructure/files/apiGateway-js-sdk/ directory.

    There, you will have an HTML page that you will use to test your API.

After that:

  • Open index.html located on your serverless_intrastructure/files/apiGateway-js-sdk/ directory in your browser.

    You will notice that the drop-down list uses the API Gateway resource getheroeslist to invoke the getheroeslistFunction Lambda function.

  • Using the index web page, retrieve mission details.

  • Review the output.

Note To retrieve mission details using the index web page, select the Super Hero name in the drop down list and then click GO to display the Mission Status and Mission Dossier

aws-infrastructure-code-serverless-webapp's People

Contributors

rproenza86 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.