html-lambda-cli

1.0.3 • Public • Published

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>

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.3
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.3
    1
  • 1.0.2
    0
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i html-lambda-cli

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • cwheel
  • mattcsalsify