Name: elasticache-geospatial-public-bikes
Owner: Amazon Web Services - Labs
Owner: AWS Samples
Description: Sample application that demonstrates use of Redis Geospatial commands using Amazon ElastiCache, AWS Lambda, and Serverless Application Model.
Created: 2017-03-08 18:25:01.0
Updated: 2017-09-20 04:08:20.0
Pushed: 2017-03-09 15:25:53.0
Homepage: null
Size: 608
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
public-bikes is a sample project that utilizes the AWS Serverless Application Model (SAM) in conjunction with Amazon ElastiCache to find nearby public bike stations.
For more details on this project, please visit the accompanying blog post.
To get started, clone this repository locally:
t clone https://github.com/awslabs/elasticache-geospatial-public-bikes.git
The repository contains CloudFormation templates and source code to deploy and run a complete sample application.
To run the public-bikes sample application, you will need to:
Before deploying the sample, install several dependencies using NPM:
public-bikes/server
api
m install
../stream
m install
..
The deployment of our AWS resources has been broken into two CloudFormation templates. The first of which contains network resources, including VPC, Subnets, and Gateways. While not strictly necessary in this example, utilizing VPC is intended to help secure our deployment.
Deploy the network stack (network.yaml) via the AWS CLI:
s cloudformation deploy --template network.yaml --stack-name public-bikes-network
Create a new S3 bucket from which to deploy our source code (ensure that the bucket is created in the same AWS Region as your network and services will be deployed):
s s3 mb s3://<MY_BUCKET_NAME>
Using the SAM, package your source code and serverless stack:
s cloudformation package --template-file app-sam.yaml --s3-bucket <MY_BUCKET_NAME> --output-template-file app-sam-output.yaml
Once packaging is complete, deploy the stack (note: this step may require 10-15 minutes as ElastiCache is deployed):
s cloudformation deploy --template-file app-sam-output.yaml --stack-name public-bikes-dev --capabilities CAPABILITY_IAM
After your stack has been created, the sample API has been deployed and you can retrieve the domain of the API (going forward, we will refer to it as API_DOMAIN):
s cloudformation describe-stacks --stack-name public-bikes-dev --query 'Stacks[0].Outputs[?OutputKey==`ApiDomain`].OutputValue'
For our sample application, we have included a special API endpoint that retrieves sample data (for Chicago's Divvy bike share) and loads it to DynamoDB. To load the data to your environment:
rl https://<API_DOMAIN>/Prod/stations/setup
Now that we have deployed all of our AWS resources and loaded a small set of sample data, we can test our service by passing a latitude and longitude in downtown Chicago:
rl ?L 'https://<API_DOMAIN>/Prod/stations?latitude=41.8802596&longitude=-87.6346818'
The resulting response will contain the 10 closest Divvy bike locations to the passed coordinates, including the distance (in miles) and coordinates of the station:
"name": "Wacker Dr & Washington St-Chicago",
"distance": "0.2484 mi",
"coordinates": {
"latitude": 41.88327238502640881,
"longitude": -87.63731449842453003
}
"name": "State St & Harrison St-Chicago",
"distance": "0.5589 mi",
"coordinates": {
"latitude": 41.87405360416989453,
"longitude": -87.62771755456924438
}
Finally, we will clean up the AWS environment using CloudFormation:
s cloudformation delete-stack --stack-name public-bikes-dev
s cloudformation delete-stack --stack-name public-bikes-network