aws-samples/amazon-dax-lambda-nodejs-sample

Name: amazon-dax-lambda-nodejs-sample

Owner: AWS Samples

Description: A sample application showing how to use Amazon DynamoDB Accelerator (DAX) with Lambda and CloudFormation.

Created: 2018-03-23 20:15:48.0

Updated: 2018-05-14 23:32:46.0

Pushed: 2018-05-08 04:22:23.0

Homepage: null

Size: 10

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Amazon DynamoDB Accelerator (DAX) Lambda Node.js Sample

A sample application showing how to use Amazon DynamoDB Accelerator (DAX) with Lambda and CloudFormation. This is based on the blog post at TODO.

Setup & Deployment

Deploying the demo will require npm, the AWS CLI, and an AWS account. The AWS credentials for that account should be set up in the AWS CLI.

First, download the dependencies using npm:

npm install

Then, create a zip file called geturl.zip containing the lambda and node_modules folders. On Mac/Linux/WSL, uses the zip command:

zip -qur geturl node_modules lambda

Otherwise, put the necessary folders in a zip file.

CloudFormation needs the code & template to be stored in an S3 bucket (replace bucket-name with something unique):

aws s3 mb s3://bucket-name

Now we can create the CloudFormation package and deploy it:

aws cloudformation package --template-file template.yaml --output-template-file packaged-template.yaml --s3-bucket bucket-name
aws cloudformation deploy --template-file packaged-template.yaml --capabilities CAPABILITY_NAMED_IAM --stack-name amazon-dax-lambda-nodejs-sample

One the CloudFormation stack is created, determine the insternal endpoint name (macOS/Linux/WSL):

gwId=$(aws apigateway get-rest-apis --query "items[?name == 'amazon-dax-lambda-nodejs-sample'].id | [0]" --output text)
endpointUrl="https://$gwId.execute-api.region.amazonaws.com/Prod"

To shorten a URL:

curl -d 'https://www.amazon.com' "$endpointUrl"

The output will be a “slug” that can be used to fetch the URL (in this case, grqpaeet):

curl -v "$endpointUrl/grqpaeet"
License Summary

This sample code is made available under a modified MIT license. See the LICENSE file.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.