Giter Club home page Giter Club logo

html-lambda-cli's Introduction

html-λ-cli

A simple command line interface for html-lambda-runner.

While Amazon's Lambda functions aren't hard to make, making lot's of them is a time consuming task, especially if you're only making lots of single page serving functions. html-lambda-cli provides a convenient and clean interface to rapidly build and deploy new HTML generating Lambda functions using our html-lambda-runner module. With a bit of setup and a few lines of code, you'll have a Lambda up and running in no time.

To Install

npm install -g html-lambda-cli

Usage

init - Create the files needed for a new Lambda project in the current directory.

build - Build the project source and bundle it into a zip file in the dist folder.

serve - Preview the current Lambda by running a local server on :3000. Changes will be automatically built and get parameters will be passed.

deploy - Runs build and then uploads the result to Amazon.

Make a Lambda

Most of the work you'll need to do for each function is merely setup on Amazon's end. While it looks like a lot, it's not a hard procedure. This assumes you've setup your local AWS credentials, if you haven't yet, skip to the section below.

  1. Create a new folder for your project
  2. Run html-lambda init to create the needed files.
  3. Head over to the AWS console and open up Lambda.
  4. Click 'Create a Lambda function'.
  5. Click 'Skip' when asked to use a template.
  6. Give your function a name, description and leave the 'Runtime' set as Node.js (4.x).
  7. In the 'Edit code inline' area, put something simple for now. Something like console.log('hello') will do.
  8. Leave 'Handler' as is and select lambda_basic_execution as the Lambda role.
  9. Configure anything else if needed, then click 'Next' and 'Create'.
  10. Click on the 'API endpoints tab' and the 'Add API endpoint'.
  11. Select 'API Gateway' as the type and configure other properties as desired, setting 'Resource name' to /, 'Method' to GET 'Security' to Open.
  12. Head over to 'API Gateway' and pull up the API under your Lambda's name.
  13. Under 'Method Request' > 'URL Query String Parameters' add accessKey.
  14. Under 'Integration Request' add a new 'Content-Type' set to application/json. The template below only passes the accessKey. You can add other query parameters here as well. Click 'Save' when done.
{
      "accessKey ": "$input.params('accessKey')"
}
  1. Under 'Method Response' add a new item under 'Response Headers for 200' with a value of Content-Type.
  2. Under 'Integration Response' > 'Header Mappings', set Content-Type to 'text/html'
  3. Add a new 'Content-Type' under 'Body Mapping Templates' with the value text/html and a template of $input.path('$').
  4. Finally, click the 'Actions' button in the top left and select 'Deploy API'.
  5. Choose the development stage you selected earlier and click 'Deploy'.
  6. On the main services tab, select IAM and then in the left sidebar, choose 'Encryption Keys'.
  7. Create a new key and add yourself as a key administrator.
  8. Add lambda_basic_execution for IAM roles that can decrypt and encrypt with the key. Complete key creation.
  9. View the newly created key and copy the ARN.
  10. Paste the ARN into the lambdaKmsArn of aws-config.json. Fill in the other Lambda fields as well.
  11. In config.json set a secret key (used for simple authentication via GET over HTTPS).
  12. Finally, run html-lambda deploy.
  13. Visit your API endpoint with the proper accessKey attached, and your Lambda should present your page!

AWS Credentials

Create the file ~/.aws/credentials. The file should look like:

[default]
aws_access_key_id = <your key>
aws_secret_access_key = <your access key>

html-lambda-cli's People

Contributors

cwheel avatar

Stargazers

David Wells avatar

Watchers

Matthew Cross avatar Joseph Roberts avatar David Wells avatar James Cloos avatar Jeremy Redburn avatar  avatar  avatar  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.