This serverless
app combined with express
is designed to pull information from a Google Fit API and present it either directly or via an aggregator to my personal projects.
Install dependencies with:
npm install
and then deploy with:
serverless deploy
After running deploy, you should see output similar to:
Deploying fitness-tracker to stage dev (us-east-1)
✔ Service deployed to stack fitness-tracker-dev (196s)
endpoint: ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com
functions:
api: fitness-tracker-dev-api (766 kB)
Note: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to httpApi
event docs.
After successful deployment, you can call the created application via HTTP:
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/
Which should result in the following response:
{"message":"Hello from root!"}
Calling the /hello
path with:
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/hello
Should result in the following response:
{"message":"Hello from path!"}
If you try to invoke a path or method that does not have a configured handler, e.g. with:
curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/nonexistent
You should receive the following response:
{"error":"Not Found"}
It is also possible to emulate API Gateway and Lambda locally by using serverless-offline
plugin. In order to do that, execute the following command:
serverless plugin install -n serverless-offline
It will add the serverless-offline
plugin to devDependencies
in package.json
file as well as will add it to plugins
in serverless.yml
.
After installation, you can start local emulation with:
serverless offline
To learn more about the capabilities of serverless-offline
, please refer to its GitHub repository.