Code Monkey home page Code Monkey logo

sample-serverless-webapp's Introduction

sample-serverless-webapp

Sample webapp to demonstrate serverless concepts

Overview

This is a project that provides you everything you need to quickly create your own serverless website within AWS. The website consists of S3, Cognito, API Gateway, and DynamoDB

Table of Contents

Requirements

Steps for setting up

Create S3 Bucket

  • From the root of the project (e.g., ~/sample-serverless-webapp)
    • cd infrastructure/s3-bucket
    • terraform init
    • terraform plan
    • terraform apply -var 'bucket_name=<bucket_name>'
  • Take note of the two variables (bucket_name & website_endpoint) printed out by terraform

Create Cognito

  • From the root of the project (e.g., ~/sample-serverless-webapp)
    • cd infrastructure/cognito
    • terraform init
    • terraform plan
    • terraform apply -var 'cognito_pool=<cognito_pool_name>' -var 'webapp_name=<webapp_name>'
  • Take note of the three variables (cognito_pool, cognito_pool_client, and cognito_pool_arn) printed out by terraform

Create API Endpoint

  • From the root of the project (e.g., ~/sample-serverless-webapp)
    • cd infrastructure/api-gateway
    • install the project requirements
      • npm i serverless-python-requirements
    • edit serverless.yml
      • Add the arn to the create function where it mentions 'authorizer'
    • sls deploy --api_name <api_name>
  • Take note of the API Endpoints provided by serverless (e.g., 'hxxps://8wonhgpbu3.execute-api.us-east-1.amazonaws.com/dev/notes')

Configure Website

  • From the root of the project (e.g., ~/sample-serverless-webapp)
    • cd website/src/
    • edit main.js
      • In the section Amplify.configure insert the following: region, userPoolId, and userPoolWebClientId
      • save and exit main.js
    • edit config.js
      • Insert your API Endpoint into the baseURI
      • save and exit config.js

Create Website

  • From within the website directory
    • execute npm run build
    • this will create a 'dist' directory
  • Copy the contents of the 'dist' directory into your S3 bucket
    • aws s3 cp --recursive ~/sample-serverless-webapp/website/dist s3://<bucket_name>
  • Now go to your website (refer back to the bucket_domain that you took note of)

Cleaning Up

  • Go back into the s3-bucket directory
    • aws s3 rm s3://<bucket_name> --recursive
    • 'terraform destroy -auto-approve'
  • Go back into the cognito directory and execute 'terraform destroy -auto-approve'
  • Go back into the api-gateway directory and execute 'sls remove --api_name <api_name>'

sample-serverless-webapp's People

Contributors

confusdcodr avatar

Stargazers

 avatar

Watchers

 avatar

sample-serverless-webapp's Issues

Dependabot couldn't find a package.json for this project

Dependabot couldn't find a package.json for this project.

Dependabot requires a package.json to evaluate your project's current JavaScript dependencies. It had expected to find one at the path: /website/package.json.

If this isn't a JavaScript project, or if it is a library, you may wish to disable updates for it from within Dependabot.

You can mention @dependabot in the comments below to contact the Dependabot team.

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.