Coder Social home page Coder Social logo

intro-to-aws's Introduction

Intro to AWS

[Advanced] - AWS Intro, Set up AWS and Serverless, Lambda, API Gateway

What is AWS?

Amazon Web Services(AWS) is a platform of cloud computing which provides a simple way to access servers, storage, databases and a broad set of applications. We are basically renting out AWS servers to host our application instead of having to maintain our own. There are many type of services in AWS, each performing a specific functionality.

Why use AWS?

  • Low Cost - As developers, we pay end up paying less if we want to host our application on AWS servers. Since AWS has many active users, it drives down the cost of server use.
  • Advanced security features - Expert security staff are continually upgrading and maintaining servers.
  • Highly reliable - your data is matained in many different data centers just in case one goes down

What is Serverless Framework?

AWS allows us to access the their platform through programmatic access or AWS management console access. In this course, we will be using programmatic access through the Serverless Framework which allows us to access AWS through the command line and code editor.

What is AWS Lambda?

An AWS service that allows developers to run code without having to manage a server. No express server needed. A Lambda is basically a function in the cloud.

What is API Gateway?

An AWS service that enables developers to create, publish, maintain, monitor, and secure APIs at any scale. You can create APIs that access AWS or other web services, as well as data stored in the AWS Cloud. It allows developers to create CRUD routes(GET, POST, PUT, DELETE).

What does deploy mean?

Moving our application to the AWS cloud/servers. In our case, we will be deploying our Lambda function.

What will we be doing?

We will conifgure our AWS credentials and Serverless credentials, then will set up our Lambda function and API Gateway to deploy a GET url enpoint for our frontend client.

AWS Diagram

Configuring AWS and Serverless

  1. Your instructor should have provided you with a Access Key ID and a Secret Access Key. Please save them in a safe location.
  2. Open up your git-bash terminal
  3. Install aws-cli for windows
  4. Configure Access_ID, Secrect_Access_id, and region on our computer
    • Type aws configure then hit enter
      • Input the following
        • access_id
        • access_secret_id
        • region: us-west-2
  5. npm install Serveless Framework npm install -g serverless
  6. Set Serverless provider credentials
serverless config credentials --provider aws --key YOUR_ACCESS_KEY --secret YOUR_SECRET_KEY

Create Serverless Template and Lambda Function

  1. Create a new directory/projectmkdir YOUR_PROJECT_NAME
  2. CD into your directory/project cd YOUR_PROJECT_NAME
  3. Create boilerplate/template to use Serverless**
serverless create --template aws-nodejs
  1. Change service name in serverless.yml file
  2. Uncomment the following:*
stage: dev
region: us-east-1
  • Then set region to us-west-2
  1. Deploy your code
serverlesss deploy
  1. Invoke deployed function
serverless invoke -f FUNCTION_NAME 
  1. Change message in lambda function then redeploy function only
serverless deploy -f FUNCTION_NAME
  1. Invoke deployed function
serverless invoke -f FUNCTION_NAME 
  1. Get logs from deployed function
serverless logs -f FUNCTION_NAME -t
  1. If need help with serverless commands
serverless --help

Create API Gateway GET request

  1. Paste in the following code snippet in serverless.yml
functions:
  FUNCTION_NAME:
    handler: handler.FUNCTION_NAME
    events:
      - http:
          path: PATH_NAME
          method: get
          cors: true
  1. Paste in the following in your response object, above the body property

This allows CORS

headers: {
     'Access-Control-Allow-Origin': '*',
     'Access-Control-Allow-Credentials': true
   },
  1. Deploy your code
serverless deploy
  1. You should see a GET endpoint url under endpoints:

Serverless Workflow

  1. Write your functions
  2. Useserverless deployonly when you've made changes toserverless.yml
  3. Useserverless deploy function -f FUNCTION_NAMEto rapidly deploy changes when you are working on a specific AWS Lambda Function.
  4. Useserverless invoke -f FUNCTION_NAMEto test your AWS Lambda Functions on AWS.
  5. Open up a separate tab in your console and stream logs in there viaserverless logs -f FUNCTION_NAME -t.

Class Exercise

  1. In your Lambda function, create a random food generator
  2. Create file structure in your root path for you frontend
serverless-demo
|
+ --public
    |
    +-- index.html
    +-- styles.css
    +-- app.js
  1. Use axios in your app.js to get a random food from your newly created GET endpoint
  2. Render the following to your browser Today, I will eat a ${INSERT_FOOD_VALUE}
  3. Your browser should render a different food everytime you refresh

Resources

What is AWS?

How does Amazon Web Services (AWS) work? - Quora

Serverless Framework - AWS Lambda Guide - Quick Start Serverless Framework - CORS & API Gateway

AWS Services

What Is AWS Lambda?

What Is Amazon API Gateway?

intro-to-aws's People

Contributors

jaygiang avatar

Watchers

James Cloos 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.