Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

[Deprecated] API for serving quality datapoints of niche markets to enable consumers to make concious decisions

License

Notifications You must be signed in to change notification settings

thirdwavelist/thirdwavelist-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api.thirdwavelist

Setup

This setup uses the following Amazon Web Services:

  • S3
  • CloudFormation
  • ApiGateway
  • DynamoDB

The API is based on: Swagger / OpenAPI Specification

Instructions

  1. Clone this repository
git clone git@github.com:hipinc/api.thirdwavelist.git
cd api.thirdwavelist/
  1. Create the lambda code file (lambda.zip)
npm install --production
./bundle.sh
  1. Create an S3 bucket called api.thirdwavelist in the US East (N. Virginia, us-east-1) region and upload the lambda.zip file

Note: At this point please ensure you have set up awscli and ran aws configure before continuing.

aws s3 mb s3://api.thirdwavelist
aws s3 cp lambda.zip s3://api.thirdwavelist/lambda.zip
  1. Create cloudformation stack
aws cloudformation create-stack --stack-name thirdwavelist-apigateway --template-body file://template.json --capabilities CAPABILITY_IAM --parameters ParameterKey=S3Bucket,ParameterValue=api.thirdwavelist
  1. Wait until the stack is created (CREATE_COMPLETE)
aws cloudformation wait stack-create-complete --stack-name thirdwavelist-apigateway
  1. Replace all nine occurrences of $AWSRegion in swagger.json with the region that you are creating your API and Lamdba in
cp swagger.json swagger.json.bak
sed 's/$AWSRegion/us-east-1/g' swagger.json.bak > swagger.json
  1. Get the LambdaArn
aws cloudformation describe-stacks --stack-name thirdwavelist-apigateway --query "Stacks[0].Outputs"
  1. Replace all four occurrences of $LambdaArn in swagger.json with the ARN from the stack output above (e.g. look for the XXX and replace it with the output of the previous command)
sed 's/$LambdaArn/XXX/g' swagger.json > swagger.json.temp; mv -f swagger.json.temp swagger.json
  1. Deploy the API Gateway

Note: make sure you have an up-to-date version (aws --version) of the AWS CLI >= 1.10.18. Learn more here.

aws apigateway import-rest-api --fail-on-warnings --body file://swagger.json
  1. Update the CloudFormation template to set the ApiId parameter (replace $ApiId with the id output from above)
aws cloudformation update-stack --stack-name thirdwavelist-apigateway --template-body file://template.json --capabilities CAPABILITY_IAM --parameters ParameterKey=S3Bucket,UsePreviousValue=true ParameterKey=S3Key,UsePreviousValue=true ParameterKey=ApiId,ParameterValue=$ApiId
  1. Deploy to Stage v1 (replace $ApiId)
aws apigateway create-deployment --rest-api-id $ApiId --stage-name v1
  1. (Optional) Set the $ApiGatewayEndpoint environment variable (replace $ApiId)
export ApiGatewayEndpoint="$ApiId.execute-api.us-east-1.amazonaws.com/v1"

Use the RESTful API

The following examples assume that you replace $ApiGatewayEndpoint with $ApiId.execute-api.us-east-1.amazonaws.com

  1. Create a cafe and POST it
curl -vvv -d '{"name": "The best coffeeshop", "thumbnail": "http://lorempixel.com/200/200/city/1", "address": "Vaci street 1"}' -H "Content-Type: application/json" https://$ApiGatewayEndpoint/cafe
  1. List cafes with a GET
curl -vvv https://$ApiGatewayEndpoint/cafe

Teardown

  1. Delete API Gateway (replace $ApiId)
aws apigateway delete-rest-api --rest-api-id $ApiId
  1. Delete CloudFormation stack
aws cloudformation delete-stack --stack-name thirdwavelist-apigateway
  1. Delete S3 bucket (replace $S3Bucket)
aws s3 rb --force s3://api.thirdwavelist

Update database

  1. csv2json ./input.csv -o ./output.json -p -s ';'

  2. sed 's/"TRUE"/true/g' output.json > output.json.temp; mv -f output.json.temp output.json

  3. sed 's/"FALSE"/false/g' output.json > output.json.temp; mv -f output.json.temp output.json

  4. sed 's/null/" "/g' output.json > output.json.temp; mv -f output.json.temp output.json

About

[Deprecated] API for serving quality datapoints of niche markets to enable consumers to make concious decisions

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •