Skip to content

PyMyFord/example-prefect-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

example-prefect-lambda

Start your car from an AWS Lambda.

Caveats

This tutorial does not cover authentication. You will need to keep your URL secret in order to avoid others from starting your car!! The minimum viable security for this tutorial is to require that a user pass a specific, secret header string or GET param. Do not leave this endpoint open to the world after completing this tutorial.


This is an example script that uses PyMyFord/prefect from an AWS Lambda running Python 3 to start a car remotely.

Setup

Generate a code bundle zipfile

You can either clone this repository or copy the code into your own handler.py. You will also need to create a new virtual environment:

$ virtualenv v-env

Once you have the following in your directory, you can zip it into a .zip file to upload to AWS Lambda.

$ ls
v-env/
handler.py

Zip the files like this:

$ zip -r9q prefect-lambda *

Create a new Lambda

Navigate to the AWS lambda console and click on "Create Function":

image

Select the option to 'author the lambda from scratch.' Set the runtime to Python 3 (the latest as of writing is 3.8). The other default settings are fine for now:

image

Upload your code

Option 1: Web Console

Scroll to "Function Code" and select "upload a .zip". Upload the .zip you created in the previous step.

Option 2: aws CLI

You can also use the AWS command line utility (aws) to do this:

$ AWS_PROFILE=personal aws lambda update-function-code --function-name my-prefect-lambda --zip-file fileb://prefect-lambda.zip

Set the handler pointer

Under "handler" in the lambda web console, set the handler function to handler.handler. This will run the handler function inside the handler.py file. (main.foo will run the function foo() in main.py when the API is called, for another example.)

Set the environment variables

You must set prefectuser and prefectpass in the Environment Variables section of the console.

Add an API Gateway trigger

Scroll to the "Designer" section of the lambda page and click "Add Trigger":

image

Select "API Gateway" from the dropdown:

image

Create a new API Gateway:

image

Press "Add".

Back on the lambda function screen, under the Designer section, click on the API Gateway to highlight it (it will turn light blue). The next section will become an API Gateway inspector, and will show you your new API Gateway trigger URL. Note this, but protect it: This tutorial does not cover authentication, so anyone with this URL will be able to start your car!

Usage

$ curl https://[your_api_gateway_url].execute-api.us-east-1.amazonaws.com/[your_extension]

About

Start your car from an AWS Lambda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages