Code for triggering lambda function for ingesting WZDx feed data based on the WZDx Feed Registry Socrata dataset.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
If you plan to deploy the script on AWS Lambda, you need access to an AWS account and be able to assign role(s) to a lambda function. There needs to be a role that is able to invoke lambda functions and perform list/read/write actions to relevant buckets in S3.
If you plan to deploy the script on your local machine, you need the following:
- Have access to Python 3.6+. You can check your python version by entering
python --version
andpython3 --version
in command line. - Have access to the command line of a machine. If you're using a Mac, the command line can be accessed via the Terminal, which comes with Mac OS. If you're using a PC, the command line can be accessed via the Command Prompt, which comes with Windows, or via Cygwin64, a suite of open source tools that allow you to run something similar to Linux on Windows.
- Have your own Free Amazon Web Services account.
- Create one at http://aws.amazon.com
- Obtain Access Keys:
- On your Amazon account, go to your profile (at the top right)
- My Security Credentials > Access Keys > Create New Access Key
- Record the Access Key ID and Secret Access Key ID (you will need them in step 4)
- Save your AWS credentials in your local machine, using one of the following method:
- shared credentials file: instructions at https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#shared-credentials-file.
- environmental variables: instructions at https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#environment-variables
- Download the script by cloning the git repository at https://github.com/usdot-its-jpo-data-portal/wzdx_registry. You can do so by running the following in command line.
git clone https://github.com/usdot-its-jpo-data-portal/wzdx_registry.git
. If unfamiliar with how to clone a repository, follow the guide at https://help.github.com/en/articles/cloning-a-repository. - Navigate into the repository folder by entering
cd wzdx_registry
in command line. - Install the required packages by running
pip install -r requirements.txt
.
- To prepare the code package for deployment to AWS Lambda, run
sh package.sh
to build the package. This will create the filewzdx_trigger_ingest.zip
in the repo's root folder. - Create a lambda function in your AWS account "from scratch" with the following setting:
- Runtime: Python 3.8
- Permissions: Use an existing role (choose existing role with full lambda access (e.g. policy AWSLambdaFullAccess) and list/read/write permission to your destination s3 bucket)
- In the configuration view of your lambda function, set the following:
- In "Designer" section, add a CloudWatch Events trigger
- Set CloudWatch to trigger at your desired ingestion frequency. Once every 15 minutes is the highest frequency you should set for work zone status ingestion.
- In "Function code" section, select "Upload a .zip file" and upload the
wzdx_trigger_ingest.zip
file as your "Function Package." - In "Environment variables" section, set the following:
DATASET_ID
: ID of the WZDx feed registry Socrata dataset.- default set as
69qe-yiui
- default set as
LAMBDA_TO_TRIGGER
: Name of the lambda function to trigger.- default set as
wzdx_ingest_to_archive
. The code for thewzdx_ingest_to_archive
can be found at https://github.com/usdot-its-jpo-data-portal/wzdx_sandbox.
- default set as
SOCRATA_PARAMS
: stringified json object containing Socrata credentials for a user that has write access to the WZDx feed registry. At a minimum, this should includeusername
,password
,app_token
, anddomain
.
- In "Basics settings" section, set adequate Memory and Timeout values. Memory of 1664 MB and Timeout value of 10 minutes should be plenty.
- Make sure to save all of your changes.
- Python 3.6+: Python
- requests: package managing HTTP requests
- boto3: AWS API
- sodapy: Python client for the Socrata Open Data API
- Fork it
- Create your feature branch (git checkout -b feature/fooBar)
- Commit your changes (git commit -am 'Add some fooBar')
- Push to the branch (git push origin feature/fooBar)
- Create a new Pull Request
Please read CONTRIBUTING.md for general good practices on code of conduct, and the process for submitting pull requests.
This project is licensed under the Apache 2.0 License. - see the LICENSE file for details
- Thank you to the Department of Transportation for funding to develop this project.
Agency: DOT
Short Description: Code for triggering lambda function for ingesting WZDx feeds based on the WZDx Feed Registry Socrata dataset.
Status: Beta
Tags: transportation, connected vehicles, intelligent transportation systems, python, ITS Sandbox, Socrata, work zone data exchange (WZDx), smart work zone
Labor hours: 0
Contact Name: Brian Brotsos
Contact Phone: (202) 366-9013