Skip to main content

Retrieving Cozie data

Data flow from database to researcher

Overview

How to retrieve data from a user/researcher perspective is shown under Data and Download

There are a few technical constraints that are governing the design of the web API for Cozie dat retrieval:

  • Payload limit of Python Lambda function: 6MB
  • Timeout limit of AWS API Gateway: 30 seconds
  • InfluxDB Cloud cluster memory: 4GB

If any of these limits are reached, the web API returns an error. If the memory of InfluxDB is exceeded, the cluster crashes and restarts. This process takes a few minutes during which no data can be written to or read from the InfluxDB. To avoid reaching the memory limit of the InfluxDB data of only one participant is queried at a time.

Lambda function code

Lambda configuration

ConfigurationValueComment
General configuration
Memory4096 MB
Ephemeral storage512 MBdefault value
Timeout4 min 0 sec
Triggers
API Gatewaycozie-apple-v3-researcher-api
Environment variables
DB_HOSTXXX.influxcloud.net(replace 'XXX')
DB_NAMEcozie-apple
DB_PASSWORDXXX(replace 'XXX')
DB_PORT8086
DB_USERCozie-Apple-Lambda-Writer-App-API
S3_BUCKET_NAMEcozie-apple-web-api
Layers
AWSSDKPandas-Python311AWS Layer for Pandas
InfluxCustom layer for InfluxDB client

S3 bucket configuration

ConfigurationValueComment
General configuration
Bucket namecozie-apple-web-api

API Gateway configuration

ConfigurationValueComment
Proxy resourcedisableddefault
Resource path/
Resource nameretrieve
CORS (Cross Origin Resource Sharing)enabled
Method details
Method typeANY
Integration typeLambda function
Lambda proxy integrationenabled
Lambda functionarn:aws:lambda:[region]:[Accound ID]:function:cozie-apple-v3-researcher-read-influxcheck dropdown menu
Default timeoutenabled29 seconds (default)
Method request settings
AuthorizationNonedefault
Request validatorNonedefault
API key requiredenabled
URL query string parameters
leave default
HTTP request headers
leave default
Request body
leave default

Conclusion

If you don't need to offer a web API then it might be easier to retrieve the data from your database directly and omitting this part of the web API.