The Rusty serverless API that powers fm.loige.co. Developed with AWS Lambda, Rust and SAM.
If you want to build something like this for yourself, you can use this repo as a reference and follow the instructions below.
It requires a Last.fm account and a Last.fm API key.
If you want to deploy it on AWS you need an AWS account and the AWS CLI installed and configured.
You'll also need the Rust toolchain, cargo-lambda, Docker, and SAM installed on your machine.
First of all, grab an API key and make sure to populate the LASTFM_API_KEY
environment variable with it.
To run the Lambda locally you can use cargo lambda
:
$ cargo lambda watch
This will spin up a development server to which you can send requests. For example:
$ cargo lambda invoke --data-file events/example-apigw-request.json
If you want to run this as a local API, you can do that with SAM:
$ sam local start-api
Then you can send requests to http://localhost:3000/playing
.
Before deploying to AWS you most likely want to customise the template.yaml
.
In particular, you will want to change all the various parameters. I am also using a custom domain name, so you'll want to change that as well.
Domain name requires validation, so when the first deployment starts, it will stay in a pending state until you create the necessary DNS records to validate the TLS certificate. This can be done manually or by logging in the AWS console and going to the Certificate Manager service.
Note: This is only necessary for the first deployment
Once you are happy with the configuration, you can deploy the stack with:
$ sam deploy --guided
And follow the guided procedure.
Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.
Licensed under MIT License. © Luciano Mammino.