conda -V
, update with conda update conda
if lower than 4.6)virtualenv
with python3 -m pip install --user virtualenv
(https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) - Note that conda can also manage virtual environments very nicely but it is easier to use virtualenv
directly to make smaller lambda function environmentsaws --version
aws configure
(doc)aws rds describe-db-instances
make clean install
, which does the following:source bin/activate
(folder name)
at the beginning of the console linerequirements.txt
, here python lambda (doc) and postgresql db drivers (doc)make init
, which does the following:lambda init
service.py
file and connected scriptsmake invoke
to run lambda function with the information in some event file event.json
lambda invoke -v --event_file event.json
in the virtual environmentconfig.yaml
exists yet (should have been created during make init
), run make config.yaml
config.yaml
, see Integration section for details (no worries if not everything correct right away, deploy will throw errors)make deploy
to deploy the lambda function:lambda deploy
in the virtual environmentOnce the Lambda function is deployed it can be viewed and tested in the Lambda functions console https://console.aws.amazon.com/lambda. Detailed log messages and errors are available at the Cloudwatch console https://console.aws.amazon.com/cloudwatch. For the lambda function to be useful though, it usually needs to be setup with the right IAM role, VPC access and usually some sort of API gateway.
AWSLambdaVPCAccessExecutionRole
(see setup docs for details)role
setting of the config.yaml
subnet_ids
setting in config.yaml
- format: [subnet-1,subnet-2,...]
security_group_ids
setting in config.yaml
- format: [sg-1,sg-2,...]
make deploy
), these settings should now all be listed in the details for the lambda function at https://console.aws.amazon.com/lambdalambda deploy
, simply add them manually in the console at https://console.aws.amazon.com/lambda for the new lambda function (under the Network section)For the lambda function to be easily accessible via web API (be it http or something else), an API gateway needs to be set up, see this link for a good example and the API gateway administration: https://console.aws.amazon.com/apigateway
Notes:
- API gateway configuration is completely independent of the lambda function deployment and must be configured separately (i.e. no setting in the config.yaml
that plays a role here)
- if you want to make the API secure, good to include an API key requirement which requires creating an API key and setting up a usage plan that allows the API key for a specific API gateway and deployed stage (this stage's method must have the API Key Required
setting in the Method->Method Request
set to true
).
- API development can be very tricky, POSTMAN helps with testing APIs:
Lastly, the particle photons need to actually send data to the API, this is done via Webhooks.
webhook_data_log.json
and webhook_state_log.json
files exist yet (should have been created during make init
), run make webhooks
<<ACCESS_POINT>>
, <<STAGE>>
and <<RESOURCE>>
are parameters from the API gateway<<API-KEY>>
is the access key from the API gateway (if configured to need one, see details above)<<OWNER>>
is the name/id of the owner record in the database (depends on what is set up in your database)particle webhook create webhook_data_log.json
and particle webhook create webhook_state_log.json
(need to be logged into the particle account via particle login
)particle webhook list
and particle webhook delete
before re-creating updated versionsserverless provides a potential deployment alternative compatible with multiple providers, not just AWS but it's a bit different setup (and not currently what we use). Below are a few notes on the approach.
brew install node
, manual installation of https://github.com/nvm-sh/nvm and then nvm install node
) and then the serverless framework with npm install -g serverless
(see https://www.serverless.com/framework/docs/providers/aws/guide/quick-start/ for details)serverless config credentials --provider aws --key AKIAIOSFODNN7EXAMPLE --secret wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
(and the correct key and secret for the new user created above)serverless create \
--template aws-python3 \
--name lablogger_lambda \
--path lablogger_lambda
(example: https://www.serverless.com/blog/serverless-python-packaging)lablogger_lamda
folder (cd lablogger_lambda
)python3 -m venv env
(note that using conda for this makes later steps more complicated and the lambda function zip bigger than it needs to be)source venv/bin/activate
pip install ...
but keep in mind that lambda functions have a size limit so ideally restrict to only absolutely necessary packages.py
filerequirements.txt
file with pip freeze > requirements.txt
deactivate
when doneserverless.yml
deployment file and package.json
file for node dependencies as described here: https://www.serverless.com/blog/serverless-python-packaging#deploying-your-serviceserverless deploy
(needs docker installed)Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.