Amazon AWS Lambda function for accessing Purple Air API and rendering the result as a web page
- Obtain a Purple Air API key. Email [email protected]; be sure to provide your first and last name.
- Create an AWS Lambda Node.js function, running on Node.js 18.x
- Add the environment variable
API_KEY
to the Lambda configuration; set the value to your Purple Air API read key. - Create an AWS API Gateway:
- Select "HTTP API".
- Add an integration to your Lambda function
- Configure the route with the
GET
HTTP method
- Configure the AWS API Gateway:
- Select the gateway
- Select Integration
- Create a new Parameter mapping:
Response (based on a status code)
Response status code
of 200- Add new mapping for
header.Content-Type
,Overwrite
with valuetext/html
.
Access the created Amazon API Gateway, with the specified route, passing in a comma-delimited list of Purple API Sensor IDs for the sensors parameter. You can look up sensor IDs via the Purple Air Map. Click on a particular sensor, and extract the value of the select
URL parameter.
- Purple Air sensors do not return AQIs. Instead, they return particle counts, which need to be transformed to AQIs.
- The temperature reading is not an environmental value; instead, it is the internal temperature of the sensor itself. Testing has shown this to be 8° above the environmental temperature. Read more here.