This setup uses the following Amazon Web Services:
- S3
- CloudFormation
- ApiGateway
- DynamoDB
The API is based on: Swagger / OpenAPI Specification
- Clone this repository
git clone git@github.com:hipinc/api.thirdwavelist.git
cd api.thirdwavelist/- Create the lambda code file (
lambda.zip)
npm install --production
./bundle.sh- Create an S3 bucket called
api.thirdwavelistin the US East (N. Virginia,us-east-1) region and upload thelambda.zipfile
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- 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- Wait until the stack is created (
CREATE_COMPLETE)
aws cloudformation wait stack-create-complete --stack-name thirdwavelist-apigateway- Replace all nine occurrences of
$AWSRegioninswagger.jsonwith 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
- Get the
LambdaArn
aws cloudformation describe-stacks --stack-name thirdwavelist-apigateway --query "Stacks[0].Outputs"- Replace all four occurrences of
$LambdaArninswagger.jsonwith 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- 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- Update the CloudFormation template to set the
ApiIdparameter (replace$ApiIdwith theidoutput 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- Deploy to Stage v1 (replace
$ApiId)
aws apigateway create-deployment --rest-api-id $ApiId --stage-name v1- (Optional) Set the
$ApiGatewayEndpointenvironment variable (replace$ApiId)
export ApiGatewayEndpoint="$ApiId.execute-api.us-east-1.amazonaws.com/v1"The following examples assume that you replace $ApiGatewayEndpoint with $ApiId.execute-api.us-east-1.amazonaws.com
- 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- List cafes with a GET
curl -vvv https://$ApiGatewayEndpoint/cafe- Delete API Gateway (replace
$ApiId)
aws apigateway delete-rest-api --rest-api-id $ApiId- Delete CloudFormation stack
aws cloudformation delete-stack --stack-name thirdwavelist-apigateway- Delete S3 bucket (replace
$S3Bucket)
aws s3 rb --force s3://api.thirdwavelist-
csv2json ./input.csv -o ./output.json -p -s ';' -
sed 's/"TRUE"/true/g' output.json > output.json.temp; mv -f output.json.temp output.json -
sed 's/"FALSE"/false/g' output.json > output.json.temp; mv -f output.json.temp output.json -
sed 's/null/" "/g' output.json > output.json.temp; mv -f output.json.temp output.json